Support » Fixing WordPress » Really stuck with page ids…!!

  • Resolved you_know_zo


    Hi everyone,

    I have been searching for answers for HOURS – I haven’t found anything that helps, so I hope this isn’t a repeast question…

    Basically, I have am building a site where the home page is set to a static page… I then have 3 other static pages, and one more called ‘store’ which displays the posts of my blog – blog entries are simply products… that’s all fine…

    The problem is that I have a sidebar which displays on every page, and I only want it to display on the ‘store’ page… I can get it to only display on any other page, using a variety of methods – as I said, I have been trying for hours!! I wanted to do it with page ID or page title, but neither of them work for this page… all the others, yes, but not this one…

    When I print the page id on the store page it comes out as being 1, where as it is 10 in the url… but neither work in my if statement… if pageid works for every page but that one…

    I tried is_category and have_posts too, but since pages are posts they didn’t work either… I applied a category to just the posts in the blog, but it was applied to all the pages too…

    Does anyone have any idea why the page ID doesn’t work on the blog page? Or if there is anything else I can use? I’m going out of my mind!!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Have you tried is_page?

    if(is_page('Store')) {

    Yep… it works for the home page, and the links page…

    <?php if(is_page('Home')) {

    But not store… I don’t get it!!

    Thanks for replying 🙂

    Try one of the other methods..

    Might be worth creating a test page, named test, or something else and trying some of the above is_page arguments…

    Of course it might be worth just printing the page id or title on the page just to make sure it matches what you’re entering into is_page…

    Something like…

    if($post) {
    if(method_exists($post,'post_title')) echo $post->post_title.'';
    else echo 'no title found';
    if(method_exists($post,'ID')) echo $post->ID.'';
    else echo 'no ID found';
    if(method_exists($post,'post_name')) echo $post->post_name.'';
    else echo 'no post name found';

    A page is still effectively a post but the post_type = page…

    The above should just print the title, id and name for you, just to make sure they match up with what you’ve been passing into is_page..

    Hi 🙂

    Thanks again… I tried all those things already though 🙁 Sorry, I should have made a more extensive explanation…

    Using the code you posted above, I got:

    no title foundno ID foundno post name found

    But when I did a check for the page ID before, it said it was page ID 1, even though it’s 10 in the URL – but neither 10 nor 1 work…

    I am going to drink some tea… this problem is driving me NUTS!!

    Thank you again for your help 🙂

    I’ll test it for you when i’m back on the other PC…

    Perhaps it didn’t like method_exists() , though i’ve not had a problem with it before…

    Ok, try…

    print '<pre>';
    print '</pre>';

    Just so you can get an idea of what is being held in $post…

    Of course if this is a live site and you need to avoid anyone seeing this (other then you) let me know and i’ll wrap that in a user level check for you…

    Hello – you’re a legend, thank you!!

    OK… I used that little code snippet and this is what I got on the Store page…

    stdClass Object
    [ID] => 33
    [post_author] => 1
    [post_date] => 2009-05-11 18:39:05
    [post_date_gmt] => 2009-05-11 17:39:05
    [post_content] => Product Description: Plain white t-shirt with Brain Wraps design.

    Price: $15

    [post_title] => New T-shirt design
    [post_category] => 0
    [post_excerpt] =>
    [post_status] => publish
    [comment_status] => open
    [ping_status] => open
    [post_password] =>
    [post_name] => new-t-shirt-design
    [to_ping] =>
    [pinged] =>
    [post_modified] => 2009-05-12 15:14:58
    [post_modified_gmt] => 2009-05-12 14:14:58
    [post_content_filtered] =>
    [post_parent] => 0
    [guid] => http://localhost/wordpress/?p=33
    [menu_order] => 0
    [post_type] => post
    [post_mime_type] =>
    [comment_count] => 0
    [ancestors] => Array

    So I tried my if statement with 33, as all the other IDs in the statement match the one in the URL… Unless my if statement is truly wrong, then it wasn’t 33… Every page said ‘not 33’

               { echo "page 33"; }
               { echo "not 33"; } ?>

    Any ideas??

    Ok, well all the above refer to methods (i think thats the term) of the $post object…

    You can refer to them using…

    $post->ID for the first ie. [ID]
    $post->post_name for the post name..

    and so on……

    The previous suggestion just outputs this all on screen so you know what’s being held in $post, then you can use it to refer to…

    So try this instead…

    if($post->ID == 33) { echo 'match!'; }

    Or you might need to use… (quotes round the number)..

    if($post->ID == '33') { echo 'match!'; }

    That’s what print_r, var_dump, etc…. exist for, dumping and printing data (i think)… that’s what i use them for… 🙂

    Hello again 🙂

    OK – that worked, I got it to say that it was a match to page 33… with:

    if($post->ID == 33) { echo 'match!'; }

    Hoorah – you are a genius… Since I started trying to solve this problem I have worked around it so I didn’t come to a stand still, but this little tid-bit is incredibly useful to me… thank you for all your help 🙂


    No worries, you’re welcome…

    Figured the first would work, but mentioned the second just incase.. 🙂

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Really stuck with page ids…!!’ is closed to new replies.