organizing posts by category
-
So I’m looking to organize posts by category. I need to have a webpage display three news articles that are a) of a specific category and b) if there are not 3 relevant posts in the child category any left over slots filled with the parent category and c) the parent category should display last regardless of date written. I’ve been messing with the code and came up with this:
<?php$args1 = array (
‘category_name’ => ‘child’,
‘posts_per_page’ => 3,
);
$args2 = array (
‘category_name’ => ‘parent’,
);
$the_query1 = new WP_query($args1);
$the_query2 = new WP_query($args2);?>
<!– Start the Loop –>
<?php if($the_query1->have_posts() ): while ( $the_query1->have_posts() ) : $the_query1->the_post(); ?><!– Display Title –>
<h1>“><?php the_title();?></h1><!– Display the post’s featured image –>
<?php the_post_thumbnail(‘blog-thumbnail’); ?><!– Display tags –>
<?php the_tags(); ?><!– Display Meta Data (edit in template-tags) –>
<?php archeroftheeye_posted_on(); ?>
<?php archeroftheeye_posted_by();?><!– Display content –>
<?php the_excerpt(); ?><!– Display post’s category –>
<!– <?php the_category(); ?> –><?php endwhile; ?>
<!– end loop –>
<?php endif ?><!– Start the Loop –>
<?php if($the_query2->have_posts() ): while ( $the_query2->have_posts() ) : $the_query2->the_post(); ?><!– Display Title –>
<h1>“><?php the_title();?></h1><!– Display the post’s featured image –>
<?php the_post_thumbnail(‘blog-thumbnail’); ?><!– Display tags –>
<?php the_tags(); ?><!– Display Meta Data (edit in template-tags) –>
<?php archeroftheeye_posted_on(); ?>
<?php archeroftheeye_posted_by();?><!– Display content –>
<?php the_excerpt(); ?><!– Display post’s category –>
<!– <?php the_category(); ?> –><?php endwhile; ?>
<!– end loop –>
<?php endif ?>
the problem is I don’t know how to limit the parent category to be whatever is left over and I was wondering if there was a more compact way to code it.
- The topic ‘organizing posts by category’ is closed to new replies.