Example:
视频cat id=4视频cat儿童类别id=7,8,9新闻cat id=5新闻cat儿童类别id=11,12,13
我想在不同的档案中显示选定的类别(如视频和新闻)。php?
可以吗?谢谢。
(抱歉我的英语不好)
谢谢Chris S,但这不是我想做的。
<?php
$catPosts = new WP_Query();
$catPosts->query( array( \'category__and\' => array(5,11,12,13), \'posts_per_page\' => 5, \'orderby\' => \'date\', \'order\' => \'DESC\' ) );
while ($catPosts->have_posts()) : $catPosts->the_post(); ?>
<h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
<div class="meta">
By <?php the_author() ?>
</div>
<div class="content">
<?php the_excerpt(); ?>
</div>
当我写入父类别id时,我不想写入其子类别id。当我选择父类别id时,系统应将其子类别id保存在同一存档页中。
最合适的回答,由SO网友:Mridul Aggarwal 整理而成
创建2页类别新闻。php&;类别视频。php&;将此代码放入其中。然后根据需要自定义两者的标记
<?php
$children = get_categories(\'child_of\'=>get_query_var(\'cat\'));
$cat = array(get_query_var(\'cat\'));
foreach($children as $child)
$cat[] = $child->term_id;
$catPosts = new WP_Query( array( \'category__in\' => $cat, \'posts_per_page\' => 5, \'orderby\' => \'date\', \'order\' => \'DESC\' ) );
while ($catPosts->have_posts()) : $catPosts->the_post(); ?>
<h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
<div class="meta">
By <?php the_author() ?>
</div>
<div class="content">
<?php the_excerpt(); ?>
</div>
SO网友:chris_s
因此,您已经知道需要创建归档类别。每个类别的php模板。在每个模板中,您将为每个类别及其子类别调用自定义查询。例如:
<?php
$catPosts = new WP_Query();
$catPosts->query( array( \'category__in\' => array(5), \'posts_per_page\' => 5, \'orderby\' => \'date\', \'order\' => \'DESC\' ) );
while ($catPosts->have_posts()) : $catPosts->the_post(); ?>
<h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
<div class="meta">
By <?php the_author() ?>
</div>
<div class="content">
<?php the_excerpt(); ?>
</div>
这一个显示了“新闻”类别及其子类。请注意,您可以放置任何自己的标记来输出所需的HTML。