-
-
Save tulanght/11130910 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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