2013-08-28 31 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; ?>