2014-11-03 2 views
0

퀴즈와 같은 WordPress에 플러그인을 만들고 싶지만 특별한 질문이 아닙니다. 게시물에만 해당됩니다. 4 게시물 사이에 1 개의 추천 이미지와 4 개의 게시물이 표시됩니다. 손님은 특색 지어진 심상의 맞은 제목을 선정 할 것이다. 나는 임의의 게시물을 받고있다.워드 프레스에서 임의의 글 중 하나를 선택하십시오.

<ul> 
<?php $posts = get_posts('orderby=rand&numberposts=4'); foreach($posts as $post) { ?> 
<li><p desc="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></p> 
</li> 
<?php } ?> 
</ul> 

그러나 나는 무작위로 정답을 선택하고 질문으로 추천 이미지를 얻는 방법을 해결할 수 없었습니다.

PLS는

답변

0
<ul> 
    <?php 
     $arr = array(); 
     $posts = get_posts('orderby=rand&numberposts=4'); 
     foreach($posts as $post) { ?> 
     <li> 
      <p desc="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?> </p> 
      <?php $arr[ get_the_ID() ]; // store every post id in array ?> 
     </li> 
    <?php } ?> 
</ul> 
<?php 
    $id = array_rand($arr); // choose one random post id 
    echo get_the_post_thumbnail($id,'thumbnail'); // get thubnail against id 
?> 

사용이 코드를 도와 '$ ID'값을 사용자가 선택한 후 ID를 비교합니다.

건배 !!!

관련 문제