• Hello,

    This post is sort of related to my first and previous post named “Browser address display permalinks and no id” which has been resolved.

    This is now my problem;

    I have installed the wordpress theme named “Twenty Eleven” and customised it for my purposes.

    I want to display a different header image on each page, dependant on the page subject.

    In the template named HEADER.php I have some code that looks like this;

    switch ($page_id) {
    		case 0: $page_subject = 'BLOG'; break;
    
    	case 45: $page_subject = 'WEDDING'; break;	
    
    	case 47: $page_subject = 'PORTRAIT'; break;	
    
    	case 51: $page_subject = 'HOME'; break;		
    
            }

    Before I activated permalinks this worked fine and changed the image dependant on which page you opened. The only pages that change the image are the BLOG page and HOME. All the other pages display the blog page image.

    It appears that the permalinks feature has blocked the page from seeing the page id.

    How can I keep my permalinks on and also keep my case statement in the header.

    Thank You for any assistance
    Ben

Viewing 10 replies - 1 through 10 (of 10 total)
  • what are you using to create the $page_id variable?

    Thread Starter bentonda

    (@bentonda)

    I’m not clear on how it works but it gets its value from the page_id, which is generated by wordpress.

    ok.

    Try and add this above the switch..

    global $post;
    $page_id = $post->ID;

    or

    $page_id = get_the_id();

    Something like that.

    Thread Starter bentonda

    (@bentonda)

    I tried that and it returns an Error occurred: 404 – not found message.

    I think the page_id is being blocked by the permalink function it seems to be interfering with it being seen by the code in my header.php

    A 404 where?

    Basically you need to debug what $page_id is.

    echo it out just before the switch

    echo $page_id;
    Thread Starter bentonda

    (@bentonda)

    I placed this code above the switch echo $page_id;
    The page id flashed up on the screen in the top left hand corner.

    When I inspect the page source it is printed right in above the tag named
    <!DOCTYPE html>

    yeah it will, never mind that, what did it say, i.e. what was the number?

    Thread Starter bentonda

    (@bentonda)

    Exactly the same numbers as I have in my case statement above;


    switch ($page_id) {
    case 0: $page_subject = ‘BLOG’; break;

    case 45: $page_subject = ‘WEDDING’; break;

    case 47: $page_subject = ‘PORTRAIT’; break;

    case 51: $page_subject = ‘HOME’; break;

    }

    so if you are on the wedding page (or the page where you want to display the wedding banner) the page_id is 45?

    Well in that case what does the $page_subject do? Because if the $page_id is 45 then the $page_subject variable should be set to the string ‘WEDDING’. You could test that by doing this under the switch.

    echo $page_subject;

    If that is all correct it depends what is happening with the $page_subject variable after that, it should just work.

    Thread Starter bentonda

    (@bentonda)

    I am going to have to have a close look at what is going on. The two variables are definitely picking up the correct information.

    Its got me beat at the moment.

    Thank You for your help
    Ben

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Permalinks hide page id from my code’ is closed to new replies.