Hi David,
I’d like to do it without having to install a new plugin.
I’ve achieved a nice result with this code below, but I am unable to customise CSS.
function wpcat_postsbytag() {
// the query
$the_query = new WP_Query( array( 'tag' => 'bombando-na-web', 'posts_per_page' => 6 ) );
// The Loop
if ( $the_query->have_posts() ) {
$string .= '<ul class="postsbytag widget_recent_entries">';
while ( $the_query->have_posts() ) {
$the_query->the_post();
if ( has_post_thumbnail() ) {
$string .= '<li>';
$string .= '<a href="' . get_the_permalink() .'" rel="bookmark">' . get_the_post_thumbnail($post_id, array( 50, 50) ) . get_the_title() .'</a></li>';
} else {
// if no featured image is found
$string .= '<li><a href="' . get_the_permalink() .'" rel="bookmark">' . get_the_title() .'</a></li>';
}
}
} else {
// no posts found
}
$string .= '</ul>';
return $string;
/* Restore original Post Data */
wp_reset_postdata();
}
// Add a shortcode
add_shortcode('categorytags', 'wpcat_postsbytag');
// Enable shortcodes in text widgets
add_filter('widget_text', 'do_shortcode');