Sim*_*mon 9 wordpress wordpress-theming
我是Wordpress的新手,并试图创建一个类别循环.循环应该是:
每个的html都是
<div class="cat_wrap">
<div class="cat_name">
<a href="<?php get_category_link( $category_id ); ?>">Cat Name</a>
</div>
<ul class="cat_items">
<li class="cat_item">
<a href="permalink">cat item 1</a>
</li>
<li class="cat_item">
<a href="permalink">cat item 2</a>
</li>
<li class="cat_item">
<a href="permalink">cat item 3</a>
</li>
<li class="cat_item">
<a href="permalink">cat item 4</a>
</li>
<li class="cat_item">
<a href="permalink">cat item 5</a>
</li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
请帮忙
小智 12
哎呀,错过了你想要5个帖子
<?php
//for each category, show 5 posts
$cat_args=array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories=get_categories($cat_args);
foreach($categories as $category) {
$args=array(
'showposts' => 5,
'category__in' => array($category->term_id),
'caller_get_posts'=>1
);
$posts=get_posts($args);
if ($posts) {
echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
foreach($posts as $post) {
setup_postdata($post); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
} // foreach($posts
} // if ($posts
} // foreach($categories
?>
Run Code Online (Sandbox Code Playgroud)
Hy在这里保持简单,就是如何解决它
<?php wp_list_categories('show_count=1&title_li=<h2>Categories</h2>'); ?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20630 次 |
| 最近记录: |