Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Displaying Page/Category Dependant Content In Wordpress Header

Featured Replies

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?

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 by Renaissance-Design

  • 3 weeks later...
  • 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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.