Skip to content

Instantly share code, notes, and snippets.

@tulanght
Forked from NateJacobs/gist:1263835
Created April 21, 2014 02:46
Show Gist options
  • Save tulanght/11130910 to your computer and use it in GitHub Desktop.
Save tulanght/11130910 to your computer and use it in GitHub Desktop.
<?php
/* This part goes in your functions.php */
/**
* Get Some Posts
*
* Use get_posts to get an array of posts matching a set of criteria.
* The category_name is passed to the function.
* get_posts uses the same parameters as WP_query. See the Codex for the full details..
* http://codex.wordpress.org/Template_Tags/get_posts
*
* @author Nate Jacobs
* @link https://gist.github.com/1263835
*/
function ngtj_get_some_posts( $category_name )
{
// set the criteria
$args = array(
'numberposts' => 10,
'category_name' => $category_name
);
// return the object array of the posts.
return get_posts( $args );
}
?>
<?php
/* This part goes where you would like the posts to display */
$posts_returned = ngtj_get_some_posts( 'CATEGORY_NAME' );
foreach ( $posts_returned as $post_returned )
{
echo $post_returned->post_title.'<br>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment