2015-09-30 201 views
0

我正在Wordpress中的新聞網站上工作。Wordpress分頁,不在編號頁面顯示一些內容

新聞報道都是帖子。

主頁在頂部有一個宣傳欄,然後是一個故事列表。

底部有分頁顯示其他頁面上的故事。

在主頁後面的頁面上,我不想顯示促銷部分。

的主頁上有像

mysite.co.uk/news 

,第二頁的URL就像是

mysite.co.uk/news//page/2 

(我不知道爲什麼有後的「新聞」兩隻盼着斜槓)

我試過在is_page上使用if語句,但它不起作用。

<?php 

     if(is_page('News')){ 
    ?> 

     <div class="news-content-block"> 

      <div class="container"> 

       <div class="news-content-block__header"> 

        <div class="row"> 

         <?php 

          $news_intro = array(

           'category_name' => 'news', 
           'post_type' => 'post', 
           'orderby' => 'date', 
           'order' => 'DESC', 
           'posts_per_page' => 2 
          ); 

          $news_loop = new WP_Query($news_intro); 

          if($news_loop->have_posts()) : 
           while($news_loop->have_posts()) : 
            $news_loop->the_post(); 
         ?> 

         <div class="col-sm-6"> 
          <div class="news-article-block"> 
           <a href="<?php the_permalink(); ?>"> 
            <?php the_post_thumbnail('news_header', array('class' => 'img-responsive'), true); ?> 
            <h4><?php the_title(); ?></h4> 
           </a> 
          </div> 
         </div> 

         <?php endwhile; endif; ?> 

         <?php wp_reset_postdata(); ?> 

        </div><!--row--> 

       </div> 

      </div><!--container--> 

     </div><!--content-block--> 

    <?php 
    } 
    ?> 

我怎麼只顯示促銷的東西新聞主頁上

+0

pagnation dispalying或無t?如果有更多頁面,則應在所有頁面上顯示 –

+0

分頁。這是主頁上的促銷部分我不想在其他頁面上顯示 – ttmt

+0

是否要嘗試我的工作代碼 –

回答

0

把這個代碼在你的頁面模板

if (!isset($wp_query->query_vars['paged']) || $wp_query->query_vars['paged'] == 1) : 
# Featured post code 
endif; 
+0

是#精選郵政編碼促銷部分我想隱藏在不是主頁的頁面上。這是我嘗試過的,但並未顯示在任何頁面上。 – ttmt

+0

使用此代碼特色的帖子只顯示第一頁 –

0

使用is_paged()功能:它會返回true,如果當前頁面數字大於1(因此它將返回false爲主頁,然後頁2,3等)。

if(is_paged()): 
    // feature code... 
endif; 
0

我的工作代碼:

http://localhost/wordpress/wp-admin/admin.php?page=video_comment&paged=2 $_REQUEST['paged']值從以下網址獲得

$paged = (!isset($_REQUEST['paged']) ? '1' : $_REQUEST['paged']); 
$args = array (
    'posts_per_page' => 10, 
    'paged' => $paged, 
    'search_prod_title' => $search_term, 
); 

$query = new WP_Query($args); 
?><?php if ($query->have_posts()) : ?><?php while ($query->have_posts()) : $query->the_post(); 

$current_stat= get_post_meta(get_the_ID(),'vc_stat'); 

if(isset($current_stat[0])) 
{ 
    if($current_stat[0]=='1') 
    { 
     $status='<label class="label label-success">Active</label>'; 
    } 
    else 
    { 
     $status='<label class="label label-danger">Inactive</label>'; 
    } 
}else 
{ 
     $status='<label class="label label-success">Active</label>'; 
} 

?> 
       <tr> 
        <td width="20%" id=""><?php the_title(); ?><input type="hidden" id="postID" value="<?php echo get_the_ID();?>"> 
        <input type="hidden" id="parmalink" value="<?php the_permalink() ?>"> 
        </td> 

        <td width="70%"> 

         <button type="button" class="btn btn-success view_vc" data-toggle="modal" data-target="#myModal">View Comments</button> 

       </td> 
       <td width="5%" id="status"><?php _e($status);?></td> 
        <td width="5%"><select class="action"> 
         <option>-Select-</option> 
         <option value="1" >Active</option> 
         <option value="0">Inactive</option> 
        </select></td> 
       </tr> 


<?php endwhile; ?> 

<?php endif; ?> 

enter image description here