php is_page()

  • Mod

    Kenneth John Odle

    #4859

    I’ve been using the PHP plugin, trying to echo something to both posts and pages. No matter what I try, I can’t get it to show up on pages, only posts.

    I’ve tried

    if (is_singular())

    which only shows up only on posts, and

    if (is_single() || is_page())

    which also shows up only on posts, and even

    if ($post_type->name == 'page' )

    which I got from here and which didn’t show up anywhere.

    I even tried this:

    if (is_front_page() || is_archive() || is_attachment()) {} else

    which again worked on posts, but not pages.

    Any ideas what I am doing wrong?

    References:

    http://codex.wordpress.org/Function_Reference/is_single

    http://codex.wordpress.org/Function_Reference/is_singular

    Thanks

    Admin

    Syahir Hakim

    #29538

    Hurm..where is this function attached to?

    Mod

    Kenneth John Odle

    #29539

    It’s in a PHP widget in the after_post_content widget area.

    Full code is here: http://pastebin.com/2H7SRLNY

    Admin

    Syahir Hakim

    #29540

    It could be that the global $post variable has been changed (or destroyed?) by the time the script is executed. Can’t really tell without delving deeper into it.

    Have you tried using the Widget Logic (Visual) with it?

    Mod

    Kenneth John Odle

    #29541

    It could be that the global $post variable has been changed (or destroyed?)

    I’ll look into this. At least my syntax is right.

    Have you tried using the Widget Logic (Visual) with it?

    I’ll try this tomorrow, I think, if I can’t get anything else to work. I wanted to avoid adding another plugin as I’m still looking for a good secondary slider plugin. (Nothing yet on that account, though.)

    Thanks for taking a look.

    Admin

    Syahir Hakim

    #29542

    Try this and see what’s the output:

    global $wp_query;
    disect_it( $wp_query );
    Mod

    Kenneth John Odle

    #29543

    Where should I add that?

    ronangelo

    #29544

    isn’t after_post_content intended for posts only.

    why not add to both after_post_content and after_page_content hooks

    Mod

    Kenneth John Odle

    #29545

    @ronangelo:

    Of course, you are absolutely right.

    I didn’t even notice that file before. I did exactly as you suggested and it all works fine now. Thanks.

    Sidenote: I can now do what I originally intended to do with an HTML widget, instead of a PHP widget. Graphene really does make things easy, except for when I overcomplicate them.

    Thanks again, everyone.

    Admin

    Syahir Hakim

    #29546
    Quote:
    isn’t after_post_content intended for posts only.

    why not add to both after_post_content and after_page_content hooks

    Ah yes, I forgot this too 🙂

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

You must be logged in to reply to this topic.

Do NOT follow this link or you will be banned from the site!