2016-07-11 8 views
1

ブートストラップを使ってWordpressアーカイブブログテンプレートを作成したいと思います。Wordpressブログ第1行2列第2行と続けている行3列

最初の行の最初のポストは8列、2番目のポストは4列にする必要があります。

2番目の行と継続する行には、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

ありがとうございますJames私はこれを実装します – DarrenLee

+0

これがあなたを助けた場合、アップアップ/マーキングを受け入れることを検討してください! –

+0

ジェームスのテンプレートは完全に表示されます。データとタイトルと抜粋はどうやって引っ張りますか? – DarrenLee

関連する問題