Forums

How do I detect the Blog Posts page? (2 posts)

  1. Matt Van Andel
    Member
    Posted 1 year ago #

    I'm currently using the 'wp' action hook to execute some code. The function that I'm hooking with uses the $post global to get information about the currently displayed page/post. For pages and posts themselves, this works perfectly. However, on the Blog Posts page, the $post variable does not return information about the Blog Posts page itself but only the most recent post.

    For example, let's say I created a page for the blog posts and called it "News Items" (ID 5) and gave it four posts (IDs 6,7,8,9). Then I navigated to the "News Items" page. If I used $post->ID in my plugin to get the current page ID, I would not see 5 despite that "technically" being the page am I actually viewing... I would see 9 (the id of the most recent post).

    This causes a problem since $post cannot be reliably used to determine the actual id of the page being viewed by a user... so we need to ALSO detect what TYPE of page the user is viewing (is this a special WordPress-generated page?).

    I'm assuming there's another way to detect what kind of page we're on, but I've been searching for a couple days and can't figure this out. I need to be able to conclusively detect what KIND of page the currently displayed page is - page, post, blog posts page, category page, etc... while using the 'wp' action hook. Does anyone have any ideas? I'm stumped.

  2. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    <?php if( is_home() ):?>
    [ do stuff ]
    <?php endif;?>

    http://codex.wordpress.org/Conditional_Tags#The_Main_Page

Topic Closed

This topic has been closed to new replies.

About this Topic