WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Recent Posts Arguments? (9 posts)

  1. motivatingfactor
    Member
    Posted 5 years ago #

    Hello,

    I am building a theme: http://organic-tote-bags.com/blog/ - On the sidebar, I am displaying "Previous Posts" and I want the post date to show on the left of the post title. I am currently displaying this information using the "Recent Posts" widget. But I will code it in the sidebar, so I can achieve the desired effect, if needed.

    I'm sure this is possible, I'm just not sure how to achieve this. Any assistance will be very much appreciated.

    Very Best Regards,
    Richard

  2. MichaelH
    Member
    Posted 5 years ago #

    Play with this:

    <?php
    $posts=get_posts('showposts=5');
    if ($posts) {
    foreach($posts as $post) {
    setup_postdata($post);
    ?>
    <p>by <?php the_author(); ?><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    <?php }
    }
    ?>

    Consider downloading and installing Otto's php code widget and putting that code in one of those widgets:

    Please remember to support our plugin authors by clicking on the Donate button there.

  3. motivatingfactor
    Member
    Posted 5 years ago #

    Hello MichaelH,

    First of all, thanks for assisting me with this issue. I followed your instructions, however unfortunately it didn't work. You can see the results of the provided php code, after being placed inside Otto's widget here: http://www.organic-tote-bags.com/blog/

    Any ideas..

  4. MichaelH
    Member
    Posted 5 years ago #

    What's this:
    PREVIOUS POSTS
    * WINTER DARK
    * BUDS

  5. motivatingfactor
    Member
    Posted 5 years ago #

    Yes,
    * WINTER DARK
    * BUDS

    are the previous posts I would like to display, having the post date on their left-side. They are currently being displayed, using the "Recent Posts widget".

    Beneath "Archives" you will see:
    by adminBUDS
    by adminBUDS

    These are the results of the php code you provided, using Otto's Plugin.

  6. t31os
    Member
    Posted 5 years ago #

    Try something like...

    <?php
    $posts=get_posts('showposts=5');
    if ($posts) {
    foreach($posts as $post) {
    setup_postdata($post);
    ?>
    <p><?php the_time('l, F jS, Y') ?> at <?php the_time() ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
    <?php the_title(); ?></a>
    </p>
    <?php }
    }
    ?>
  7. motivatingfactor
    Member
    Posted 5 years ago #

    Ok, we are getting close. Below is the modified code I used:

    <?php
    $posts=get_posts('showposts=5');
    if ($posts) {
    foreach($posts as $post) {
    setup_postdata($post);
    ?>
    <p>"><?php the_time('j.m.y'); ?> / <?php the_title(); ?></p>
    <?php }
    }
    ?>

    But it only shows the oldest post "Buds" twice. It is not showing each post. How can I modify the above code to show each post and not the same post twice?

    You can view the results here: http://www.organic-tote-bags.com/blog/
    The results of the above code, appear beneath the heading "Test Code"

  8. motivatingfactor
    Member
    Posted 5 years ago #

    I got it,

    Using the following:

    <?php while (have_posts()) : the_post(); ?>
    <p>"><?php the_time('j.m.y'); ?> / <?php the_title(); ?></p>
    <?php endwhile; ?>

    Wow, the Otto's php code widget Plugin is great, I was able to use the same php that I used in the content area of the theme.

    Thanks for all your help t31os & MichaelH

    Regards,

  9. t31os
    Member
    Posted 5 years ago #

    Welcome, i never tested the code... i just modified michaels....

    Glad you got there in the end though.... ;)

Topic Closed

This topic has been closed to new replies.

About this Topic