Support » How-To and Troubleshooting » Display posts from a single category

Display posts from a single category

  • Right now I have a piece of code on my homepage that is pulling in the most recent posts from a set of categories. However, I only want it to pull in the posts from category #15. Can someone please help me tweak this code to do that?

    <?php $allCats = get_categories();
    						$blogCats = array();
    						$blogcat = get_cat_ID(get_option('15'));
    						foreach ($allCats as $category) {
    							if (in_subcat($blogcat, $category->cat_ID)) $blogCats[] = $category->cat_ID;
    						$args = array('category__not_in' => $blogCats,
    									  'showposts' => get_option('portfolio_number'));
    						$i = 1;
    						if (have_posts()) : while (have_posts()) : the_post(); ?>
    							<?php include(TEMPLATEPATH . '/includes/gallery.php'); ?>
    						<?php $i++; endwhile; endif; wp_reset_query(); ?>
Viewing 1 replies (of 1 total)
  • If you do a Google search there is a heap of answers to this

    while(have_posts()) : the_post();
    <li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
    <ul><li><?php the_content(); ?></li>
    <?php endwhile; ?>


    <?php $recent = new WP_Query(); ?>
    <?php $recent->query('cat=15&showposts=5'); ?>
    <?php while($recent->have_posts()) : $recent->the_post(); ?>
                <a href="<?php the_permalink(); ?>">
                <?php the_title(); ?>
    <?php endwhile; ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Display posts from a single category’ is closed to new replies.
Skip to toolbar