如何在任何页面上的任意位置打印特定的 WordPress 类别?
有人可以告诉我 PHP 会是什么样子,以便从 Wordpress 获取类别,然后将其打印在我想要的地方吗?
我猜我必须构建一个 PHP 函数。类似于:
function get_a_category() {
$category = get_the_category(); <-----(不确定如何获取特定类别)
echo $category;
我
不知道我对 PHP 一无所知,
有人可以帮助我吗?
Can someone tell me what the PHP would look like in order to get a category from Wordpress and then print it where ever I want?
I'm guessing I have to build a PHP function. Something like:
function get_a_category() {
$category = get_the_category(); <-----( not sure how to ge ta specific category )
echo $category;
}
I have no idea I know nothing about PHP
can someone help me please ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不必编写自己的函数;您必须使用 The Loop (WordPress Codex) 和新查询 (函数参考/查询帖子 « WordPress Codex) 以保持原始 WP 循环不变。在页面模板中运行此新查询以获取“mycategory”中的第一篇文章。将 showposts 更改为您想要的帖子数量。
You don't have to write your own function; you do have to work with the The Loop (WordPress Codex) and a new query (Function Reference/query posts « WordPress Codex) to keep the original WP loop in place. Run this new query in a page template to get the first post from "mycategory". Change showposts to the number of posts you want.
试试这个
Try this