WordPress.org

Ready to get started?Download WordPress

Forums

Different header links on different pages? (14 posts)

  1. webmakerholly
    Member
    Posted 2 years ago #

    Hi,

    I'm using a child theme of Twenty Eleven. I've created a few different template pages and I'm wondering if/how I can make my headers link to different pages? Specifically, on my homepage, I want the header image to link to the News page and on all other pages I want the header image to link to the home page. My header image for the homepage is created using the Featured Image function. The header for all other pages is in the default header.php file.

    Here's a link to the site: http://springersgymclub.ca/dev/

    Thanks for your help!

  2. flashbuddy
    Member
    Posted 2 years ago #

    I'm confused...

    For adding different content on a per page basis a couple things come to mind:

    1.) Create a widget area and assign widgets on a per page/post basis using widget logic plugin.

    2.) Add PHP code to the area I want to effect that is page specific. Example:

    <?php if ( is_page('home') ) { ?>
    <p>Hey, this is your home page!</p>
    <?php } else { ?>
    <p>This is NOT your home page!</p>
    <?php } ?>
  3. esmi
    Forum Moderator
    Posted 2 years ago #

    Yes - this should be possible via a custom header.php template file.

    // Check to see if the header image has been removed
    $header_image = get_header_image();
    if ( ! empty( $header_image ) ) :
    ?>
    <a href="<?php echo esc_url( home_url( '/' ) ); ?>">

    to:

    // Check to see if the header image has been removed
    $header_image = get_header_image();
    if ( ! empty( $header_image ) ) :
    $my_url = esc_url( home_url( '/' ) );
    if( is_home() || is_front_page) ) :
    $news = get_page_by_title( 'News' );
    $my_url = get_page_link( $news->ID )
    endif;?>
    <a href="<?php echo $my_url; ?>">

    WARNING: Untested

  4. webmakerholly
    Member
    Posted 2 years ago #

    Thanks for all your suggestions. Esmi, I tried your code and it gave me an error on this line:

    if( is_home() || is_front_page) ) :

    I am a designer impersonating a developer, so I don't know what to try to fix there. Any suggestions?

  5. Chip Bennett
    Theme Review Admin
    Posted 2 years ago #

    Change this:

    is_front_page)

    ...to this:

    is_front_page()
  6. webmakerholly
    Member
    Posted 2 years ago #

    Hmmm, now I get this error message:

    Parse error: syntax error, unexpected ':' in /.../public_html/dev/wp-content/themes/springers/header.php on line 83

  7. Chip Bennett
    Theme Review Admin
    Posted 2 years ago #

    Change this:

    $my_url = get_page_link( $news->ID )

    ...to this:

    $my_url = get_page_link( $news->ID );

    If you have questions about general PHP syntax, I would recommend reading up at sites such as w3schools.com or PHP.net.

  8. webmakerholly
    Member
    Posted 2 years ago #

    Thanks Chip. I tried that but I still get that same syntax error. Anything other suggestions?

  9. Chip Bennett
    Theme Review Admin
    Posted 2 years ago #

    Thanks Chip. I tried that but I still get that same syntax error. Anything other suggestions?

    Yes: try w3schools.com or PHP.net to help familiarize yourself with PHP syntax. Since we can't see your actual code, have no idea what the line numbers refer to in the PHP errors you're getting, it is next-to-impossible to troubleshoot.

  10. webmakerholly
    Member
    Posted 2 years ago #

    I agree that I need to be more familiar with PHP to work with WordPress. However, I need to figure out how to get it working by tomorrow. Thanks anyway. And thanks for the links.

  11. flashbuddy
    Member
    Posted 2 years ago #

    Send me the your ftp login and password, and your wp-admin login and password and I'll take a look by tomorrow.

  12. Chip Bennett
    Theme Review Admin
    Posted 2 years ago #

    I think it is generally frowned upon to ask for - or to give out - hosting/FTP/WordPress credentials...

  13. Samuel Wood (Otto)
    Tech Ninja
    Posted 2 years ago #

    webmakerholly,

    The correct syntax for the line you're having problems with is this:

    if( is_home() || is_front_page() ) :

    Double check that.

  14. webmakerholly
    Member
    Posted 2 years ago #

    Otto, that worked! Thanks! The only thing is now when you're on the News page, the header links to the News page instead of back to the homepage. (All other pages link back to the homepage though, so that's good.)

    I moved the site to: http://springersgymclub.ca

    Thanks for everyone's help!

Topic Closed

This topic has been closed to new replies.

About this Topic