Solved

wordpress recent posts with category

Posted on 2014-04-16
7
368 Views
Last Modified: 2014-05-01
i am using the shortcode [recent-posts] on a page and its working perfectly.  However, instead of all posts appearing, I want only posts from a certain category to appear.  How do I code this?
0
Comment
Question by:livewirewebsolutions
  • 3
  • 3
7 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 40005584
Is this a wordpress.com site or a .org site?

If .org, which plugin are you using to get the shortcode?
0
 

Author Comment

by:livewirewebsolutions
ID: 40005589
its a wordpess site using the twenty twelve theme
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 40005599
Haven't answered my questions.

Is this self hosted or hosted through wordpress.com? Twenty Twelve exists on both.

If self hosted, which plugins are installed?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:livewirewebsolutions
ID: 40005617
self hosted.  wordpress shortcodes plugin is installed but i don't think its the reason why [recent-posts] works.  Doesn't that shortcode come with Wordpress?
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 40005645
Doesn't that shortcode come with Wordpress?

Nope :)

Self-hosted WordPress doesn't come with any shortcodes out of the box...they are added in by coding, themes, and plugins.  Wordpress.com is a different story. Which shortcode plugin is this...there are two or three people who make one?
0
 

Author Comment

by:livewirewebsolutions
ID: 40005650
this is the link to the plugin: http://synved.com/wordpress-shortcodes/
0
 
LVL 15

Accepted Solution

by:
eemit earned 330 total points
ID: 40006432
Try this in your theme's functions.php:
add_filter( 'widget_posts_args', 'yourchildthemeslug_extend_recent_posts_query' );
function yourchildthemeslug_extend_recent_posts_query( $args ) {
	$args['category__in'] = array('2'); //change '2' to your category ID
	
	//use this to show posts from more categories
	//$args['category__in'] = array('2', '3'); //change '2' and '3' to your category IDs

	return $args;
}

Open in new window

Change 'yourchildthemeslug' to your child theme's slug.
If your child theme's slug contains hyphens, replace them with underscores (You can not use a hyphen in a PHP function name).
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question