2013-08-28 29 views
1

對不起,我對WordPress編碼和從零開始學習它很新。請原諒我缺乏經驗。日期基礎檔案在WordPress主頁

我有一個自定義後類型,稱爲「產品」,並希望只顯示他們在網頁上的日期基於歸檔。但是,我不想顯示帖子標題或帖子中的任何其他內容,但該日期前三到四個帖子中的內容除外。事情是這樣的:

This is what I want to do

我想下面的代碼,但它返回的職位爲正常循環。

<?php $query = new WP_Query(array('post_type' => 'products', 'orderby' => 'date')); ?> 
    <?php if ($query->have_posts()) : ?> 

     <?php /* Start the Loop */ ?> 
     <?php while ($query->have_posts()) : $query->the_post(); ?> 

      <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 
      <?php 
       $archive_year = get_the_time('Y'); 
       $archive_month = get_the_time('m'); 
       $archive_day = get_the_time('d'); 
      ?> 
      <div class="idpostdate"> 
       <a href="<?php echo get_day_link($archive_year, $archive_month, $archive_day); ?>"><?php the_date('F j, Y', '', '<span class="datetext">: Click Here To View Products</span>', true);?></a> 
      </div> 
      <div class="thumbnail"> 
       <?php if (has_post_thumbnail()) { the_post_thumbnail('homet'); } ?> 

      </article> 

     <?php endwhile; ?> 


    <?php else : ?> 

     <?php get_template_part('no-results', 'index'); ?> 

    <?php endif; ?> 

任何指導?

回答

1

功能如the_ID()the_post_thumbnail()運行在主要查詢。如果你想在你的代碼中使用他們的等價物,你需要爲它們加上$query->

未經檢驗的,但我認爲它會做你想讓它是什麼:

<?php $query = new WP_Query(array('post_type' => 'products', 'orderby' => 'date')); ?> 
<?php if ($query->have_posts()) : ?> 

    <?php /* Start the Loop */ ?> 
    <?php while ($query->have_posts()) : $query->the_post(); ?> 

     <article id="post-<?php $query->the_ID(); ?>" <?php $query->post_class(); ?>> 
     <?php 
      $archive_year = $query->get_the_time('Y'); 
      $archive_month = $query->get_the_time('m'); 
      $archive_day = $query->get_the_time('d'); 
     ?> 
     <div class="idpostdate"> 
      <a href="<?php echo get_day_link($archive_year, $archive_month, $archive_day); ?>"><?php $query->the_date('F j, Y', '', '<span class="datetext">: Click Here To View Products</span>', true);?></a> 
     </div> 
     <div class="thumbnail"> 
      <?php if ($query->has_post_thumbnail()) { $query->the_post_thumbnail('homet'); } ?> 

     </article> 

    <?php endwhile; ?> 


<?php else : ?> 

    <?php get_template_part('no-results', 'index'); ?> 

<?php endif; ?>