• I’m new to WordPress and I’m having some trouble finding a way to link to multiple categories (the link takes you to a page, similar to a standard blog page, where all the posts are listed.

    I can make a simple link to a single category using this http://localhost/portal/?cat=29 however, I need the category to include more than one category.

    Looking through the Codex I found this. If I understand it correctly, it would allow me to change what category(ies) are displayed on the default blog template, but I don’t want to make a broad structural change (I need flexibility).

    I also found this in the Codex. If I understand it correctly, I would have to create category templates for every combination of categories I would need to have in a blog post page. That would be a lot of work, but more importantly it wouldn’t allow much flexibility since I would have to modify the code and create a template for each new category need.

    I’ll close with a quick description of what I am working with. I have 10 departments, and each department has 3 areas (which are the same for each of the 10 departments). I will need to categorize posts with a department and one of the 3 areas. I then will need to link to a blog page that lists all the posts with particular department category and area only.

    Using a plugin I could create new custom post types, but then I would have to create 10 template pages. It’s an answer, but requires more work (which is only bad because I’m not a php coder).

Viewing 4 replies - 1 through 4 (of 4 total)
  • I think this support ticket contains the answer you’re looking for:

    https://wordpress.org/support/topic/how-can-i-filter-posts-belonging-to-2-categories-with-query_posts?replies=20

    You’ll definitely have to do a little custom coding to get this working. I don’t know of any default functionality in WordPress that will query for posts in two categories.

    Another thing I would look at doing is not overloading the “category” taxonomy two serve two purposes. I would create two taxonomies “department” and “area” with the appropriate options, and then query against those.

    Shawn

    Thread Starter thisismyalias

    (@thisismyalias)

    Thanks for the quick response Shawn. I read the post you linked to and I’m just too new to grasp it all. If the query goes in a template file or in the functions.php file (and passed a string from the template file) it appears to me that it wouldn’t work because I would have to create template files for each department.

    Ugh. I’m lost.

    How about you create a template file that using something like this:

    $department=$_GET['department'];
    $tag=$_GET['area'];
    
    $args = array(
    	'cat'      => $department,
    	'tag'     => $tag
    );
    
    query_posts( $args );
    
    // The Loop
    while ( have_posts() ) : the_post();
        echo '<li>';
        the_title();
        echo '</li>';
    endwhile;
    
    // Reset Query
    wp_reset_query();

    (code not tested)

    In this example you’d use a tag to specify the area.

    Then you can link to it like this:

    http://example.com/deparment-posts?department=computers&area=software

    I was thinking the same thing as octalmage, use the querystring to pass in the department & area parameters.

    Combine that logic with the category__and query in the post I sent you and that should do it.

    Shawn

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘A single link to multiple categories’ is closed to new replies.