August 3, 201214 yr Hi everyone, I've been working on this feature for a while, but have hit a bit of a wall, and hoping someone might be able to assist. What I'm trying to do is display different types of content in the header of the site depending on what page the visitor happens to be on. So far, this code seems to be working. Displays my slider on the home page, and then displays a page/post title and a custom field on any other page. I have no idea whether the code is correct or not, but it does appear to be working. <?php if (is_front_page()) { echo do_shortcode("[nivoslider slug=home-page-slideshow]"); } else { ?> <h1><?php the_title(); ?></h1> <span class="page-tagline"><?php echo get_post_meta($post->ID, 'page-tagline', true); ?></span> <?php } ?> However, the title and tagline content is not appropriate for all pages/categories. There are some areas that I would like to display different content, such as my about page (a category layout), which presently displays the title of the most recent post, when I'd like it to display some static text. I've seen some examples using 'elseif' statements, but I haven't been able to figure out how to get those working. Can anyone point me in the right direction?
August 3, 201214 yr When working with PHP templates, it's better to use the alternative conditional syntax. Easier for your IDE to colour, and it maintains HTML whitespace. <?php if (is_front_page()): ?> <?php echo do_shortcode("[nivoslider slug=home-page-slideshow]"); ?> <?php elseif(is_page(42)): ?> <h1><?php the_title(); ?></h1> <span class="page-tagline"><?php echo get_post_meta($post->ID, 'page-tagline', true); ?></span> <?php elseif(is_page('contact')): ?> <h1>Some different markup</h1> <?php elseif(is_page()): ?> <h1>Generic page</h1> <?php elseif(is_category()): ?> <h1>Markup for categories</h1> <?php elseif(is_category('specific-category')): ?> <h1>Markup for specific category</h1> <?php endif; ?> Edited August 3, 201214 yr by Renaissance-Design
August 21, 201214 yr Author Thanks for this Chris, and apologies for the delayed reply. I had thought I had come across an error using this code, as I was getting five little 'question mark inside diamond' icons on the home page, but I had another look at the code today and I'd accidentally put some extra characters in there. Ooops! Thanks again! :-)
Create an account or sign in to comment