2013-07-04 2 views
0

저자 목록으로 페이지에 게시물 목록을 원합니다. 저자 게시물은 각 페이지에서 동적으로 사용됩니다. 아래 코드를 사용했습니다.저자에 의한 Wordpress 게시 질의

<ul> 
<?php 
global $post; 
$args = array('posts_per_page' => 3, 'post_type'=> 'post', 'author_name' => 'ppm'); 
$myposts = get_posts($args); 
foreach($myposts as $post) : setup_postdata($post); ?> 

    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> 

<?php endforeach; ?> 
</ul> 

저자명 배열을 확인하십시오. ppm 사용자의 게시물을 표시하고 싶습니다. 이제 저는 역동적으로 할 것입니다. 페이지의 사용자 정의 필드에서 저자 이름을 가져오고 싶습니다. Like

<?php $author_name = get_post_meta($post->ID, 'author_name', true); ?> 
<ul> 
<?php 
global $post; 
$args = array('posts_per_page' => 3, 'post_type'=> 'post', 'author_name' => '$author_name'); 
$myposts = get_posts($args); 
foreach($myposts as $post) : setup_postdata($post); ?> 

    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> 

<?php endforeach; ?> 
</ul> 

그러나 코드가 작동하지 않습니다. 페이지의 사용자 정의 필드에서 작성자 이름을 얻으려면 어떻게합니까? 누구든지 도와 줄 수 있습니까?

약한 영어는 죄송합니다.

+0

'$ post-> ID'를 루프 외부에서 가져올 수 없습니다. – bboy

+0

코드를 참조하십시오 http://wordpress.stackexchange.com/questions/36135/how-can-i-list-posts-by-author 감사합니다, –

+0

나는 루프 안에 시도했지만 여전히 작동하지 않습니다. –

답변

1

이것은 저에게 효과적입니다. Sarim Khan에게 감사의 말씀을 전합니다.

<ul> 
<?php 
global $post; 
$author_name = get_post_meta($post->ID, 'author_name', true); 
$args = array('posts_per_page' => 3, 'post_type'=> 'post', 'author_name' => $author_name); 
$myposts = get_posts($args); 
foreach($myposts as $post) : setup_postdata($post); ?> 

    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> 

<?php endforeach; ?> 
</ul> 
0
<?php while (have_posts()) : the_post(); ?> 
<?php $author_name = get_post_meta($post->ID, 'author_name', true); ?> 
<?php endwhile; ?> 


<?php 
     $args = array('posts_per_page' => 3, 'post_type'=> 'post','meta_key'=>'author_name','meta_value'=>$author_name); 
     query_posts($args); 
?> 

<ul> 
<?php while (have_posts()) : the_post(); ?> 
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> 
<?php endwhile; ?> 
</ul>