2012-09-07 3 views
0

가장 최근 게시물을 표시하는 WordPress 사이트가 있습니다. 내용의 네 개의 행카테고리에 따라 WordPress에 표시되는 게시물 수 제한

http://tienvooracht.nl/themes/elevate/

세 개의 열 : 그들은이와 비슷한 디자인에서 출력됩니다. 여기에 내가 이해할 수없는 부분이 있습니다. 카테고리에 관계없이 가장 최근 게시물을 가져 오지 만 행당 표시되는 수를 제한하려면 어떻게해야합니까?

예 : 사진, 웹 디자인 및 UI 디자인 카테고리가 있습니다. 사진에 관한 5 개의 게시물을 연속적으로 쓰지 만, 내 가장 최근 게시물이 모두 사진에 관한 것이 아닐 것입니다.

그 한계에 도달하면 하나의 카테고리로 표시되고 다른 카테고리의 다른 글을 보여 얼마나 많은 게시물 제한하는 방법이 있나요?

답변

0

제한적입니까? 늘 그렇듯이. 그렇다면 WordPress의 읽기 설정에서 설정할 수 있습니다. 메인 루프가 $ x = 0 변수를 추가하기 전에; 그런 다음 루프에서 $ x ++를 추가하십시오. 그런 다음 두 번째 쿼리를 추가하면됩니다. 그들은 우리가 우리의 차 쿼리를 추가 할 수 페이지 당 최대 아래 인 경우

<?php 

$defaultPostsPerPage = 12; 

$sndary = $defaultPostsPerPage - $x; 

if($sndary > 0){ 
$y=0; 
$args = array('post_type'=>'post','post_per_page'=>12); 

$showcase = new WP_Query($args); 

if ($showcase->have_posts()) { while ($showcase->have_posts()) { $showcase->the_post(); ?> 
<!-- post html css goes here as you would any other loop --> 
<?php 
    if($y%4==0){ 
     //add some sort of css line break, clear fix or last class on the element. to break to the new line. 
    } 
} ?> 
<!-- post navigation --> 
<?php }else{ ?> 
<!-- no posts found --> 
<?php } 

} 

는 여기에서 우리는 메인 쿼리가 얼마나 많은 게시물 확인하고 있습니다. 여기서 주목해야 할 것은 페이지 매김을 고려하지 않았지만 질문의 일부가 아니란 점입니다.

0

특정 카테고리의 게시물을 제한하려면이 코드를 사용하십시오.

<?php 
global $post; 
$args = array('numberposts' => 5, 'category' => 3); 


$myposts = get_posts($args); 
foreach($myposts as $post) : 
setup_postdata($post); ?> 

<?php the_title(); ?> 
<?php the_content(); ?> 

<?php endforeach; ?> 

변경 카테고리 ID 및 사후 제한의 수 ...

0
<?php 
/* create categories array and pass id of categories from which we want to show the  posts*/ 
$categories=array(4,5,3); 
foreach($categories as $cat){ 
    global $post; 
    /* limit numberposts, here specified 2 and pass the categories dynamically in args array*/ 
    $args=array('numberposts' =>2, 'category' =>$cat); 
    $myposts=get_posts($args); 
    foreach($myposts as $mypost){ 
      echo "<h1>".$mypost->post_title."</h1> ".$mypost- >post_content." ".$mypost->post_modified; 
      echo "<br />"; 
    } 
} 

?>

관련 문제