WordPress.org

Ready to get started?Download WordPress

Forums

Page2cat: Category, Pages & Posts Shortcodes
[resolved] [Plugin: Category Page] Want to display a thumbnail with catlist tag (12 posts)

  1. TheDailyDG
    Member
    Posted 3 years ago #

    Hi all, I'm using the "catlist" tag in the Category Page plugin to display pages with post excerpts, as in: http://es.diegograglia.net/horahispana/
    I want to display a thumbnail for each post. I have activated thumbnails in functions.php and assigned a "featured image" to the posts.
    Now I don't know how to write the php to have catlist call it. Would this be correct? (I only added the line in bold.)

    foreach($catposts as $single):
    $output .= "<h3>ID)."'>".$single->post_title."</h3>";
    $output .= "$single->post_excerpt";
    $output .= "$single->the_post_thumbnail()";

    endforeach;

    Thanks for any help!

  2. Pneumonic
    Member
    Posted 3 years ago #

    It'd be better to put it into it's own variable instead. While it makes the code longer, if something changes in wp or something you have the benefit of changing only one thing:

    $the_thumbnail = get_the_post_thumbnail($single->ID, 'thumbnail');
    $output .= $the_thumbnail

    I just added this functionality in though. You can check it out here.

  3. TheDailyDG
    Member
    Posted 3 years ago #

    I used the whole code you posted in the other thread and it works like a charm: http://es.diegograglia.net/horahispana/
    I just need to style it a bit and it'll be perfect.
    Thank you very very much, Pneumonic.

  4. TheDailyDG
    Member
    Posted 3 years ago #

    I just realized one thing though: it doesn't use the manual excerpt but the first 500 words from the actual post. How can I change that?
    Thanks a bunch.

  5. TheDailyDG
    Member
    Posted 3 years ago #

    Ok, I figured this out by myself! So here it is for anyone as ignorant as myself.

    [For me, PHP is like being in a foreign country where I'm using a phrase book to find the bus terminal. Don't know the language but I usually, slowly, get there.]

    My theme had a conflict with the neat_trim function, so I had to delete that for the plugin to work.

    Here's what I wrote --you'll tell me how unorthodox it is-- to have the thumbnail AND the manually-written post excerpt in the page that displays a category's posts.

    All I had to do was change the $single_post_content line to this:

    foreach($catposts as $single): $single_post_content = $single->post_excerpt;

    ... where post_excerpt replaces post_content.

    Again, big thanks to Pneumonic for helping out.

  6. Pneumonic
    Member
    Posted 3 years ago #

    Damn wordpress not notifying me of replies again...

    Anyhow. Yeah that's spot on how I'd go about doing it though (without actually looking at my hacked-ass code :). Glad I was able to help.

  7. Marcus Thompson
    Member
    Posted 2 years ago #

    Hey All,

    I've tried everything here and I'm getting the feature image of the page as a thumbnail in my list, not the featured image of the post.

    Thanks,

  8. TheDailyDG
    Member
    Posted 2 years ago #

    Hi Marcus, maybe you're using the wrong category ID?
    I did this three months ago and honestly don't remember exactly how it worked, but it could help if you publish a link.

  9. Marcus Thompson
    Member
    Posted 2 years ago #

    I have the right category ID. I'm now just getting the list of posts and not the post thumbnail.

    http://vangi-art.com/animals/

    at what line does the code need to go?

  10. Marcus Thompson
    Member
    Posted 2 years ago #

    OK, so here's my new dilemma :P

    I can get just a thumbnail with excerpt and I select "Yes" for the thumbnail, or I can get the full post. If I set the number of characters (I'm assuming it's characters) from 500 to 0, I still get the full excerpt. If I deselect excerpt and select yes for thumbnails, I only get a title.

    Thanks again.

  11. TheDailyDG
    Member
    Posted 2 years ago #

    Well, your problem seems to be the same I had. And that's where that altered line of code came in:

    "All I had to do was change the $single_post_content line to this:

    foreach($catposts as $single): $single_post_content = $single->post_excerpt;

    ... where post_excerpt replaces post_content."

    That did it for me. Hope it works.

  12. Marcus Thompson
    Member
    Posted 2 years ago #

    Yay it works! Thanks for your help.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic