2016-07-11 2 views
1

부트 스트랩을 사용하여 Wordpress 보관 블로그 서식 파일을 만들고 싶습니다.Wordpress 블로그 첫 행 2 열 두 번째 연속 행 3 열

첫 번째 행의 첫 번째 게시물은 8 열이고 두 번째 게시물은 4 열이어야합니다.

두 번째 행과 연속 된 행은 4 개의 열로 된 게시물을 가져야합니다.

저는 PHP 카운터가이 템플릿을 사용할 수 있다고 믿습니다. 누군가 코드 작성 방법을 알고 있습니까?

템플릿 예제 : WP_Post 객체의 배열을 반환 게시물을 얻을 get_posts() 모든 게시물을 얻어서 enter image description here

+2

시도해보고 코드를 게시하십시오! –

답변

0

시작.

// Get all our posts, and start the counter 
$postNumber = 0; 
$args = array(
    'posts_per_page' => 8 
); 
$posts = get_posts($args); 
// Loop through each of our posts 
foreach ($posts as $post) { 
    // If we're at the first post, or just before a post number that is divisible by three then we start a new row 
    if (($postNumber == 0) || (($postNumber+1) % 3 == 0)) { 
     echo '<div class="row">'; 
    } 
    // Choose the post class based on what number post we are 
    $postClass = ''; 
    if ($postNumber == 0) { 
     $postClass .= "col-md-8"; 
    } else { 
     $postClass .= "col-md-4"; 
    } 
    echo '<div class="'.$postClass.'">'; 
    // Print the post data... 
    echo $postNumber. " " . $postClass; 
    echo "</div>"; 
    // If we are at the second post, or we're just after a post number divisible by three we are at the end of the row 
    if (($postNumber == 1) || (($postNumber-1) % 3 == 0)) { 
     echo '</div>'; // close row tag 
    } 
    $postNumber++; // Increment counter 
} 

이이 같은 몇 가지 출력을 제공합니다 :

output-data

당신은 분명히 당신의 템플릿을 기반으로이를 수정해야하지만 나는 그렇게 같은 게시물을 통해 다음 루프를 거라고 당신에게 좋은 출발점을 주어야합니다.

+0

고마워요 제임스가 이것을 구현합니다 – DarrenLee

+0

이것이 도움이된다면 upvoting/marking을 받아 들여야합니다! –

+0

제임스 템플릿이 완벽하게 표시됩니다. 어떻게 데이터, 제목 및 발췌 내용을 가져 오나요? – DarrenLee