问题
I need help with the templating in wordpress.
On the front-page I want a custom static header, while all the other pages should use the title for their page instead. Also, if the page is not the front-page I want to add some custom HTML next to the title.
What is the best way to do this?
回答1:
You can do it like this, including the following in header.php (I've just added some example content);
<?php
if ( is_front_page() ) {
echo '<div id="homestuff">Home stuff in here</div>';
} elseif (is_page()) {
echo '<div id="pagestuff">'. the_title() .'</div>';
}
?>
Take note, there is also a is_home() in Wordpress and it's sometimes easy to get in a bit of a tangle about whether is_front_page() or is_home() is the correct one to use, this stackexchange answer is a good source of info about that;
Whether to use is_front_page() or is_home() in Wordpress
来源:https://stackoverflow.com/questions/11709805/wordpress-conditional-statement-for-front-page-or-inner-page