Support » Themes and Templates » the_date math calculation

  • psuhiker

    (@psuhiker)


    In a list of recent posts, I am looking to preface each post title with the day of the year (<?php the_time(‘z’) ?>), but from a specific point, i.e. the 71st day of the year. So if the day of the year is 81, it actually displays as Day 10.

    I’m having trouble more in the loop, where I can do the math function correctly, but when put into a list with other post entries, the day ends up being the same for all posts, and I think, is taking the day of the year from the current post only, instead of each post individually.

    This was the function I was using:

    <?php $date = “<?php the_date(z);?>”; ?><?php $start = 71; ?><?php $day = ($date – $start); ?><?php echo $day ?>

Viewing 1 replies (of 1 total)
  • MichaelH

    (@michaelh)

    This works for me:

    <?php
    $args=array(
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Posts';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><?php the_time('m.d.y') ?> day of year is <?php the_time('z') ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

Viewing 1 replies (of 1 total)
  • The topic ‘the_date math calculation’ is closed to new replies.