Wordpress - 在侧边栏“最近的帖子"中显示来自特定类别的帖子; [英] Wordpress - show posts from a particular category in sidebar "recent posts"

查看:31
本文介绍了Wordpress - 在侧边栏“最近的帖子"中显示来自特定类别的帖子;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让 WP 侧边栏中的最近的帖子"仅显示来自特定类别的帖子?

how can i make the "recent posts" in the WP sidebar show posts from a particular category only?

推荐答案

使用 Otto 的 php 代码小部件之一制作自己的最近帖子小部件可能最容易http://wordpress.org/extend/plugins/php-code-widget/ 和一个新查询:

Probably easiest to make your own recent posts widget with one of Otto's php code widgets http://wordpress.org/extend/plugins/php-code-widget/ and a new query:

<?php $my_query = new WP_Query('category_name=mycategory&showposts=1'); ?>

<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>

<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">

<?php the_title(); ?></a>

<?php endwhile; ?>

随心所欲地设计.新的查询循环不会与主 WP 循环发生冲突,并且可以使用任意次数.

Style it any way you want. The new query loop won't conflict with the main WP loop and can be used any numbers of time.

这篇关于Wordpress - 在侧边栏“最近的帖子"中显示来自特定类别的帖子;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆