Title: Code help
Last modified: August 30, 2016

---

# Code help

 *  Resolved [Mike](https://wordpress.org/support/users/mgmcguire1/)
 * (@mgmcguire1)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/code-help-9/)
 * I’ve had to use a plugin [PHP Code for Posts and Pages] to get all my posts displayed
   in chronological order. It works like a charm when I use this code:
 *     ```
       <?php
       $args=array(
         'post_type' => 'post',
         'post_status' => 'publish',
         'posts_per_page' => -1,
         'caller_get_posts'=> 1,
         'order'=> 'ASC',
       );
       $my_query = null;
       $my_query = new WP_Query($args);
       if( $my_query->have_posts() ) {
         while ($my_query->have_posts()) : $my_query->the_post(); ?>
           <p><h3><strong><a href="<?php the_permalink() ?>" target="blank" rel="bookmark" title="Link to <?php the_title_attribute(); ?> [Opens in new window]"><?php the_title(); ?></a></strong></h3> <?php the_time( 'F jS, Y' ) ?><br><?php comments_popup_link( 'No Comments »', '1 Comment »', '% Comments »' ); ?></p>
         <?php
       if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
         the_post_thumbnail('thumbnail', array('class' => 'alignleft'));
       } 
   
         the_excerpt();
         endwhile;
   
       }
       wp_reset_query();  // Restore global post data stomped by the_post().
       ?>
       ```
   
 * The problem I’m having is that it all jumbles together and the posts aren’t separated.
 * What can I do to accomplish the following goals?
 * 1. Put a separator line between each post.
    2. Truncate each post to a certain
   number of characters, say 400, with a “Read more…” link. 3. Align the thumbnail
   to the left with the truncated excerpt to the right of each thumbnail.
 * Here’s a link to the page I’m working on: [http://siochana.us/from-the-beginning/](http://siochana.us/from-the-beginning/)
 * Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [zota marius](https://wordpress.org/support/users/zota-marius/)
 * (@zota-marius)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/code-help-9/#post-6625853)
 * 1. after every loop you must use clear property, is used to prevent elements 
   from wrapping around.
    2. i use php function substr() to limit the post excrept
   to 400
 * you can try next code :
 *     ```
       <?php
       $args=array(
         'post_type' => 'post',
         'post_status' => 'publish',
         'posts_per_page' => -1,
         'caller_get_posts'=> 1,
         'order'=> 'ASC',
       );
       $my_query = null;
       $my_query = new WP_Query($args);
       if( $my_query->have_posts() ) {
         while ($my_query->have_posts()) : $my_query->the_post(); ?>
           <p><h3><strong><a href="<?php the_permalink() ?>" target="blank" rel="bookmark" title="Link to <?php the_title_attribute(); ?> [Opens in new window]"><?php the_title(); ?></a></strong></h3> <?php the_time( 'F jS, Y' ) ?><br><?php comments_popup_link( 'No Comments »', '1 Comment »', '% Comments »' ); ?></p>
         <?php
       if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
         the_post_thumbnail('thumbnail', array('class' => 'alignleft'));
       }
       $truncate=the_excerpt();
       echo substr($truncate, 0,400); // 400 characters
       ?>
        <a href="<?php the_permalink() ?>" target="blank" >Read More ... </a>
        <div style="clear:both;"></div>
       <?php
         endwhile;
   
       }
       wp_reset_query();  // Restore global post data stomped by the_post().
       ?>
       ```
   
 *  Thread Starter [Mike](https://wordpress.org/support/users/mgmcguire1/)
 * (@mgmcguire1)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/code-help-9/#post-6625894)
 * PERFECT! [@zota](https://wordpress.org/support/users/zota/) marius, that worked
   exactly as I intended. The help is much appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Code help’ is closed to new replies.

## Tags

 * [php code](https://wordpress.org/support/topic-tag/php-code/)
 * [separator](https://wordpress.org/support/topic-tag/separator/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [Mike](https://wordpress.org/support/users/mgmcguire1/)
 * Last activity: [10 years, 8 months ago](https://wordpress.org/support/topic/code-help-9/#post-6625894)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
