Make WordPress Core

Opened 15 years ago

Closed 14 years ago

Last modified 14 years ago

#11550 closed feature request (worksforme)

Assign Categories to Static Pages

Reported by: westonruter's profile westonruter Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: has-patch reporter-feedback 2nd-opinion
Focuses: Cc:

Description

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.

My suggestion:

  1. 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).
  1. 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)
  1. Archive pages would be available under category page and would be restricted to posts in the category: /news/2009/12/ => /about/news/2009/12/
  1. 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.

Attachments (1)

category-static-pages.php (1.9 KB) - added by westonruter 15 years ago.
Theme customizations to get categories mapped to static pages and posts to appear under them.

Download all attachments as: .zip

Change History (16)

@westonruter
15 years ago

Theme customizations to get categories mapped to static pages and posts to appear under them.

#1 @hakre
15 years ago

I have to ask back:

I have a post "CAR" which is in the "NEW" category. And the "NEW" category has a category-page assigned. Then I get:

  1. A category-page I can request as /new/
  2. That category-page does a listing of all posts in that category
  3. Pre-Fixed posts-URLs, like /new/car/ for the post "CAR"

Does these assumptions fit for your concept?

#2 @hakre
15 years ago

  • Keywords has-patch reporter-feedback 2nd-opinion added; wp_rewrite permalinks categories static pages wp_list_pages category_link post_link removed

#3 @westonruter
15 years ago

@hakre: Yes. Whatever the permalink structure is for posts would be valid after the page name, if it begins with %category%. So if the permalink structure is: /%category%/%year%/%monthnum%/%postname%/

Then the "Car" post placed into the "New" category (which is assigned to a static page), the URI would be: /new/2010/02/car/

Archive pages would be accessible via appending the date to the category page URI:
'New' posts by month: /new/2010/02/
'New' posts by year: /new/2010/

#4 @janeforshort
15 years ago

  • Milestone changed from 3.0 to Future Release

This wasn't a feature we agreed to include in 3.0 when we determined scope. Taxonomies for pages is important, but I don't think we should try to squeeze it into 3.0... we agreed 3.0 would focus on the merge, custom post types and menu management. Since taxonomies on pages has a big effect on users, I don't feel comfortable putting it in without doing testing and considering it in relation to other taxonomy stuff. I'm changing the milestone to future release so that you can keep working on it without it distracting from the 3.0 dev effort.

#5 @janeforshort
15 years ago

  • Type changed from enhancement to feature request

#6 @janeforshort
15 years ago

  • Component changed from General to Taxonomy
  • Owner set to filosofo

#7 follow-up: @janeforshort
15 years ago

  • Owner filosofo deleted
  • Status changed from new to assigned

That's weird. I changed the component to taxonomy, but I definitely didn't add filosofo as owner. I have no idea why that is saying I did, so I'm removing filosofo as owner since it looks like some weird Trac bug.

#8 in reply to: ↑ 7 @filosofo
15 years ago

Replying to janeforshort:

That's weird. I changed the component to taxonomy, but I definitely didn't add filosofo as owner. I have no idea why that is saying I did, so I'm removing filosofo as owner since it looks like some weird Trac bug.

Some of us get certain components by default. You can see the complete list here.

#9 @nacin
15 years ago

Since pages are nothing more than a post type, then how much of this ticket is fixed with this attached to the init hook:

register_taxonomy_for_object_type( 'category', 'page' );

#10 follow-up: @scribu
15 years ago

xref: #10470

#11 @mch
14 years ago

i was waiting for 6 months to get the patch into WP 3.0. Can sameone tell me when i can use that functionality ??

#12 in reply to: ↑ 10 @mch
14 years ago

Replying to scribu:

xref: #10470

This is NOT an DUPLICITE - this functions set proper URL Path - my proposed patch allows to set more pages which displays post for different categories. This code USES ONLY ONE CATEGORY and DOES ONLY URL REWRITE.

#13 @kevinB
14 years ago

  • Cc kevinB added

#14 @nacin
14 years ago

  • Resolution set to worksforme
  • Status changed from assigned to closed

#15 @duck_
14 years ago

  • Milestone Future Release deleted
Note: See TracTickets for help on using tickets.