WordPress.org

Forums

[resolved] Advanced customization of category archive pages (4 posts)

  1. jayant
    Member
    Posted 7 years ago #

    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.

  2. 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.

  3. jayant
    Member
    Posted 7 years ago #

    Yes the AND operation. Thanks.

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

  4. 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.

Topic Closed

This topic has been closed to new replies.

About this Topic