EDIT: This used to be
How do I force a page to be
is_archive == true?
I was trying to solve the wrong problem. Instead of forcing the post/page to have a particular attribute, I should have looked at the classes applied to the menu item. The 'Blog' menu-item has the
current-page-ancestor class applied to it. I can style the menu based on this.
I have my own theme where I created an
archives.php template in order to have a page that tries to list the different ways to view archives and to give a place for users to browse the archives if they want to.
I created a page using the WP admin page and I made it's parent the 'Blog' page. The 'Blog' page is the page where all my posts get emitted. I have a menu at the top and right now, every sub-page under the 'Blog' page causes the menu to highlight 'Blog' (this is the correct behavior). Specifically, the menu item has the style
current_page_* applied to it. This doesn't happen when you load
blog/archives (the template/page I created in the first paragraph).
So when I click on the date of a blog post, it brings me to an archived post page it looks like this (note that the Blog menu item is highlighted):
When I go to my archives, it looks like this (note that the menu item is NOT highlighted):
I looked at
$wp_query to see what the difference was. I saw that
is_home was true in the cases where the menu-item was correctly styled.
How do I force my page to be
is_archive == true? I tried to insert a
$wp_query->set('is_archive', 1); before the call to
get_header(); in my template but that didn't work. I also looked in the WP admin dashboard to see if there was something I could click to force the page to be considered an archive.
Edit: To be clear, I'm looking for a WP solution. I know that I can hard-code the CSS to get the menu item to appear the way I want it to be, but that doesn't seem to be the right thing to do.