没有在帖子中获取内容部分只显示缩略图和标题

时间:2014-02-21 05:18:58

标签: wordpress twitter-bootstrap

<div class="row" id="content">
  <?php
   $args = array( 'posts_per_page' =>3, 'category' =>3 );
   $rand_posts = get_posts( $args );
   foreach( $rand_posts as $post ) : 
  ?>
      <div class="col-md-8">
         <h2 style="text-transform:uppercase;font-size: 19px;font-weight:bold;"><?php the_title();?></h2>
         <div class="col-md-6">
            <div class="thumbnails">
                <a href="<?php the_permalink();?>"> <?php the_post_thumbnail('full');?></a>
            </div>
         </div>
         <div class="col-md-6">
             <?php echo the_content(); ?>
             <?php echo the_excerpt(); ?>
         </div>
         <div class="bar3"></div>
     </div>

   <?php endforeach; ?>
      <div class="col-md-4">    
            <?php get_sidebar(); ?>     
      </div>
</div> 

这是我的代码。我没有从缩略图和标题显示的帖子中获取内容..请任何人帮我解决问题。我的英语很差。

3 个答案:

答案 0 :(得分:0)

用这个代替你的代码......

<div class="row" id="content">
    <?php
    $args = array( 'posts_per_page' =>3, 'category' =>3 );
    $rand_posts = new WP_Query( $args );
    if ( $rand_posts->have_posts() ) :
        while ( $rand_posts->have_posts() ) : $rand_posts->the_post();
    ?>
      <div class="col-md-8">
         <h2 style="text-transform:uppercase;font-size: 19px;font-weight:bold;"><?php the_title();?></h2>
         <div class="col-md-6">
            <div class="thumbnails">
                <a href="<?php the_permalink();?>"> <?php the_post_thumbnail('full');?></a>
            </div>
         </div>
         <div class="col-md-6">
             <?php the_content(); ?>
             <?php the_excerpt(); ?>
         </div>
         <div class="bar3"></div>
     </div>
    <?php 
       endwhile;
    endif;
    wp_reset_query();
    ?>
      <div class="col-md-4">    
            <?php get_sidebar(); ?>     
      </div>
</div> 

我希望它能奏效......

答案 1 :(得分:0)

试试这个:

    <div class="row" id="content">
        <?php
       $args = array( 'posts_per_page' =>3, 'category' =>3 );
       $rand_posts = get_posts( $args );
       foreach( $rand_posts as $post ) :  setup_postdata($post);
      ?>
          <div class="col-md-8">
             <h2 style="text-transform:uppercase;font-size: 19px;font-weight:bold;"><?php the_title();?></h2>
             <div class="col-md-6">
                <div class="thumbnails">
                    <a href="<?php the_permalink();?>"> <?php the_post_thumbnail('full');?></a>
                </div>
             </div>
             <div class="col-md-6">
                 <?php  the_content(); ?>
                 <?php  the_excerpt(); ?>
             </div>
             <div class="bar3"></div>
         </div>

       <?php endforeach; ?>
   <?php wp_reset_postdata(); ?>
          <div class="col-md-4">    
                <?php get_sidebar(); ?>     
          </div>
    </div> 

答案 2 :(得分:0)

您缺少setup_postdata($ post);

当你使用the_content();你不需要添加“echo”,与其他查询一样,以“_ _”

开头

请在此处查看get_posts查询:http://codex.wordpress.org/Template_Tags/get_posts

干杯!