WordPress.org

Ready to get started?Download WordPress

Forums

Showing metadata with get_recent_posts ? (8 posts)

  1. 3stripe
    Member
    Posted 8 years ago #

    I'm using Coffee2Code's get_recent_posts on my static homepage at http://www.tonguengroove.co.uk/index.php to list some recent posts.

    Is there a way to show the meta data under each post, so that the homepage looks more like my archive pages? (For example at http://www.tonguengroove.co.uk/content/events you can see category/posted by/comments).

    I can't find a mention of this in the plugin's support anywhere... :-?

    (Or, if get_recent_posts could show the category name, I think it would be easy enough to recreate all of this myself)

  2. iand
    Member
    Posted 8 years ago #

    I once managed something similiar (I think). get_recent_posts can't do the category but I used the following:
    <?php c2c_get_recent_posts(1,'<div class="post"><h2>%post_date%</h2> <h2 class="title">%post_URL%</h2><div class="meta">Filed by: %post_author%</div><div class="content">%post_content%&nbsp;<div class="feedback">category | <a href=%comments_url%> %comments_fancy%</a></div></div></div>','','date','DESC','0','F jS, Y',''); ?>

    You should be able to copy and paste to get all the code.

    Hope that helps.

  3. 3stripe
    Member
    Posted 8 years ago #

    Hey thanks Ian.... i've just been tring to hack the plugin and by adding this in the "Perform percent substitutions" loop I've almost got the category to show up now!

    case '%the_category%':
    $new = $new = the_category();
    break;

    So now I just include %the_category% when I call the function... but the category seems to be doing funny things to the layout as it's a link as well. Back to drawing board!

  4. iand
    Member
    Posted 8 years ago #

    I've just edited my code a little. If you do get the category to work can you post your solution for others to use?

  5. 3stripe
    Member
    Posted 8 years ago #

    Sure will...

    If you have a look at http://www.tonguengroove.co.uk/index.php you'll see the category is working, but not quite in the right place...

    I think it might be due to the link in the_category() so I'm going to try calling the unlinked version instead and then relink it

  6. 3stripe
    Member
    Posted 8 years ago #

    Can't work out how to feed in the category name...

    I need to write something like:

    $new = category_nicename;

    But I can only do this using the get_the_category function? (http://codex.wordpress.org/Template_Tags/get_the_category)

  7. 3stripe
    Member
    Posted 8 years ago #

    Got it working :-)

    Will post full solution when I've spoken to the plugin author!

  8. 3stripe
    Member
    Posted 8 years ago #

    Line 265-ish of customizable-post-listings.php, add:

    case '%post_category%':
    foreach((get_the_category()) as $cat) {
    $new = $cat->cat_name;
    }
    break;

    Line 309-ish of the same file, in the list of percentage tags, add:

    "%post_category%", // The category of the post

    Now when calling c2c_get_recent_posts you can include the category using %post_category% :-D

    Please note I've change the name to %post_category% instead of %the_category% to make it consistent with the rest of the plugin. At the moment this only adds the category name, not a link to the category. Still working on that!

Topic Closed

This topic has been closed to new replies.

About this Topic