我有自己的主题,我想在特定类别的主页上显示帖子.
到目前为止,我已经实现了这样:
<?php
global $post;
$args = array( 'numberposts' => 10, 'category' => 6 );
$posts = get_posts( $args );
foreach( $posts as $post ): setup_postdata($post);
?>
<divs with the_title() the_excerpt() etc ></div>
<?php
endforeach;
?>
Run Code Online (Sandbox Code Playgroud)
但是,如果我想通过它的slug获得该类别怎么办?或者是否可以在管理面板中简单地创建一个类别选择框?
loQ*_*loQ 28
用.替换你的category参数category_name
<?php
global $post;
$args = array( 'numberposts' => 10, 'category_name' => 'cat-slug' );
$posts = get_posts( $args );
foreach( $posts as $post ): setup_postdata($post);
?>
<divs with the_title() the_excerpt() etc ></div>
<?php endforeach; ?>
Run Code Online (Sandbox Code Playgroud)
欲了解更多信息:http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
| 归档时间: |
|
| 查看次数: |
52138 次 |
| 最近记录: |