2015-10-20 99 views
2

在網站上工作,我需要有一個單獨的模板/頁面才能顯示該帖子。在其他模板/頁面上顯示一個帖子

在主頁上(索引)Ill循環遍歷我的類別並僅顯示其中的一部分 - 事件 - 新聞 - 引用。

像這樣:

  <?php 
      $query = new WP_Query(array('category_name' => 'Events')); 

      if ($query->have_posts()) 
      { 
       while ($query->have_posts()) : $query->the_post(); 
         $haveEvents = true; 
         if ($eventCount < 3) { 
          $eventCount++; 
          ?> 
          <div class="event-tile"> 
           <div class="event-tile-content"> 
            <h3><?php the_title(); ?></h3> 
            <h4><?php the_time('F jS, Y'); ?></h4> 
            <a href="<?php the_permalink(); ?>" class="event-tile-read-more">Lees meer</a> 
           </div> 
          </div> 
          <?php 
        } 
       endwhile; 
      } 

,每個節都有一個閱讀所有和讀取特定項目按鈕: enter image description here enter image description here

我已經找到了如何顯示一個類別中的所有職位分離頁面上命名爲:page-posts.php

On page-posts.php我只是檢查我是哪個頁面,並根據哪個頁面進行查詢以顯示帖子內的內容指定類別現在我不能,如何顯示在主頁上(的index.php)單後,單後的網頁上(甚至不花錢像谷歌時段後)計算出

 $query; 
     if (is_page('events')) { 
      $query = new WP_Query(array('category_name' => 'Events')); 
     } 
     elseif (is_page('news')) { 
      $query = new WP_Query(array('category_name' => 'News')); 
     } 

     if ($query->have_posts()) 
     { 
etc.. 

。 ..

在我使用的操作按鈕:

<a href="<?php the_permalink(); ?>" class="event-tile-read-more">Lees meer</a> 

這讓我回到主屏幕。 (剛開始使用Wordpress)

回答

1

在Wordpress主題single.php用於顯示帖子。如果它不存在,下降到使用index.php

請嘗試移動page-posts.phpsingle.php

+0

啊謝謝,這個作品,只是爲了記錄,我已經像幾個小時左右Google搜索,所以非常感謝! –

+0

順便說一句,我現在使用兩個,單一的只是一個類別中的所有職位的特定職位和網頁發佈! –

0

也許最好使用archive-events.php。您可以創建自定義帖子的存檔。

可以這樣做:其中活動是您的自定義發佈類型。然後登陸事件存檔頁面。

據我可以看到你的問題是,該職位是全球職位(從你家)。所以也許你可以setup_postdata($ post),或者使用home_url('url')函數。

+0

嘿沃特,感謝響應。我已經找到了使用存檔的東西,但這對我沒有幫助。有什麼優勢,因爲single.php適用於一個職位 –

相關問題