2013-04-08 1 views
0

저는 맞춤 작성자 페이지가있는 사이트에서 작업하고 있습니다. 작성자 페이지에는 해당 작성자의 다른 게시물을 표시하는 최근 작성자 게시물 위젯이 있습니다. 이 사이트는 여러 명의 작가가 있으므로 모든 게시물마다 다르며이 작업을 수행하는 플러그인을 찾지 못했습니다. 게시물 미리보기 이미지, 제목 및 카테고리 이름을 표시하려고합니다.루프 밖에서 the_category 얻기

제목과 미리보기 이미지를 표시하는 기능을 사용하고 있지만 카테고리가 없습니다. 나는 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; 

}, 감사합니다!

<?php 
$cat=1; 
$yourcat = get_category($cat); 
if ($yourcat) 
{ 
    echo '<h2>' . $yourcat->name . '</h2>'; 
} 
?> 

카테고리 이름을 얻으려면

답변

0

이 코드를 시도하십시오,

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

희망과 같은 몇 가지 일을하려고 그게 작동하지 않는 것 : ( – user1272433

+0

'get_the_category ($ cat_id)'와 함께 작동해야합니다 ... –

0

+0

고마워! 이것은 내 목표에 더 가까워지고, 범주 이름을 표시하며, 범주에 대한 링크를 출력하는 데 필요하지 않습니다. – user1272433

관련 문제