WordPress.org

Ready to get started?Download WordPress

Forums

Portfolio Press
[resolved] I want to add some text to the home page header only (8 posts)

  1. figure2
    Member
    Posted 2 years ago #

    To be more specific, I want to add the contents of a custom field which will conditionally display only on the home page header of my Portfolio Press child theme.

    In header.php, I placed the following below the description tag within the hgroup tag:

    <?php if(is_home() ) {
    
    <p><?php echo get_post_meta($post->ID, 'Home Instruction', true); ?></p>
    
    } ?>

    All it did was cause the site to fail. Is there a better way I can do this?

    Mark

    http://wordpress.org/extend/themes/portfolio-press/

  2. Marventus
    Member
    Posted 2 years ago #

    Hi.
    The problem with your code is that you can't access post information while in the home page. The way WP works is that, when you are in the home page, you are not inside a post, so the post data is not accessible.
    What you could do is have one header for your home page and one for your posts. Something like this in your header.php file would work:

    <?php
    if( is_home() ) {
       $header = '<p>We are Home</p>';
    } else if( is_single() ) {
       $header = '<img src="path/to/image" alt="image" />'
    } else {
       $header = '<p>Default Header</p>';
    }
    echo $header;
    ?>

    If you only need a custom header for your home page only and the same header in the rest of the site, simply remove the else ifpart of the code:

    <?php
    if( is_home() ) {
       $header = '<p>We are Home</p>';
    } else {
       $header = '<p>Default Header</p>';
    }
    echo $header;
    ?>

    Another simpler alternative for this last version would be:

    <?php
    $header = ( is_home() ) ? '<p>We are Home</p>' : '<p>Default Header</p>';
    echo $header;
  3. figure2
    Member
    Posted 2 years ago #

    @Marventus: Before I test your solution I need some info. Basically what I need is the default header with the addition of one line of text after the description. If I read your solution with my limited PHP knowledge, it looks like it replaces the entire header with one line of text which does not solve my problem.

    Can I insert this code inside the hgroup, leaving all the content which is there now intact with the addition of my line of text only on the home page?

    Here is what I am looking to do (Before and after shots): http://www.markhannondesign.com/clientJobs/homePage.jpg

  4. Sridhar Katakam
    Member
    Posted 2 years ago #

    <?php if (is_front_page())echo 'This text can only be seen on the home page.'; ?>

  5. psalm100
    Member
    Posted 2 years ago #

    Hi, I'm NEW and can't even get a template downloaded...can anyone tell me how to do that? I can only open NOT save or Download.THANKS.susan

  6. figure2
    Member
    Posted 2 years ago #

    Thanks Srikat!

  7. Marventus
    Member
    Posted 2 years ago #

    @Figure2: Did you figure out where to insert the code? If you didn't, I'll download your theme and tell you where to put it.

  8. figure2
    Member
    Posted 2 years ago #

    @Marventus: Srikat's code solved the problem. Thanks for the offer of help though.

    Mark

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic