Displaying Custom Post Type content in the Header?
-
I’m trying to hack the header in a Twenty Eleven child theme to display dynamic headlines in the banner. I’ve got it partially working on a (staging server), so you can see what I mean.
I’m using the Metabox script/plugin by Riwalis so that the user can create/modify the headline on a page-by-page basis. This is working great for most pages.
But I also need a default headline as a fall-back for the index pages and other WP-generated pages. I thought the best way to do this would be to create a Custom Post Type to create/edit the default headline and then add a conditional statement in the header.php file to call it if there isn’t a custom headline for the page. But I can’t get the default headline to display.
Here’s what I have in the header.php file. I’m new to PHP, so I expect that I haven’t constructed this correctly? I’d be grateful for any insights:
<div id="headline"> <?php $headline_custom = get_post_meta(get_the_ID(), 'sb_banner_headline', true); $headline_default = get_post_type('sb_default_headline', true); if (is_page()) : echo $headline_custom; //Show the custom headline from Page METABOX else : echo $headline_default; //Show the default headline from CUSTOM POST TYPE ?> <?php endif; // end check for HEADLINE ?> </div> <!-- #headline -->
- The topic ‘Displaying Custom Post Type content in the Header?’ is closed to new replies.