0

カスタム作成者ページを持つサイトで作業しており、作成者ページには、その作成者による他の投稿を表示する最近の作成者投稿ウィジェットがあります。このサイトには複数の作成者がいるため、投稿ごとに異なり、これを行うプラグインは見つかりませんでした. 投稿のサムネイル、タイトル、カテゴリ名を表示しようとしています。

タイトルとサムネイルを表示している関数を使用していますが、カテゴリがありません。カテゴリを追加しようとしました: the_category(' ','multiple',$authors_post->ID) 残念ながら、最初の li にすべてのカテゴリが表示されます。各投稿の代わりに。

これが私が取り組んでいるものです:

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;

}

どんな助けでも大歓迎です、ありがとう!

4

2 に答える 2

0

のようなことを試してください

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;
}

これがうまくいくことを願っています..

于 2013-04-08T06:05:19.260 に答える