• Resolved Mike

    (@mgmcguire1)


    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/

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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

    (@mgmcguire1)

    PERFECT! @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.