WordPress.org

Ready to get started?Download WordPress

Forums

Display Posts Shortcode
[resolved] Can I pull list of posts from category excluding most recent post? (3 posts)

  1. sventhebaker
    Member
    Posted 2 years ago #

    I am looking to feature the most recent post, using a thumbnail etc. Is there a way to have a list right under the most recent post that just pulls 3 other posts that are older than the most recent?
    Example: Category X has posts from Aug 1, Aug, 2, Aug 3, Aug 4.
    I want to feature Aug 4 with thumb, but list Aug 3,2,1 below it.

    Thanks!

    Stephen

    http://wordpress.org/extend/plugins/display-posts-shortcode/

  2. Bill Erickson
    Member
    Plugin Author

    Posted 2 years ago #

    This is a bit outside the scope of this plugin. For your particular instance I'd recommend creating a page template that altered what was displayed based on the post count.

    Right before the loop you would put $counter = 1;

    Then, inside the loop do something like:

    if ( 1 == $counter ) {
    [your markup for your first featured post]
    } else {
    [your markup for all other posts]
    }
    $counter++;
  3. Bill Erickson
    Member
    Plugin Author

    Posted 2 years ago #

    Actually, now that I've added a filter to the shortcode you can do this. It will only work if the shortcode is used only once on the page. Place this in your functions.php file:

    /**
     * Exclude the first post
     * @author Bill Erickson
     * @link http://wordpress.org/extend/plugins/display-posts-shortcode/
     * @link http://wordpress.org/support/topic/plugin-display-posts-shortcode-can-i-pull-list-of-posts-from-category-excluding-most-recent-post
     *
     * @param $output string, original markup for an individual post
     * @return false or $output
     *
     */
    
    add_filter( 'display_posts_shortcode_output', 'be_exclude_first_post' );
    function be_exclude_first_post( $output ) {
    	global $exclude_first_post;
    	if ( !isset( $exclude_first_post ) ) {
    		$exclude_first_post = true;
    		return false;
    	} else {
    		return $output;
    	}
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic