Support » Plugins » Hacks » Limiting blog snippets in custom recent post feed

  • I have pages that use the existing blog structure of displaying a list of recent pages. I wanted however to also have a custom feed only on certain pages that would be slightly different. I have achieved the majority of this using the PHP Snippets plugi and building out my own PHP doc (attached). The issue I am having is I would like it to only pick up one category (success stories) and be limited to just 4 recent posts and not show the endless run it shows now. Any help would be very gratefully received! Thanks

    .col-620 {
        width: 980px;
    <?php get_header(); ?>
            <div id="content-blog" class="grid col-620">
            <?php $options = get_option('responsive_theme_options'); ?>
    		<?php if ($options['breadcrumb'] == 0): ?>
    		<?php echo responsive_breadcrumb_lists(); ?>
            <?php endif; ?>
        if ( get_query_var('paged') )
    	    $paged = get_query_var('paged');
    	elseif ( get_query_var('page') )
    	    $paged = get_query_var('page');
    		$paged = 1;
    <?php if (have_posts()) : ?>
    		<?php while (have_posts()) : the_post(); ?>
    			<div id="successpost">
                <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                    <div class="post-meta">
                    </div><!-- end of .post-meta -->
                    <div class="post-entry">
                        <?php if ( has_post_thumbnail()) : ?>
                            <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
                        <?php the_post_thumbnail(); ?>
                        <?php endif; ?>
                         <h5 class="post-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'responsive'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></h5>
                        <?php wp_link_pages(array('before' => '<div class="pagination">' . __('Pages:', 'responsive'), 'after' => '</div>')); ?>
                    </div><!-- end of .post-entry -->
                    <div class="post-data">
    				    <?php the_tags(__('Tagged with:', 'responsive') . ' ', ', ', '<br />'); ?>
    					<?php printf(__('Posted in %s', 'responsive'), in_category('news ')); ?>
                    </div><!-- end of .post-data -->             
                <div class="post-edit"><?php edit_post_link(__('Edit', 'responsive')); ?></div>
                </div><!-- end of #post-<?php the_ID(); ?> -->
            <?php endwhile; ?> 
    <?php endif; ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz


    Change your query_posts() call to this:

    query_posts( array(
      'post_type' => 'post',
      'paged' => $paged,
      'posts_per_page' => 4,
      'category_name => 'success-stories'

    Note the category name value must actually be the slug, so I may not have it quite right. Don’t forget to call wp_reset_query(); after the endwhile;

    Thanks so much for this, it was a huge help! It turns out all I needed was

    <?php wp_reset_query(); ?>

    to be at the end and that did all that needed to be done! To limit the blog posts within I was able to simply change the settings in the reading piece of the main wordpress settings as 4 will suffice for any blog feed

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Limiting blog snippets in custom recent post feed’ is closed to new replies.