Posts with Tag on Bottom of Page

Here’s a quick shortcode I put together for your functions.php file if you want to use it as a starting point. or it can be converted to a plugin if you prefer.

function wpse27961_show_tagged_posts( $atts ) {
    extract( shortcode_atts( array(
        'tags' => '',
        'number' => 5,
    ), $atts ) );

    $args = array(
        'posts_per_page' => $number,
        'tag' => $tags
    );

    $wpse_tagged_posts = new WP_Query( $args );

    $output = "";

    if($wpse_tagged_posts):
        $output .= "<ul>";
        while($wpse_tagged_posts->have_posts()):
            $wpse_tagged_posts->the_post();
            $output .= '<li><a href="';
            $output .= get_permalink();
            $output .= '">';
            $output .= the_title( '', '', false );
            $output .= '</a></li>';
        endwhile;
        $output .= "</ul>";
    endif;

    wp_reset_query();

    return $output;
}
add_shortcode( 'wpse_tagged_posts', 'wpse27961_show_tagged_posts' );

yeah, it’s not pretty, but someone can tweak it if they have the time. add the shortcode to your page like this:

[wpse_tagged_posts tags="foo,bar"]

it’ll default to showing 5 posts. or if you want a specific number of posts:

[wpse_tagged_posts tags="foo,bar" number="6"]

tech