开发者

Wordpress Category And Posts [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

We would like to know the Wordpress more about Wordpress Category print and then print Post in selected category.

Like in this style

<h2>Categories Name 1</h2>
<ul>
<li>Post1</li>
<li>Post2</li>
<li>Post3</li>
<li>P开发者_运维问答ost4</li>
</ul>
<h2>Category Name 2</h2>
<ul>
<li>Post1</li>
<li>Post2</li>
<li>Post3</li>
<li>Post4</li>
</ul>


Wordpress provides a function to return all categories (get_categories()) and a function to list all posts of a category (WP Query object).

With the combination of the two, you can create the output you would like to do. The following is some example code that can be extended / changed with the parameters you need:

$categories = get_categories();
foreach($categories as $category)
{
  printf('<h2>%s</h2><ul>', $category->cat_name);
  $posts = new WP_Query('cat='.$category->cat_ID);
  while($posts->have_posts())
  {
    $posts->the_post();
    echo '<li>', the_title(), '</li>';
  }
  print '</ul>';     
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜