Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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', '' );
}
share|improve this question
    
Please use the code button in an edit and reformat your question. It's highly unreadable that way. –  kaiser Jan 23 at 2:00
add comment

1 Answer 1

up vote 0 down vote accepted

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:

get_the_post_thumbnail(get_the_ID(),'thumbnail');
share|improve this answer
    
Thank you for the reply, I changed the_post_thumbnail to get_the_post_thumbnail and now the thumbnails are gone. Here is the link: beta.artimeg.com/2013/10/30/image-post (Sorry about the formatting on the original post, I used the code button, but I guess I messed it up.) –  user45531 Jan 23 at 19:02
    
@user45531 : see the edit –  s_ha_dum Jan 23 at 19:13
    
Great! Got the thumbnails working. But the first item in the list (the one without the link applied) gets put out of the widget. Also the thumbnails gets wrapped in <li> but the post title does not. The link above shows the current results. Thanks again for the help! –  user45531 Jan 23 at 19:47
    
$out .= $post_id === get_the_ID() ? the_title( '<li>' . get_the_post_thumbnail(get_the_ID(),'thumbnail'), '</li>', false ) : the_title( '<li>' . get_the_post_thumbnail(get_the_ID(),'thumbnail') . '<a href="' . get_permalink() . '">', '</a></li>', false ); Got it fixed. Here is the final code. Thanks again! –  user45531 Jan 24 at 4:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.