• I’m currently developing a video interview section of a website. The client has asked that I list related video post titles and thumbnails by category and date range. The date range is the tricky part.

    They way I have it currently setup is that underneath the video player, there is a list of 12 of the latest videos. The client specifically wants this to be changed — he wants them sorted by date. So for example, if a video was posted on February 20, 2009, he wants 12 previously posted videos before February 20 to display, instead of just the latest.

    Live Example:

    https://michaelfairmansoaps.com/2009/video-interviews/arianne-zuker-a-day-of-days/

    HTML/PHP code:

    <?php
    /*
    Single Post Template: Video Interview
    Description: Template for Video Interviews
    */
    get_header();
    ?>
    <div id="vid-interviews">
      <div id="content-wrap" class="clearfix">
        <div id="content">
          <h3 class="single-vid-interviews">Video Interviews</h3>
          <p class="all"><a href="/video-interviews/">&laquo; Back to all video interviews</a></p>
          <div id="masthead-videos">
            <div class="info">
              <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
              <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
                <div class="entry">
                  <h2>
                    <?php the_title(); ?>
                  </h2>
                  <?php the_content('<p class="serif">Read the rest of this entry &raquo;</p>'); ?>
                  <?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
                  <?php wp_related_posts(); ?>
                  <p><a href="<?php the_permalink() ?>#respond">
                    <?php comments_number('0','1','%'); ?>
                    comments</a> on this interview</p>
                  <p>
                    <?php if (function_exists('sharethis_button')) { sharethis_button(); } ?>
                  </p>
                </div>
              </div>
            </div>
          </div>
          <div id="wrap">
            <div class="more-vids">
              <h3>Latest Interviews</h3>
              <ul>
                <?php $recent = new WP_Query("cat=156&showposts=16"); while($recent->have_posts()) : $recent->the_post();?>
                <li><a href="<?php the_permalink() ?>" rel="bookmark" ><img src="<?php echo p75GetThumbnail($post->ID, 200, 133); ?>" alt="<?php the_title(); ?>" /><span>
                  <?php the_time('F j, Y') ?>
                  </span>
                  <?php the_title(); ?>
                  </a></li>
                <?php endwhile; ?>
              </ul>
              <p class="more"><a href="/video-interviews/">&laquo; Back to all video interviews</a></p>
            </div>
            <div class="center" style="width:580px;">
              <?php comments_template(); ?>
            </div>
          </div>
        </div>
        <?php endwhile; else: ?>
        <p>Sorry, no posts matched your criteria.</p>
        <?php endif; ?>
      </div>
    </div>
    <?php get_footer(); ?>

    I’ve looked around for a plugin but couldn’t find a suitable solution. I’m hoping someone can help me out with this.

Viewing 9 replies - 1 through 9 (of 9 total)
  • In your first loop (after <?php if (have_posts()) : while (have_posts()) : the_post(); ?>) store the post ID in a variable.

    Then in your 2nd query $recent = new WP_Query("cat=156&showposts=16"); use the post__not_in argument with the post ID variable.

    See query_posts Post & Page Parameters

    Also the query_posts article as a Time Parameter section with an example to filter posts by a date range but it doesn’t look like you really need that.

    Thread Starter steve35mm

    (@steve35mm)

    How would I go about storing the post ID in a variable? Would you mind giving me an example of this?

    Thanks for your quick response!

    Change this:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    to

    <?php
    $nodup = array();
    if (have_posts()) : while (have_posts()) : the_post();
    $nodup[]=$post->ID;
    ?>

    For your query, change:

    <?php $recent = new WP_Query("cat=156&showposts=16");

    to

    <?php
        $args=array(
          'post__not_in' => $nodup,
          'cat' => 156,
          'posts_per_page'=>16,
          'caller_get_posts'=>1
        );
    $recent = new WP_Query($args);

    Thread Starter steve35mm

    (@steve35mm)

    Michael, thank you for this code. After implementation, I noticed that your code successfully filters out the current post from the thumbnail listing of 16.

    What I’m trying to achieve is to list out the 16 posts previous to the current post. For example, if I’m showing post A, then posts B-P are displayed. And if I’m showing post E, then posts F-U are displayed.

    Is this doable?

    Thanks again for your help. I really appreciate it.

    Did you just go from talking about ‘dates’ to talking about posts in ‘alpha’ order?

    If so then you will want to use query_posts() to return an object of ALL posts in that category, in alpha (title) order, then cycle through the object to find the current post, then display the next 16 posts. Note you mentioned “16 posts previous to the current post” but not sure if that’s what you meant.

    Thread Starter steve35mm

    (@steve35mm)

    Yes, I am referring to the “16 posts previous to the current post”. I’m not sure how to cycle through the object to find the current post, but I’ll try to figure it out. Unless you have some quick code I could use ??

    Thanks again, Michael. Your help is a big part of why I love WordPress.

    This seems right along the same lines of my question, so figured I’d post it here. Tried searching the documentation and google to find something about pulling a specific date range and I’m getting nothing!

    I’ve commented exactly what I’m trying to accomplish. One of those old programmer things where you just try and write it out, then convert it over…but, this is my first wordpress site. I’m not too familiar with the syntax just yet. Thanks in advance!

    $weekly_article_args=array(
       'category__in' => $cat,
       'showposts' => 3,
       /* meta_key NOT 'pixel_video', meta_value NOT 'yes' */
       /* show posts from THIS week only */
       'caller_get_posts' => $do_not_show_stickies
       );  
    
    $archive_article_args=array(
       'category__in' => $cat,
       'showposts' => 3,
       /* meta_key NOT 'pixel_video', meta_value NOT 'yes' */
       /* show posts from the previous week of the article date */
       'caller_get_posts' => $do_not_show_stickies
    	);

    Hello just to add something,is there a way to filter this

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    from plugin,fox example,is post contain word girl,set background color red,and if not contain set background color blue,and this only in archive.php,I know to do this from code,to chagne archive.php,but I want to do this from plugin,can some one help please ?

    Hi steve35mm,

    I was wondering what plugin did you use to get thumbnails from the vimeo video. Did you generate them manually or it’s done dynamically from vimeo?

    thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Dynamic post titles & thumbnails by date range?’ is closed to new replies.