motivatingfactor
Member
Posted 4 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
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.
motivatingfactor
Member
Posted 4 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..
What's this:
PREVIOUS POSTS
* WINTER DARK
* BUDS
motivatingfactor
Member
Posted 4 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.
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 }
}
?>
motivatingfactor
Member
Posted 4 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"
motivatingfactor
Member
Posted 4 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,
Welcome, i never tested the code... i just modified michaels....
Glad you got there in the end though.... ;)