2016-11-19 6 views
0

私はテーマを作成し、category.phpページにいくつかの完全な投稿を表示したいと思います。これを2または1に簡単に)、次にカテゴリ内の残りの投稿をタイトルリンクとして表示します。catgegoryページに3つの完全な記事を表示し、残りの投稿をタイトルとして残す

自分の投稿をスタイリングしてカスタムフィールドを追加するために、私のループにかなりの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

3件の投稿を取得するために$ per_pageを3に変更し、whileループでカウンタを使用してください。counterが2より大きい場合はthe_content()を呼び出してください。@ Devonanne –

+0

ありがとうございます。上記のコードを変更しますか?変更する部分をまだ完全には明らかにしていません。 – Devonanne

+0

こんにちは、条件付きループを作成することができます –

答えて

0

次のコードを使用して上記のことをachiveことができます。 まずあなたがループにすべてのポストとを持っており、それは常に存在しますcontent.butタイトルを印刷するより、その後2そのストップに達するカウンターを置きます。詳細については

 <?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プラグインも使用し、特定のカテゴリを持つ個々のウィジェットをそれぞれの対応するカテゴリページに表示する必要がありました。私が言ったように、ちょっとした複雑な解決策ですが、最終的な結果はまさに私が達成したかったものです。

関連する問題