tags:

views:

72

answers:

3

I am using this code in wordpress to display different content when different pages are loaded. I have 5 pages on the site called Home, Bio, Work, Contact and Notes. The Notes page is being used as a blog. Here is the code I am using.

                    <?php if (is_page('contact')) { ?>
                    get in touch with me
                <?php } elseif (is_single()) { ?>
                    a note from me
                <?php } elseif (is_page('notes')) { ?>
                    the notes of me
                <?php } else { ?>
                    the <?php the_title(); ?> of me
                <?php } ?>

So if it the contact page, it displays "get in touch with me" and if it is a single blog post page it displays "a note from me". However this is where I have a problem. The next statement should display "the notes of me" when it is on the Notes page. However, this does not happen. Instead it shows the default content which is in the "else" statement. any idea on why this is happening?

A: 

Comes to mind, that page name is not 'notes'. Check the URL of your page and see what is the page name.

Silver Light
the url is http://localhost/wordpress_test/notes/
codedude
+2  A: 

This is what I would do instead.

            <?php if (is_page('contact')) { ?>
                get in touch with me
            <?php } elseif (is_page()) { ?>
                the <?php the_title(); ?> of me
            <?php } elseif (is_single()) { ?>
                a note from me
            <?php } else { ?>
                the notes of me
            <?php } ?>
KThompson
it is set to "notes"
codedude
Ok I noticed you said you are using the 'notes' page as a blog. Is it actually a page or is it actually the default blog functionality of wordpress
KThompson
I made a page and then went to Settings>Reading and set the posts page to the Notes page.
codedude
Its the function you are using, is_page() is not appropriate for what you are checking for. is_page is checking for a STATIC page with content that you created in the admin under "Pages" it is not checking for any page (as we would call it) that happens to be called page. What you've done is made so the "Notes" url points to a post listing. So your function would need to check for a post listing OR the correct url
KThompson
Is there a tag for grabbing the parent page name on a post page?
codedude
no there isn't. Posts dont have parent's unless they are categorized, then their parents' are categories. Check my answer again I've edited it. It should solve your original problem
KThompson
Thanks man! That fixed it!
codedude
+1  A: 

please check whether the pages been puslished or not.

justjoe
it has been published.
codedude
i got several suggestion :<p>1. maybe it's little bit weird suggestion. But please check your trash post, soemtimes a delete page with the same name and slug can make pages with the same name and slug can not be seen.</p><p>2. what happen when you changes to is_page("Notes"). The is_page function work by validate input based on post ID, post_title, Slug...so change the input to use another type. To make sure, change notes into ID and set it as integer</p>
justjoe
There's nothing in the trash and I tried using the post ID just now and it did not work.
codedude
delete the notes page from the trash. And about the id, don't use '' or "", it must be an integer (event though, the type of input will be convert into an array )if it's still failed, alas, i can not help ypu more
justjoe
still nothing...one question. Could it be a problem with the order of the statements?
codedude
i think it's not the problem. you code it right. frankly, your situation is out of my knowledge :(
justjoe
oh well...thanks for the help anyways ;)
codedude