Solved

wordpress recent posts with category

Posted on 2014-04-16
7
375 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with mod_substitute 18 44
Simple function not working 7 44
show child records separated by commas 12 38
Length of for loop to be dynamic 2 33
In this article, we will look at our content management system as a whole, to get an idea of how we will start to manage these content items.
This article discusses how to implement server side field validation and display customized error messages to the client.
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

730 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