Wordpress在内容下发布

时间:2014-08-29 19:30:00

标签: php html wordpress

如何查看我的代码以显示主要主页的类别预览? 现在它是

<?php $posts = get_posts ("category=2&orderby=date&numberposts=3"); ?> 
 <?php if ($posts) : ?>
 <?php foreach ($posts as $post) : setup_postdata ($post); ?>
 <div>
 <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a> 
 </div>
 <?php endforeach; ?>
 <?php endif; ?>

以及

以下
<?php if(have_posts()): ?>
<?php while(have_posts()): the_post(); ?>
    <div class="pageContainer"><?php the_content(); ?></div>   
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else: ?><div>Sorry, posts are not found.</div>
<?php endif; ?>

这导致忽略第二部分......

抱歉我的英文。

1 个答案:

答案 0 :(得分:1)

 <?php 
       // Category posts
       $posts = get_posts("category=2&orderby=date&numberposts=3");
       if ($posts){
          foreach ($posts as $article){
             echo '<div><a href="'.get_permalink($article->ID) ?>" rel="bookmark">'.
                   $article->post_title.'</a></div>';
           }
       }

       // Current page content
       if ( have_posts() ) :
         while ( have_posts() ) : the_post(); ?>
           <div class="pageContainer">
               <?php the_content(); ?>
           </div>   
        <?php endwhile;
       else:
           echo '<div>Sorry, posts are not found.</div>';
       endif; 
       ?>