I am using the plugin: Series and by default it only gets the linked posts titles. I would like to add the post thumbnails as well. I was able to get the thumbnails to appear, but they show up outside of the widget. I added: the_post_thumbnail(‘thumbnail’) parts. The full template is below.
Thank you for the help!
/**
* Displays a list of posts by series ID.
*
* @since 0.1.0
* @param array $args
* @return string
*/
function series_list_posts( $args = array() ) {
if ( empty( $args['series'] ) )
return;
$out = '';
$post_id = 0;
if ( in_the_loop() )
$post_id = get_the_ID();
else if ( is_singular() )
$post_id = get_queried_object_id();
$defaults = array(
'series' => '', // term slug
'order' => 'ASC',
'orderby' => 'date',
'posts_per_page' => -1,
'echo' => true,
);
$args = wp_parse_args( $args, $defaults );
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
$out .= '<ul class="series-list">';
while ( $loop->have_posts() ) {
$loop->the_post();
$out .= $post_id === get_the_ID() ? the_title( '<li>' . the_post_thumbnail('thumbnail') . '</li>', false ) : the_title( '<li>' . the_post_thumbnail('thumbnail') . '<a href="' . get_permalink() . '">', '</a></li>', false );
}
$out .= '</ul>';
}
wp_reset_postdata();
if ( false === $args['echo'] )
return $out;
echo $out;
}
/**
* Displays a list of posts related to the post by the first series.
*
* @since 0.1.0
* @param array $args
* @return string
*/
function series_list_related( $args = array() ) {
$post_id = 0;
if ( in_the_loop() )
$post_id = get_the_ID();
else if ( is_singular() )
$post_id = get_queried_object_id();
if ( !empty( $post_id ) )
$series = get_the_terms( $post_id, 'series' );
if ( empty( $series ) )
return;
$series = reset( $series );
$args['series'] = $series->slug;
return series_list_posts( $args );
}
/* === DEPRECATED === */
/**
* @since 0.1.0
* @deprecated 0.2.0
*/
function get_series_feed_link( $cat_id, $feed = '' ) {
_deprecated_function( __FUNCTION__, '0.2.0', 'get_term_feed_link' );
return get_term_feed_link( $term_id, 'series', $feed );
}
/**
* @since 0.1.0
* @deprecated 0.2.0
*/
function is_series( $slug = false ) {
_deprecated_function( __FUNCTION__, '0.2.0', 'is_tax' );
return is_tax( 'series', $slug );
}
/**
* @since 0.1.0
* @deprecated 0.2.0
*/
function in_series( $series, $_post = null ) {
_deprecated_function( __FUNCTION__, '0.2.0', 'has_term' );
return has_term( $series, 'series', $_post );
}
/**
* @since 0.1.0
* @deprecated 0.2.0
*/
function create_series_taxonomy() {
_deprecated_function( __FUNCTION__, '0.2.0', '' );
}
/**
* @since 0.1.0
* @deprecated 0.2.0
*/
function series_register_widgets() {
_deprecated_function( __FUNCTION__, '0.2.0', '' );
}
the_post_thumbnail
prints data to the screen immediately. It does not return a string that you can concatenate into your$out
variable.Use
get_the_post_thumbnail
instead.Make sure you get the arguments right. They are different from the arguments for
the_post_thumbnail
. Should be something like: