用于首页或内页的WordPress条件语句

时间:2012-07-29 13:57:54

标签: php html wordpress wordpress-theming

我需要wordpress中的模板帮助。

在首页我想要一个自定义静态标题,而所有其他页面应该使用标题作为其页面。 此外,如果页面不是首页,我想在标题旁边添加一些自定义HTML。

这样做的最佳方式是什么?

1 个答案:

答案 0 :(得分:1)

你可以这样做,包括header.php中的以下内容(我刚刚添加了一些示例内容);

        <?php 
             if ( is_front_page() ) { 
                echo '<div id="homestuff">Home stuff in here</div>';
              } elseif (is_page()) { 
                echo '<div id="pagestuff">'. the_title() .'</div>'; 
              } 
        ?>

请注意,Wordpress中还有一个is_home(),有时很容易让人觉得is_front_page()或is_home()是否正确使用,这个stackexchange答案是一个很好的来源有关的信息;

Whether to use is_front_page() or is_home() in Wordpress