将if语句添加到WordPress中的php中的类

我有以下代码:

<?php if ( is_post_extra_title_meta_enabled() ) { ?>
<div class="post-header">
<h2 class="entry-title"><?php the_title(); ?></h2>
</div>
<?php } ?>

如果要在wordpress的首页/首页上创建类H1, 我想将其设为H1。我该如何在其中添加if / else命令?所以基本上:

If on front page:
<h1 class="entry-title"><?php the_title(); ?></h1>

Else:
 <h2 class="entry-title"><?php the_title(); ?></h2>

#1


要确定你是否在wordpress的主页上, 可以使用is_home()函数。

因此, 如果你要在提供的原始if语句中添加if else, 则代码会像这样,

<?php if ( is_post_extra_title_meta_enabled() ) { ?>
    <div class="post-header">
        <?php if ( is_home() ) { ?>
            <h1 class="entry-title"><?php the_title(); ?></h1>
        <?php } ?>
        <?php else { ?>
            <h2 class="entry-title"><?php the_title(); ?></h2>
        <?php } ?>
    </div>
<?php } ?>

我偏向于使用其他语法, 因此这是重写的代码。

<?php if ( is_post_extra_title_meta_enabled() ): ?>
    <div class="post-header">
        <?php if ( is_home() ): ?>
            <h1 class="entry-title"><?php the_title(); ?></h1>
        <?php else: ?>
            <h2 class="entry-title"><?php the_title(); ?></h2>
        <?php endif; ?>
    </div>
<?php } ?>

#2


根据你的WP配置, 你可以使用is_front_page()或is_home()(如Ryan所述)

来源:

https://www.srcmini02.com/64702.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37402.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?