WordPress.org

Ready to get started?Download WordPress

Forums

Limiting blog snippets in custom recent post feed (3 posts)

  1. jamesgrayking
    Member
    Posted 1 year ago #

    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

    http://ceedus.com/cms/?page_id=275

    <style>
    .col-620 {
        width: 980px;
    }
    </style>
    
    <?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; ?>
    <?php
        if ( get_query_var('paged') )
    	    $paged = get_query_var('paged');
    	elseif ( get_query_var('page') )
    	    $paged = get_query_var('page');
    	else
    		$paged = 1;
    		query_posts("post_type=post&paged=$paged");
    ?> 
    
    <?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(); ?>
                            </a>
                        <?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(); ?> -->
                </div>
            <?php endwhile; ?> 
    
    <?php endif; ?>
  2. bcworkz
    Member
    Posted 1 year ago #

    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;

  3. jamesgrayking
    Member
    Posted 1 year ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic