Test X posts

<?php
/*
Template Name: List-all-chronological
*/

function trimStringIfTooLong($s) {
    $maxLength = 60;
    
    if (strlen($s) > $maxLength) {
        echo substr($s, 0, $maxLength - 5) . ' ...';
    } else {
        echo $s;
    }
}

?>

<ul>
<?php
$query = array( 'posts_per_page' => -1, 'order' => 'ASC' );
$wp_query = new WP_Query($query);

if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li>
    <a href="<?php the_permalink() ?>" title="Link to <?php the_title_attribute() ?>">
        <?php the_time( 'Y-m-d' ) ?> 
        <?php trimStringIfTooLong(get_the_title()); ?>
    </a>
</li>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts published so far.'); ?></p>
<?php endif; ?>
</ul>
$maxLength) { echo substr($s, 0, $maxLength – 5) . ‘ …’; } else { echo $s; } } ?>
    -1, ‘order’ => ‘ASC’ ); $wp_query = new WP_Query($query); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
PHP Code Snippets Powered By : XYZScripts.com