2013-03-05 151 views
0

我正在为一个客户端的网站工作,我特别需要修改一个给定的WordPress模板。该模板使用get_template_part函数来调用内容。因此,对于索引页面上的循环,它应该在标题下显示the_date,但出于某种原因,它显示在某些帖子上,而不是全部。什么可以使wordpress中的the_date函数只显示在随机帖子上

的index.php

<?php get_header(); ?> 
<!-- Content --> 
    <div class="container contentarea"> 
     <div class="row"> 
      <div class="column-content"> 
       <div id="content" role="main"> 
        <?php if (have_posts()) : ?> 

        <?php while (have_posts()) : the_post(); ?> 
         <!-- Call content.php --> 
         <?php get_template_part('content'); ?> 
        <?php endwhile; ?> 

        <div class="clearfix"></div> 

        <div class="paging"> 
         <?php  if(function_exists('lugada_kriesi_pagination')) : lugada_kriesi_pagination(); else: ?> 
         <?php global $wp_query; $total_pages =  $wp_query->max_num_pages; if ($total_pages > 1) { ?> 
          <div id="nav-below" class="navigation"> 
           <div class="nav-previous"><?php next_posts_link(__('<span class="meta-nav">&laquo;</span> Older posts', 'newzeo')) ?></div>  
           <div class="nav-next"><?php previous_posts_link(__('Newer posts <span class="meta-nav">&raquo;</span>', 'newzeo')) ?></div>  
          </div> 
         <?php } endif; ?> 
        </div> 

        <?php else : ?> 

         <article id="post-0" class="post no-results not-found"> 
          <header class="entry-header"> 
           <h1 class="entry-title">Nothing Found</h1> 
          </header> 
          <div class="entry-content"> 
           <p>Sorry, we can't find post you request. Please try search for a related post.</p> 

           </div> 
          </article> 

         <?php endif; ?> 


       </div> <!-- #content --> 
      </div> <!-- .column-content --> 
      <div class="column-sidebar nomargin"> 
       <?php get_sidebar(); ?> 
      </div> 

     </div> 
    </div> 

<?php get_footer(); ?> 

content.php

<div class="content-box bucket"> 

    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?> itemscope itemtype="http://schema.org/Article" > 

      <h2 class="entry-header"> 

       <div class="entry-meta clearfix" > 

        <!-- Sticky post --> 
        <?php if (is_sticky()) : ?> 
        <div class="sticky-label"></div> 
       <?php endif; ?> 

       <!-- Post title --> 
         <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" itemprop="name"><?php the_title(); ?></a> 

       </div> <!-- .entry-meta --> 

      </h2> <!-- .header --> 

      <!-- Content --> 
      <div class="entry-content clearfix" itemprop="description"> 
       <?php the_date('','<p><strong>','</strong></p>',true); ?> 
       <?php the_content('Continue reading'); ?> 
       <div class="clearfix"></div> 
       <?php wp_link_pages(array('before' => '<div class="page-link"> <span> Pages: </span>', 'after' => '</div>')); ?> 
      </div> 

      <div class="entry-meta footerbox" > 
       <!-- Category --> 
       <span class="cat-links"> 
        <span>Posted in</span> 
        <?php echo get_the_category_list(', '); ?> 
       </span> 

       <!-- If single & have tag --> 
       <!-- Tag --> 
       <?php if (is_single()): if (has_tag()) : ?> 
       <span class="sep"> | </span> 
       <span class="tag-links"> 
        <span>Tagged</span> 
        <?php echo get_the_tag_list('',', ',''); ?> 
       </span> 
       <?php endif; ?> 
       <?php edit_post_link('Edit', '<span class="edit-link"><span class="sep"> | </span>', '</span>'); ?> 
       <div class="socialshareboxsingle clearfix"> 
        Share this post, let the world know <?php lugada_social_button();?> 
       </div> 
       <?php endif; ?> 
      </div> <!-- .footer --> 



     </div> <!-- article --> 

</div> 
<hr class="post-shadow"/> 

<!-- If its single, a user has filled out their description and this is a multi-author blog, show a bio on their entries --> 
<?php if (is_single()) : ?> 
<?php if (get_the_author_meta('description') && (! function_exists('is_multi_author') || is_multi_author())) : ?> 
<div class="content-box"> 
    <div id="author-info"> 

     <div id="author-avatar"> 
      <?php echo get_avatar(get_the_author_meta('user_email'), 80); ?> 
     </div> 

     <div id="author-description"> 
      <h2 >About <?php echo get_the_author(); ?></h2> 
      <?php the_author_meta('description'); ?> 
     </div> 

     <div id="author-link" class="clearfix"> 
      <?php if (get_the_author_meta('user_url')) : ?> 
      <span>Add my circles on Google+ : </span> 
      <span itemprop="author"><a href="<?php the_author_meta('user_url'); ?>?rel=author" rel="me"><?php echo get_the_author(); ?></a></span> 
      <br/> 
      <?php endif; ?> 
      <a href="<?php echo get_author_posts_url(get_the_author_meta('ID')); ?>"> 
      View all posts by <?php echo get_the_author(); ?><span class="meta-nav">&rarr;</span> 
      </a> 
     </div> 
    </div> 
</div> 
<hr class="post-shadow"/> 
<?php endif; endif; ?> 

回答

2

他们不是随机的帖子。阅读Codex

当有同日公布的下一个页面上的多个职位,the_date()只显示后的第一个日期(即the_date的第一个实例())。要重复在同一天发布的帖子的日期,您应该使用模板标签the_time()get_the_date()(自3.0)和date-specific format string

变化:

<?php the_date('','<p><strong>','</strong></p>',true); ?> 

要:

<p><strong><?php the_time('F j, Y'); ?></strong></p> 
相关问题