2016-02-05 69 views
0

我有這個頁面中的WordPress:如何更改此功能以僅顯示兩次文章?

link

代碼PHP:

<?php 
query_posts('cat=16'); 
$count = 0; 
while (have_posts()) : the_post(); 
    $count++; 
    if ($count == 1) { ?> 

     <div class="row"> 
      <div class="col-lg-6 col-height" > 
       <div class="text-box-right"> 
        <div class="title-home"><?php the_title(); ?></div> 

        <div class="content-home"><?php the_content(); ?></div> 
       </div> 
      </div> 
      <div class="col-lg-6 col-height" > 
       <div class="prod-box-left"> 
        <?php the_post_thumbnail('news'); ?> 
       </div> 
      </div> 
     </div> 

     <div class="row"> 
      <div class="col-md-4"><div class="content-home"><?php the_content(); ?></div></div> 
      <div class="col-md-4">2</div> 
      <div class="col-md-4">3</div> 
     </div> 

    <?php } else { ?> 

     <?php $count = 0; ?> 

     <div class="row"> 
      <div class="col-lg-6 col-height" > 
       <div class=" prod-box-right"> 
        <?php the_post_thumbnail('news'); ?> 
       </div> 
      </div> 
      <div class="col-lg-6 col-height"> 
       <div class="text-box-right"> 
        <div class="title-home"><?php the_title(); ?></div> 
        <div class="conteont-home"><?php the_content(); ?></div> 

       </div> 
      </div> 
     </div> 

    <?php } ?> 

<?php endwhile; ?> 

的問題是,一些項目出現了兩次......我只是想在要顯示底端。

我放了一張照片,以更好地理解我的意思。

enter image description here

什麼是錯我的功能? 您認爲您可以幫我解決這個問題嗎?

在此先感謝!

回答

0

如果if語句對於if ($count == 1)爲真,則使用的代碼塊的功能爲the_content()兩次。我想這就是爲什麼你會得到重複的內容。刪除這些功能之一以消除重複。

0

您通常會看到最新的10個帖子。如果你想顯示僅2個職位,你可以用query_posts()像這樣:

<?php 
query_posts('posts_per_page=2'); 
?> 

所以,你必須這樣使用。

query_posts('cat=16&posts_per_page=2'); 

有關詳細參考,請參閱WordPress的功能query_posts()文檔在下面的鏈接 - https://codex.wordpress.org/Function_Reference/query_posts