Php 试图在wordpress中仅显示一个类别的帖子
我正在使用磁铁主题,并试图在主页上显示来自单一类别的帖子。我已经阅读了好几篇文章,但没有使用我找到的建议方法 下面是home-page-grid.php文件中的代码片段,该文件似乎正在向主页添加帖子Php 试图在wordpress中仅显示一个类别的帖子,php,wordpress,Php,Wordpress,我正在使用磁铁主题,并试图在主页上显示来自单一类别的帖子。我已经阅读了好几篇文章,但没有使用我找到的建议方法 下面是home-page-grid.php文件中的代码片段,该文件似乎正在向主页添加帖子 <!-- Start content --> <div class="grid_8" id="content"> <div class="widget_container content_page"> &
<!-- Start content -->
<div class="grid_8" id="content">
<div class="widget_container content_page">
<div class="post_list_medium_widget">
<div class="post_list_medium_style1">
<?php
global $paged;
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} elseif ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}
$query = new WP_Query( array ( 'paged' => $paged, 'orderby' => 'date', 'order' => 'DESC' ) );
$row_count=0;
while ( $query->have_posts() ) {
$row_count++;
$query->the_post();
$post_id = get_the_ID();
?>
想知道需要做些什么才能显示单个类别及其所有子类别吗?尝试添加此数组项:
'cat'=>'14'
14是类别id
$query = new WP_Query( array ( 'paged' => $paged, 'cat' => '14', 'orderby' => 'date', 'order' => 'DESC' ) );
<?php
$catPost = get_posts(get_cat_ID("your_category_name")); //change this with your category
foreach ($catPost as $post) : setup_postdata($post); ?>
<div>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p><?php the_content(); ?></p>
</div>
<?php endforeach;?>