获取 WordPress 中作者存档页面的作者帖子 url 链接
function fix_canonical() {
global $paged;
if (is_category()) {
$catid = get_query_var('cat');
echo '
<link rel="canonical" href="'.get_category_link($catid).'" />
<meta name="description" content="'.$meta.'" />';
if ($paged > 1) echo '
<meta name="robots" content="noindex,follow" />';
} else {
echo '';
}
if (is_tag()) {
$tagid = get_query_var('tag_id');
echo '
<link rel="canonical" href="'.get_tag_link($tagid).'" />';
if ($paged > 1) echo '
<meta name="robots" content="noindex,follow" />';
} else {
echo '';
}
}
add_action('wp_head', 'fix_canonical');
functions.php
如您所见,我在代码中获得了类别和标签档案的根永久链接。现在我想获取作者的存档链接。我该怎么做呢?
function fix_canonical() {
global $paged;
if (is_category()) {
$catid = get_query_var('cat');
echo '
<link rel="canonical" href="'.get_category_link($catid).'" />
<meta name="description" content="'.$meta.'" />';
if ($paged > 1) echo '
<meta name="robots" content="noindex,follow" />';
} else {
echo '';
}
if (is_tag()) {
$tagid = get_query_var('tag_id');
echo '
<link rel="canonical" href="'.get_tag_link($tagid).'" />';
if ($paged > 1) echo '
<meta name="robots" content="noindex,follow" />';
} else {
echo '';
}
}
add_action('wp_head', 'fix_canonical');
functions.php
As you can see i have got the root permalink for the category and tag archives in the code. Now I want to get the archive link for authors. How can I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以这样做(您必须更改主题中的 header.php/index.php。不要摆弄functions.php,当 WordPress 升级时它会自动覆盖。)
get_users_of_blog() 函数将生成一个包含 user_name、user_id 等的对象数组。鉴于您的博客/主题支持 my_blog.com/authors/AUTHOR_ID 这是可能的,但我宁愿使用 这个插件
It's possible to do this (you'd have to change the header.php/index.php in your theme. Do not fiddle with functions.php, it's automatically overwritten when Wordpress is upgraded.)
The
get_users_of_blog()
function will yield an array of objects containing user_name, user_id and so forth. Given that your blog/theme supports my_blog.com/authors/AUTHOR_ID this would be possible, but I'd rather use this plugin