2016-11-19 29 views
0

我建立一個主題,我category.php頁面上的其餘部分我想展示幾個全員額(假設3,但需要能夠改變這到2或1很容易),然後其餘的職位類別作爲標題鏈接。顯示catgegory頁面上三個完整的帖子,再上崗的僅標題

我有相當多的HTML在我環路造型我的職位,加入所有的代碼很抱歉自定義字段,但是這是我的category.php頁面的樣子了。我已經嘗試了一些沒有工作的東西,所以編輯了這個來顯示我的原始代碼,它只是有一個正常的職位列表。我對編輯The Loop有所不同,因此會盡可能多地解釋/澄清。

<?php 
    /** 
    * The template for displaying Category Archive pages. 
    */ 

    get_header(); ?> 

    <div id="primary" class="<?php 
    $category = get_the_category(); 
      echo $category[0]->cat_name; 
      ?>"> 


    <div id="feature-container" class="full-width-container"> 
     <div class="full-width-container content-page" id="tagline-wrapper"> 
       <div id="left-black"></div> 
       <div class="page-width-container"> 
        <div id="tagline-box"> 
         <h1 class="category-title">Transactions</h1> 
        </div> 
       </div> 
      </div> 
    </div>   

    <div id="content-wrapper"> 

     <div id="project-menu" class="page-width-container"> 
      <?php wp_nav_menu(array('theme_location' => 'project-types')); ?> 
     </div> 



     <div id="content" role="main" > 



    <?php if (have_posts()) : while (have_posts()) : the_post(); ?> 


      <div class="story-container" class="module-container"> 
       <div class="our-story"> 
        <div class="story-image"> 

      <?php 
        // check if the post has a Post Thumbnail assigned to it. 
       if (has_post_thumbnail()) { 
        the_post_thumbnail(); 
       } 
      ?> 

        </div> 
        <div class="story-text"> 
         <article class="post" id="post-<?php the_ID(); ?>"> 
          <div class="entry-container"> 

       <h2><a href="<?php the_permalink() ?>#content" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> 

       <div class="project-details"> 

        <p><span class="details-location"><?php 
         global $wp_query; 
         $postid = $wp_query->post->ID; 
         echo get_post_meta($postid, '_project-location', true); 
         wp_reset_query(); 
         ?></span><br /> 
         <span class="details-funding"><?php 
         global $wp_query; 
         $postid = $wp_query->post->ID; 
         echo get_post_meta($postid, '_funding-type', true); 
         wp_reset_query(); 
         ?> | <?php 
         global $wp_query; 
         $postid = $wp_query->post->ID; 
         echo get_post_meta($postid, '_funding-source', true); 
         wp_reset_query(); 
         ?></span><br /> 
         <span class="details-value"><?php 
         global $wp_query; 
         $postid = $wp_query->post->ID; 
         echo get_post_meta($postid, '_project-value', true); 
         wp_reset_query(); 
         ?></span></p> 

       </div> 



      <div class="entry"> 



       <?php the_content(); ?> 



       <?php wp_link_pages(array('before' => __('Pages: ','html5reset'), 'next_or_number' => 'number')); ?> 

      </div> 

      <?php edit_post_link(__('Edit this entry','html5reset'), '<p>', '</p>'); ?> 

      </div> 

     </article> 

        </div> 
       </div> 

      </div> 


      <?php endwhile; endif; ?> 


</div><!-- #content --> 
     </div> 
     </div><!-- #primary --> 

<?php get_footer(); ?> 
+0

將$ per_page更改爲3以獲得3個帖子,並在while循環中使用計數器查看計數器是否大於2不要調用the_content()。@ Devonanne –

+0

謝謝 - 你能舉一個例子說明你是怎麼做的改變上面的代碼?仍然不完全清楚哪些部分要改變。 – Devonanne

+0

你好,你可以創建循環條件 –

回答

0

您可以使用下面的代碼achive上面的事情: 首先你要循環所有發佈和,並把當它達到超過2其停止打印content.but標題會在那裏總是計數器。

 <?php $countPost=1;?> 
     <?php if (have_posts()) : ?> 
     <?php while (have_posts()) : the_post(); ?> 
     <div class="post"> 
     <h2 id="post-<?php the_ID(); ?>"> 
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> 

     <?php if($countPost>2) : /*Condition for Content*/ 
     the_content(); 
     endif; 
     ?> 
      </div> 
     <?php endwhile; ?> 
    <div class="navigation"> 
    <div class="alignleft"> 
    <?php posts_nav_link('','','&laquo; Previous Entries') ?> 
    </div> 
    <div class="alignright"> 
    <?php posts_nav_link('','Next Entries &raquo;','') ?> 
    </div> 
     </div> 
    <?php else : ?> 
     <h2 class="center">Not Found</h2> 
    <p class="center"><?php _e("Sorry, but you are looking for something that isn't here."); ?></p> 
     <?php endif; ?> 
    </div> 

欲瞭解更多詳情,請參閱: https://codex.wordpress.org/The_Loop_in_Action

+0

這不適合我不幸的 - 它只顯示標題只爲所有職位。 – Devonanne

+0

你可以在這裏發佈category.php文件嗎? –

+0

是的,我有內容和標題。我只希望能夠在#content div中顯示前3個帖子中的所有內容,並在其下方顯示該類別中剩餘帖子的帖子標題列表。抱歉,我無法提供鏈接,目前只在本地進行。我也許可以得到一份拷貝在線爲你但如果你真的認爲這將有助於:) – Devonanne

0

我想通了一下我自己的一種變通方法解決的,雖然它依賴於使用插件/部件是不是我寧願。

我只是設置的閱讀設置來顯示2個職位,然後循環之下我添加了一個小工具區域,並使用小工具擴展到顯示標題/鏈接的列表中最近的帖子。這個小部件允許你跳過列表中的一定數量的帖子,所以我將它設置爲從第3個帖子開始。沒有選擇僅顯示當前類別的帖子,所以我不得不使用Widget Context插件,並使用特定類別的各個小部件顯示在相應的類別頁面上。正如我所說的那樣,有點複雜的解決方案,但最終結果正是我想要實現的。

相關問題