Хотя этот пост дает вам хорошее начало, вот код, который я бы использовал
// Set the desired category
$category = 1;
// Make query for posts in the category
$my_query = new WP_Query();
$my_query->query(
array(
'cat' => $category,
// Does not show sticky posts; use 'caller_get_posts' if using < WP 3.1
'ignore_sticky_posts' => 1
)
);
// Make sure some posts were found.
if($my_query->have_posts())
{
// Loop through each post found.
while($my_query->have_posts())
{
// Setup the post data to use
$my_query->the_post();
global $post;
// Echo out the title; Note that no formatting has been done
the_title();
the_content();
}
}
Теперь вы также можете получить заголовок с помощью:
$title = get_the_title($post->ID);
$title = $post->post_title;
Кроме того, вы можете получить содержимое публикации с помощью:
$content = $post->post_content;
Кроме того, вы можете получить категорию, используя любой из следующих параметров:
cat (int) - use category id.
category_name (string) - use category slug (NOT name).
category__and (array) - use category id.
category__in (array) - use category id.
category__not_in (array) - use category id.
Подробнее о классе WP_Query можно найти здесь: http://codex.wordpress.org/Function_Reference/WP_Query