• I have established a categories like:
    news, department1, department2, department3,(and many others)

    And my posts are often connected to 2 categories.

    Now I want to create a page with the latest news from each department.

    My theme is a child of Twenty Twelve, and I have added the following to functions.php:

    add_shortcode('tokat', 'to_kat');
    
    function to_kat($atts) {
    	extract(shortcode_atts(array('cata' => '', 'catb' => ''), $atts));
    	$category1 = explode(",",$cata);
    	$category2 = explode(",",$catb);
    	foreach ($category2 as $cat) :
    		query_posts( array( 'category__and' => array($category1,$cat), 'posts_per_page' => 1, 'orderby' => 'post_date', 'order' => 'DESC' ) );
    		while ( have_posts() ) : the_post();
    			get_template_part( 'content', get_post_format() );
    		endwhile;
    	endforeach;
    }

    And I have added [tokat cata="1" catb="2,3,4,5,6"] in a Page.

    But it doesn’t work.
    It might be my interpretation of the “query” or the “LOOP” that is wrong, but what is wrong?

Viewing 2 replies - 1 through 2 (of 2 total)
  • lisa

    (@contentiskey)

    are you trying to make a category archive page showing many posts from one category per page?

    or a single page displaying one or two posts each from many categories?

    Thread Starter Mikael Boldt

    (@boldt)

    I am trying to show 5 posts – one for each catb, which also is marked as cata on one page.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘list posts from a combination of 2 categories’ is closed to new replies.