WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Different header for each page (9 posts)

  1. stemckinney
    Member
    Posted 4 years ago #

    Hello all,

    I'm fairly new to wordpress and my PHP knowledge isn't very good, I've searched google many times, the forums here too, but to not find a solution to my problem.

    I recently came across a code which I thought would work, seemed logical to me and everything, with what knowledge I have and considering doing an attempt myself I did something similar.

    Got me this:
    Parse error: syntax error, unexpected '<' in /nfs/c06/h02/mnt/89623/domains/blog.iamsteve.me/html/wp-content/themes/iamsteve/header.php on line 43

    Using this:

    <?php if (is_page('about')) {<?php include(TEMPLATEPATH . '/about_header.php'); ?>}
    			elseif(is_page('portfolio')) {<?php include(TEMPLATEPATH . '/portfolio_header.php'); ?>}
    			elseif(is_page('blog')) {<?php include(TEMPLATEPATH . '/blog_header.php'); ?>}
    			elseif(is_page('contact')) {<?php include(TEMPLATEPATH . '/contact_header.php'); ?>}
    			else {<?php include (TEMPLATEPATH . '/home_header.php'); ?>}
    		 ?>

    I want a unique header for each page, I have created each of the pages home_header.php, contact_header.php etc.

    Also I don't want to have to use a plugin, the way my header is designed is not one image it's sliced up into several, so the best way to me seemed to use a code like the above.

    Thanks in advance for your help.

  2. Snat
    Member
    Posted 4 years ago #

    Haven't tested, but try.

    <?php 
    
    if (is_page('about')) {include(TEMPLATEPATH . '/about_header.php');}
    
    elseif(is_page('portfolio')) {include(TEMPLATEPATH . '/portfolio_header.php');}
    
    elseif(is_page('blog')) {include(TEMPLATEPATH . '/blog_header.php');}
    
    elseif(is_page('contact')) {include(TEMPLATEPATH . '/contact_header.php');}
    
    else {include (TEMPLATEPATH . '/home_header.php');}
    
    ?>
  3. stemckinney
    Member
    Posted 4 years ago #

    The parse error was corrected, just it's not showing the header on the page, I haven't fully created each header as such but I have uploaded an image/changed what's needed, what seems to have happened is the images have duplicated over instead. Well the very top one only if you check in comparison.

    http://blog.iamsteve.me/blog is the page i was testing

  4. stemckinney
    Member
    Posted 4 years ago #

    Sorry for the double post but the edit link has gone, the images looked duplicated due to my css, I have corrected that now.

  5. stemckinney
    Member
    Posted 4 years ago #

    Still looking for an answer thanks in advance.

    If it needs to be made clearer in anyway I'll gladly do so, but what seems to be happening is now it's just not calling the header I want altogether.

  6. flexnds
    Member
    Posted 4 years ago #

    Alright.. It's a little bit of a process but let's do it. I am assuming you know how to use FTP like Filezilla. First since you want to change the header for each post you will have to have a different post template for each post as well. You will do this by installing the plugin that will allow you to pick different post template. Download "Custom Post Template".

    After downloading that you will need to create 5 different post templates. drag and drop 5 .txt files into your theme files via FTP. For my sanity let's name them like this

    posttemplate1
    posttemplate2
    posttemplate3
    posttemplate4
    posttemplate5

    Now delete the .txt extension and add .php to the end of each file name.

    Now go to Appearance>Editor on your WP admin and drop this line of code at the top of each blank template.

    posttemplate1

    <?php
    /*
    Template Name Posts: posttemplate1
    */
    ?>

    posttemplate2

    <?php
    /*
    Template Name Posts: posttemplate2
    */
    ?>

    posttemplate3

    <?php
    /*
    Template Name Posts: posttemplate3
    */
    ?>

    posttemplate4

    <?php
    /*
    Template Name Posts: posttemplate4
    */
    ?>

    posttemplate5

    <?php
    /*
    Template Name Posts: posttemplate5
    */
    ?>

    After adding the code to each respective template copy and paste all of the code in your single.php file into each one of those 5 templates under the snippet of code that is already their.

    Now create 5 headers with .txt extensions

    header1
    header2
    header3
    header4
    header5

    and drag and drop them into your theme folder via FTP

    delete the .txt extension and add the .php extension.

    You do not need to use the php code above. You will simply call on these header templates by replacing this

    <?php get_header(); ?>

    With

    <?php include (TEMPLATEPATH . '/header1.php'); ?>
    <?php include (TEMPLATEPATH . '/header2.php'); ?>
    <?php include (TEMPLATEPATH . '/header3.php'); ?>
    <?php include (TEMPLATEPATH . '/header4.php'); ?>
    <?php include (TEMPLATEPATH . '/header5.php'); ?>

    in each one of your 5 different post templates. After you have finished editing your 5 new header files and have them the way you want them go to your post>edit screen and choose the template for each post via the drop down box.

    I think I got all that right.. Let me know if you have any problems..

  7. melstan1
    Member
    Posted 4 years ago #

    Try moving this line:
    else {include (TEMPLATEPATH . '/home_header.php');}

    between the "if" line and the "else if" lines. I don't know why that works, but it does, SOMETIMES. I haven't figured out the pattern yet but it might be worth a go?

    Good luck.

  8. flexnds
    Member
    Posted 4 years ago #

    Also you said each page (6 posts) If you are actually using page templates then you will not need to download the plugin stated above. You simply add this snippet of code instead

    <?php
    /*
    Template Name: posttemplate1
    */
    ?>

    After that it's pretty much the same process only you will be able to define the template under pages>edit and select the desired template via the drop down box.

  9. stemckinney
    Member
    Posted 4 years ago #

    Thanks for all the help, I did it without the plugin using the template naming method, I might try the moving around of the else another time thanks for the contributions though

Topic Closed

This topic has been closed to new replies.

About this Topic