简体   繁体   中英

Wordpress posts under content

How should look my code in order to display a preview of a categories with main main page? Now its is

<?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; ?>

and below this

<?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; ?>

This leads to ignore second part...

Sorry for my english.

 <?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; 
       ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM