Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 21st Jan 2016, 11:58 AM   #1
Warrior Member
 
Join Date: 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default
On wordpess how can i show recent posts on sidebar
Share on: 
fb share twitter share gplus share more share

I have sticky posts on my site and this code doesn't work properly because of them. How can i show only recent posts on sidebar with codes.

PHP Code:
<ul><?php $posts=get_posts("numberposts=10&orderby=post_date&order=DESC"); foreach($posts as $post) : ?><li><a href=""><?php the_title(); ?></a></li><?php endforeach; ?></ul>
McCoyTR is offline  
Unread 30th Jan 2016, 12:46 PM   #2
Active Warrior
 
rmmfree's Avatar
 
Join Date: 2016
Posts: 45
Thanks: 37
Thanked 10 Times in 10 Posts
Default
Re: On wordpess how can i show recent posts on sidebar
Share on: 
fb share twitter share gplus share more share

The code seems to be fine. Be sure to run it after the post content is displayed, not before.
rmmfree is offline  
Unread 30th Jan 2016, 02:50 PM   #3
Web Designer
 
Join Date: 2013
Posts: 70
Thanks: 0
Thanked 19 Times in 18 Posts
Default
Re: On wordpess how can i show recent posts on sidebar
Share on: 
fb share twitter share gplus share more share

Try this code, I have not tested it.

<?php
$args = array(
'post__not_in' => get_option( 'sticky_posts' ),
'posts_per_page' => 10,
'orderby' => 'date',
'order' => 'DESC'
);
$posts = get_posts($args);
?>
<ul>
<?php foreach($posts as $post):?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; wp_reset_postdata();?>
</ul>
Nathan K is offline  
Unread 6th Feb 2016, 10:41 AM   #4
Senior Web Developer
 
Join Date: 2016
Location: Bangladesh
Posts: 16
Thanks: 0
Thanked 3 Times in 3 Posts
Default
Re: On wordpess how can i show recent posts on sidebar
Share on: 
fb share twitter share gplus share more share

You can install a plugin 'Recent post plugin' which will show your recent posts to your sidebar.

Hasan Fardous is offline  
Closed Thread


Bookmarks

Tags
posts, recent, show, sidebar, wordpess


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 02:42 PM.