WordPress.org

Ready to get started?Download WordPress

Forums

Recent posts by category in the sidebar, with thumbnails? (4 posts)

  1. la_ri_za
    Member
    Posted 5 years ago #

    Hi,

    does anyone happen to know any sidebar plugin which would both call the recent posts in specific category and make a thumbnail of the picture in the post (if it has one) placing it next to the excerpt/link?

    I have found only separate plugins for this, for example Category Posts Widget and Thumbnail For Excerpts, but it doesn't seem to work like that, and my php skills aren't good enough (=none) to modify them.

    I would be really grateful if someone could point me in the right direction!

  2. la_ri_za
    Member
    Posted 5 years ago #

    ok, I'm again answering to my own questions :), but I managed to customize Category POsts Widget by adding this (with my non-existent php-skills...):

    ' . '<img align="left" class="thumbnail_cat_posts" src="' . get_post_meta($post->ID, 'post_thumbnail', true) . '">

    into cat-posts.php, line 55:

    echo '<li class="cat-posts-item-' . $post->ID . '">' . '<img align="left" class="thumbnail_cat_posts" src="' . get_post_meta($post->ID, 'post_thumbnail', true) . '"><a href="' . get_permalink($post) . '">' . $post->post_title . '</a>';

    In other words, I used the custom values in the posts of this specific category.

    The problem is that I still cannot use it because of the img-tag - it makes the page ugly in IE if there is no thumbnail in some posts, and I want to keep that option too. And it's also quite painful to make the thumbnail every time I want to have one, I would really like to have it more or less automatically.

    So, I keep searching... unless someone has better ideas?

  3. webgirl
    Member
    Posted 5 years ago #

    I'm not a php genius myself, but managed to do an else for the thumbnail, thought I share the code with you like you have done. It's sometime hard to get people to share things that they have done. ;)

    Be sure to comment out line 55 with // and also you can align the image how you want by putting align=left in the img src.

    //Category with thumbnail
    $post_thumbnail = get_post_meta($post->ID, "post_thumbnail", true);
    
    if ($post_thumbnail != "")
    { 
    
    echo '<li class="cat-posts-item-' . $post->ID . '">' . '<img class="thumbnail_cat_posts" src="' . get_post_meta($post->ID, 'post_thumbnail', true) . '"><br /><a href="' . get_permalink($post) . '">' . $post->post_title . '</a>';
    
    } else {
    echo '<li class="cat-posts-item-' . $post->ID . '"><a href="' . get_permalink($post) . '">' . $post->post_title . '</a>';
     } 
    
    //End category with thumbnail
  4. publinero
    Member
    Posted 5 years ago #

    Hello,

    The first sollution is great. All you have to do is to add a custom field named “post_thumb” to each post of your blog.

    And if you want too customize the size of your image near title, add the following code:

    echo '<table width="100%"><td><div><li class="cat-posts-item-' . $post->ID . '"> ' . '<img align="left" width="50" height="35" src="' . get_post_meta($post->ID, 'post_thumb', true) . '"></div> <a href="' . get_permalink($post) . '">' . $post->post_title . '</a></td></table>';

Topic Closed

This topic has been closed to new replies.

About this Topic