• Resolved aceofjames

    (@aceofjames)


    I have been trying to get this shortcode to work properly for me to no avail.

    I want it to show posts from a specific category but only show 2 posts. This code shows all the posts in the category instead of 2 as I specify in the code.


    function category_shortcode( $atts )
    {
    extract(shortcode_atts(array(
    'limit' => '2',
    'category' => '',
    ), $atts));
    //The Query
    query_posts('category=' . $id . 'posts_per_page=' . $limit);
    //The Loop
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    echo '<h3><font color = blue> New Article:</font></h3>';
    echo the_content();
    endwhile; else:
    endif;

    //Reset Query
    wp_reset_query();
    }
    add_shortcode('category', 'category_shortcode');

    I use this shortcode on the page:

    [category id=3 limit=2]

    This shows all the posts instead of just two. Any idea what I am doing wrong?

    I am using shortcode because every query I did to display posts was not working.

    Basically I just need to show the two most recent posts in full on a specific page. I can use shortcode or a custom template.

    Can anyone help me out?

    Thank you in advance!

    James

Viewing 2 replies - 1 through 2 (of 2 total)
  • there is an ampersand & missing before posts_per_page=:

    query_posts('category=' . $id . '&posts_per_page=' . $limit);

    this might be all, or there could be more; just try to fix this first and see what changes.

    Thread Starter aceofjames

    (@aceofjames)

    Hey Alchymyth!

    That fixed it!

    Thanks and Merry Christmas!

    AceOfJames

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Shortcode for SHOW 2 POSTS’ is closed to new replies.