Php 在WordPress小部件中显示帖子
我正在尝试过滤WordPress中短代码中显示的某些类别的内容。 我正在使用下面的,它显示了2个帖子,但我想能够说“显示类别为“苹果”的最新帖子或类别为“香蕉”的最新帖子” 我只是不知道如何执行筛选命令Php 在WordPress小部件中显示帖子,php,wordpress,widget,Php,Wordpress,Widget,我正在尝试过滤WordPress中短代码中显示的某些类别的内容。 我正在使用下面的,它显示了2个帖子,但我想能够说“显示类别为“苹果”的最新帖子或类别为“香蕉”的最新帖子” 我只是不知道如何执行筛选命令 add_shortcode( 'latest_posts', 'latest_posts' ); function latest_posts( $atts ) { ob_start(); $query = new WP_Query( array( 'post_type' => 'p
add_shortcode( 'latest_posts', 'latest_posts' );
function latest_posts( $atts ) {
ob_start();
$query = new WP_Query( array(
'post_type' => 'post', 'posts_per_page' =>2,'order' => 'DESC' ));
if ( $query->have_posts() ) { ?>
<?php while ($query->have_posts() ) : $query->the_post(); ?>
<div class="news-mini">
<p class="newsdate"><?php echo the_time(); ?></p>
<h2 class="newshead"><?php the_title(); ?></h2>
<a class="more-link" href="<?php the_permalink(); ?>" target="_blank">Read More >></a>
<hr>
</div>
<?php endwhile;
wp_reset_postdata(); ?>
<?php $myvariable = ob_get_clean();
return $myvariable;
}
add_shortcode('latest_posts','latest_posts');
职能部门最新职位($atts){
ob_start();
$query=新的WP\U查询(数组(
“发布类型”=>“发布”,“每页发布”=>2,“顺序”=>“描述”);
如果($query->have_posts()){?>
如果要按类别名称加载某些类别文章,请更新WP\u Query
如下:
$query = new WP_Query( array('post_type' => 'post',
'posts_per_page' =>2,
'order' => 'DESC',
'tax_query' => array(
'taxonomy' => 'NAME OF YOUR CATEGORY',
'field' => 'slug',
'terms' => 'category',
),
)));
问题:“slug”和“category”区域是否也需要更新?如果类别为“Apple”,slug为“Apple”"它看起来像:'taxonomy'=>'Apples','field'=>'Apples''terms'=>'Apples',还是'taxonomy'=>'Apples','field'=>'slug','terms'=>'category',@Niles'=>'category',@Niles不,他们不会,slug有点像post\u type
,它有术语类型名,它与您在'addnewcategory'@Niles second one'taxonomon'中看到的不同y'=>'苹果','字段'=>'鼻涕虫','术语'=>'类别'