Assign Categories to Static Pages
|Reported by:||westonruter||Owned by:|
|Component:||Taxonomy||Keywords:||has-patch reporter-feedback 2nd-opinion|
I have identified my most frequently-written theme customization: assigning categories to static pages so that they appear in wp_list_pages, as well as making in_category() posts appear on this category page and under it in the URI structure. Something similar is already possible in the Reading Settings where you can assign a static page to be the "posts page", but this applies to all posts in all categories and it does nothing to the permalinks for posts.
- For each category in the admin, provide a new dropdown option for selecting a static page to use for the category template, say a "News" category assigned to a "About > News" page (/category/news/ => /about/news/). The environment on this invoked page template would be very similar to when is_posts_page. The WP_Query for this page would be for all posts in the category, and the template would have to have a loop for iterating over them (would default to category.php not page.php).
- Posts in a category which is assigned a static page would appear under that page's page_uri. For example, instead of /news/2009/12/hello-world/ it would appear as /about/news/2009/12/hello-world/ (and attempting to go to the first would 301 redirect to the latter)
- Archive pages would be available under category page and would be restricted to posts in the category: /news/2009/12/ => /about/news/2009/12/
- When viewing a singe post in the category, wp_list_pages would add a current_page_ancestor class to the category page item.
See attached code for some of what I end up doing for almost every WordPress site I implement.
Change History (16)
- Keywords has-patch reporter-feedback 2nd-opinion added; wp_rewrite permalinks categories static pages wp_list_pages category_link post_link removed
6 years ago
- Owner filosofo deleted
- Status changed from new to assigned