WordPress.org

Support

Support » Themes and Templates » [Resolved] Advanced customization of category archive pages

[Resolved] Advanced customization of category archive pages

  • I have the following category structure:
    CatA
    CatB
    CatC
    CatD
    CatE
    CatFrontPage

    When the user sees the CatA’s category archive page: http://www.example.com/category/cata
    I will want to display posts which belong to both CatA as well as CatFrontPage.

    When the user sees the CatB’s category archive page: http://www.example.com/category/catb
    I will want to display posts which belong to both CatB as well as CatFrontPage.

    Also, I must handle it from category.php and not category-catid.php.
    The reason is I have 100 such categories and hence maintaining theme changes across them will be insane.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Samuel Wood (Otto)

    @otto42

    WordPress.org Tech Dude

    I will want to display posts which belong to both CatA as well as CatFrontPage.

    Do you mean an AND operation? Where the post must be in both categories?

    If so, then you need to change your query, basically. Before you start the Loop, you modify the query to also require the CatFrontPage, using category__and:

    query_posts(array(
    'category__and'=>array(123,get_query_var('cat')),
    'paged'=>get_query_var('paged')
    ));

    Where “123” is the ID number of CatFrontPage. The addition of the ‘paged’ is to keep paging working correctly.

    Yes the AND operation. Thanks.

    I think we need to document this. I cannot find documentation on “get_query_var” or on “category__and”.

    Moderator Samuel Wood (Otto)

    @otto42

    WordPress.org Tech Dude

    get_query_var has been around a long time. It just gets the variables back out of the current main query.

    category__and is relatively new and doesn’t quite work properly in all cases yet. It got introduced around the same time tags made it into the core and all the terms stuff was introduced.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Advanced customization of category archive pages’ is closed to new replies.