如何在 Wordpress 中使用 If、If Else 和 else

新手上路,请多包涵

我想在 wordpress 主页上使用 If、If else 和 else,我使用以下条件

<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
}?>
<?php if else {
<img src="<?php echo catch_that_image() ?>" width="64" height="64" alt="<?php the_title(); ?>" />
} else {
<img src="http://www.technoarea.in/wp-content/themes/TA/images/TA_Logo.png" width="64" height="64" alt="<?php the_title(); ?>" />}
?>
<?php  ?>

我想首先在主页上显示缩略图,如果缩略图不可用,则必须使用帖子中的第一张图片作为缩略图,如果帖子中没有图片,则使用此图片

http://www.technoarea.in/wp-content/themes/TA/images/TA_Logo.png

你能告诉我我错在哪里,因为上面的代码不起作用

原文由 rahul sharma 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 497
1 个回答
//Doing this for over 20 options.
//Which one is better? The first option will make 20 database calls.
//Only those filters will be invoked for whom the settings are enabled.

// ==A==
if(get_option('some_setting')=='yes')
{
    add_action( 'woocommerce_checkout_process', 'abc_xyz' );
}

function abc_xyz() {

            //Do Something here

}

//=========================OR=========================
//==B==

function abc_xyz() {

        if(get_option('some_setting')=='yes')
        {

            //Do Something here
        }
}
add_action( 'woocommerce_checkout_process', 'abc_xyz' );

原文由 Yashvi 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题