Support » Plugin: Display Posts Shortcode » [Suggestion] Added image_float property to thumbnail / image listing

  • Resolved BertvanDorp


    Let me start by thanking for the great work on this plugin!

    I was using this to display an excerpt of a post, when I noticed I couldn’t use CSS to format the thumbnail image inside the div. So I altered the display-posts-shortcode.php to support setting the image float property. Here’s a guide:

    1) I included the option for image_float after line 57:
    'image_float' => 'left',
    2) Then some security:
    $image_float = sanitize_text_field( $atts['image_float'] );
    after line ~82
    3) Altered the HTML image implementation:
    $image = '<a class="image" style="float: '. $image_float .'" href="' . get_permalink() . '">' . get_the_post_thumbnail( $post->ID, $image_size ) . '</a> ';
    in line ~232.

    So now, it defaults to float: left for the image, and you can use the shortcode to set it differently: image_float=[left/right/etc]

    Is this something that could make it into the official release? Would love this functionality!

    Also, now we’re talking.. is it hard to include funcitonality to just simply display one single post? Just like the embed_posts plugin actually, except that one isn’t maintained anymore. There’s quite some uses for this actually, and I would have loved this functionality back when I was less experienced.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Bill Erickson


    Why can’t you use CSS to do it without modifying the plugin?

    .display-post-listing img { float: left; }

    If you really need this as accessible in the shortcode (some images you want floated left, others right), then you can use the output filter to modify the image based on your new attribute. Example (not related to what you’re doing, but shows you the filter):

    You should already be able to display a single post. [display-posts id=”xxx”]

    The [display-posts id=”xxx”] didn’t work in my custom post type (Event from Events Manager), that’s why I requested it. Didn’t look into the cause though, as I switched to another solution for this.

    Hmm looks like there’s quite a lot of CSS to be learned on my end, I was happy to have even found a solution. Hope this will help others as well, thanks for suggesting a more thorough solution!

    For custom post types, you’ll need to pass the post_type argument to the shortcode as well.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Suggestion] Added image_float property to thumbnail / image listing’ is closed to new replies.