• 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 -->
Viewing 1 replies (of 1 total)
  • Thread Starter sticklechick

    (@sticklechick)

    I found a solution by eliminating the Custom Post Type and adding a Theme Options page with a textbox to add/edit the default banner content. Ian Stewart has an awesome, easy tutorial on creating Sample Theme Options. He explains how to make it work with a child theme. (Thanks, Ian!)

    Here is the what ended up going into the header.php file. Hope this helps someone else.

    <div id="headline">
         <?php
              if (is_page()) :
                   $headline_custom = get_post_meta(get_the_ID(), 'banner_headline', true);
                   echo $headline_custom; //Show the custom headline from METABOX
              else :
                   $options = get_option('sanskrit_theme_options');
                   echo $options['headline-default']; //Show the default headline from THEME OPTIONS PAGE
         ?>
         <?php endif; // end check for metabox ?>
    </div> <!-- #headline -->
Viewing 1 replies (of 1 total)
  • The topic ‘Displaying Custom Post Type content in the Header?’ is closed to new replies.