Wordpress 获取循环外部的_类别
我在一个有自定义作者页面的网站上工作,在作者页面上有一个最近的作者文章小部件,显示该作者的其他文章。这个网站有多个作者,所以每个帖子都不一样,我还没有找到一个插件可以做到这一点。我正在尝试显示文章缩略图、标题和类别名称 我正在使用一个显示标题和缩略图的函数,但它没有类别。我试着用以下方式添加类别:_类别(“”,'multiple',$authors_post->ID),不幸的是,它在第一个li中显示了所有类别。而不是每个职位 以下是我的工作内容:Wordpress 获取循环外部的_类别,wordpress,Wordpress,我在一个有自定义作者页面的网站上工作,在作者页面上有一个最近的作者文章小部件,显示该作者的其他文章。这个网站有多个作者,所以每个帖子都不一样,我还没有找到一个插件可以做到这一点。我正在尝试显示文章缩略图、标题和类别名称 我正在使用一个显示标题和缩略图的函数,但它没有类别。我试着用以下方式添加类别:_类别(“”,'multiple',$authors_post->ID),不幸的是,它在第一个li中显示了所有类别。而不是每个职位 以下是我的工作内容: function get_related_aut
function get_related_author_posts() {
global $authordata, $post;
$authors_posts = get_posts( array( 'author' => $authordata->ID,
'post__not_in' => array( $post->ID ), 'posts_per_page' => 3 ) );
$output = '<ul>';
foreach ( $authors_posts as $authors_post ) {
$output .= '<li>' . get_the_post_thumbnail( $authors_post->ID, 'xsmall-thumb' )
. '<p>' . the_category(' ','multiple',$authors_post->ID)
. '</p> <a href="' . get_permalink( $authors_post->ID )
. '">' . apply_filters( 'the_title', $authors_post->post_title,
$authors_post->ID ) . '</a></li>';
}
$output .= '</ul>';
return $output;
函数get\u related\u author\u posts(){
全局$authordata,$post;
$authors\u posts=get\u posts(数组('author'=>$authordata->ID,
'post_unot_in'=>array($post->ID),'posts_per_page'=>3));
$output='';
foreach($authors\u post作为$authors\u post){
$output.='- '。获取文章缩略图($authors\u post->ID,'xsmall thumb'))
“”。类别(“,”多个“,$authors\u post->ID)
“
”;
}
$output.='
';
返回$output;
}
任何帮助都将不胜感激,
谢谢 请尝试此代码
<?php
$cat=1;
$yourcat = get_category($cat);
if ($yourcat)
{
echo '<h2>' . $yourcat->name . '</h2>';
}
?>
要获取类别名称,请尝试以下操作
function get_related_author_posts() {
global $authordata, $post;
$authors_posts = get_posts( array( 'author' => $authordata->ID, 'post__not_in' => array( $post->ID ), 'posts_per_page' => 3 ) );
$output = '<ul>';
foreach ( $authors_posts as $authors_post ) {
$category = get_the_category($authors_post->ID);
foreach($category as $c){
$cat=$c->cat_name.' '.$cat;
}
$output .= '<li>' . get_the_post_thumbnail( $authors_post->ID, 'xsmall-thumb' ) . '<p>' . $cat . '</p> <a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a></li>';
}
$output .= '</ul>';
return $output;
}
函数get\u related\u author\u posts(){
全局$authordata,$post;
$authors\u posts=get\u posts(数组('author'=>$authordata->ID,'post\u not\u in'=>array($post->ID),'posts\u per\u page'=>3));
$output='';
foreach($authors\u post作为$authors\u post){
$category=获取\u类别($authors\u post->ID);
foreach($c类){
$cat=$c->cat_名称。“”。$cat;
}
$output.='- ”。获取“发布”缩略图($authors\u post->ID,'xsmall thumb')。'.$cat.
”;
}
$output.='
';
返回$output;
}
希望这项工作对你有用。谢谢!这让我更接近我的目标,它显示类别名称,不,我只需要它输出到类别的链接。