2

I'm trying to get the ID of my posts archive page. It's set via the admin as the posts page so it already has the default Query. The template I'm using is index.php, Tried using page-blog.php but since i set that page as the posts archive it used index.php instead (was kind of thrown off by this).

echo get_the_id() returns the ID of my top-most blog post (in this case a sticky) instead of the page ID. I am outside the loop.

There's a similar question here : ID for posts/blogs page but the objective is slightly different and the solution there is to instead use get_option('page_for_posts') to get the posts archive ID, I need a way to detect if I am in the posts archive page.

I tried using :

if (is_page('blog')){ $current_id = get_option('page_for_posts')

but this didn't work because the global $post object seems to refer to my sticky post instead of my archive page

Answers i found seems to be workarounds, but doesnt address the underlying problem which is the $post screwup. Is there something I'm missing or should be doing another way ? I explicitly need my posts archive page to not be my homepage.

1

1 Answer 1

4

Figured it out. use is_home() to detect if its the posts archive page. kind of counter-intuitive because i always thought that function was to determine if it's the homepage, found out there's a is_front_page() for that.

1
  • True. Remember that WordPress started out as a blogging platform so I think that's why that function returns the blog index page and it was never changed. Oct 3, 2018 at 20:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.