2015-01-22 2 views
0

특정 카테고리의 임의의 게시물 유형을 표시하는 코드 조각이 하나의 게시물을 표시하지만 이제는 임의로 표시됩니다. 매번 임의 게시물을 보여주고 싶습니다. 사용자가이 페이지를 새로 고치면 모든 조언과 제안 사항이 크게 알려질 것입니다.임의의 게시물 유형 및 카테고리 WordPress를 표시하는 방법

Thansk :)

<?php 

global $post; 
$args = array(
    'post_type'=>'topics', 
    'showposts'=>'1', 
    'cat'=> 8, 
    'orderby' => 'rand' 
); 

$query = 'orderby=rand'; 
$my_query = new WP_Query($args);?> 
<?php 
while ($my_query->have_posts()) : $my_query->the_post();?> 
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> 

<?php endwhile; 
wp_reset_query(); ?> 
여기

답변

3
Hi Use this code for getting random posts..It works for me !!! 

<h1>Random Posts</h1> 
<ul> 
<?php 
$args = array('posts_per_page' => 5, 'orderby' => 'rand','category' =>'8','post_type' => 'topics'); 
$rand_posts = get_posts($args); 
foreach ($rand_posts as $post) : 
    setup_postdata($post); ?> 
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> 
<?php endforeach; 
wp_reset_postdata(); ?> 
</ul> 

는 ORDERBY 파라미터 값은 MySQL RAND() 함수를 사용하여 무작위로 5 개 포스트 목록 표시

관련 문제