ThemeShaper Forums » Thematic

[closed]

I need a date -- setup_postdata

(11 posts)
  • Started 2 years ago by fwunder
  • Latest reply from fwunder
  • This topic is resolved
  1. fwunder
    Member

    I'm stumped. No big surprise.

    Creating a page with posts identified by category and scattered about a page - two across and two down. Everything works great, except for the_date(), The date only displays on the first post block. Everything else displays fine. Here is a bit of the code. I've left out the styling stuff:

    function my_stuff_below_content() {
         global $post;
         $postslistRT = get_posts( "category_name=right-top-column&numberposts=1" );
         $postslistLT = get_posts( "category_name=left-top-column&numberposts=1" );
         $postslistLB = get_posts( "category_name=left-bottom-column&numberposts=1" );
         $postslistRB = get_posts( "category_name=right-bottom-column&numberposts=1" );
    
    if (is_home() || is_front_page()) {
    	foreach ($postslistRT as $post) :  setup_postdata($post); ?>
    	     <div class="post-block">
    		    <div class="post-meta-title">
    		       <?php the_title(); ?>
    		    </div>
    	        <div class="post-meta-date">
    		        <?php the_date(); ?>
    		    </div>
    		    <div class="post-meta-excerpt">
    		        <?php the_excerpt(); endforeach; } ?>
    	        </div>
            </div>
    
    if (is_home() || is_front_page()) {
    	foreach ($postslistLT as $post) :  setup_postdata($post); ?>
    	     <div class="post-block">
    		    <div class="post-meta-title">
    		       <?php the_title(); ?>
    		    </div>
    	        <div class="post-meta-date">
    		        <?php the_date(); ?>
    		    </div>
    		    <div class="post-meta-excerpt">
    		        <?php the_excerpt(); endforeach; } ?>
    	        </div>
            </div>

    [......two more blocks like above......]

    Posted 2 years ago #
  2. try: <?php the_time('F j, Y'); ?> instead

    I think the_date() will only work for the first post in a loop of posts that are all published on the same day

    Posted 2 years ago #
  3. fwunder
    Member

    Brilliant! Thank you!

    Posted 2 years ago #
  4. is there a reason you have categories for the position of the post? can you not cycle though them all and insert the column markup where needed?

    a bit outdated b/c you no longer need to remove then add the loop back (you can use an override) but this is a great tutorial
    http://hardiannazief.com/12/create-custom-posts-layout-in-home-page-thematic-child-theme/

    Posted 2 years ago #
  5. fwunder
    Member

    Good morning! Thanks for the link and more code snipplets @helgatheviking. I'm a code snippet hoarder - just got to get organized!

    OK, lemme splain what I'm going for and see if this makes sense. I'll use my favorite book as an example. It's a recipe book.

    The book has four chapters: Beef, Pork, Chicken, Fish. Hundreds of recipes for each. I'm thinking that every few days I might want to feature a recipe from each chapter on the home page in a 4x4 grid. The graphic designer created a look that demands the featured recipe excerpt be [category] positioned on the home page. I'm thinking I might even hire a php timer and randomizer to automagically pick a new recipe from each category and display them in their appropriate position on the home page. Soooo, in the code above I should have written:

    $postslistRT = get_posts( "category_name=beef-column&numberposts=1" );
    $postslistLT = get_posts( "category_name=pork-column&numberposts=1" );
    $postslistLB = get_posts( "category_name=chicken-column&numberposts=1" );
    $postslistRB = get_posts( "category_name=fish-column&numberposts=1" );

    Now that the recipe feature (home) page is working so well, I'm thinking it might be cool if a "chapter" (category) page might be in order where the page displays excerpts from a bunch of [say] Beef recipes with beefy little thumbnails which link to the full recipe or uses query tabs to...

    Anyway, does that make any sense?

    P.S. The recipe book is purely for illustration purposes. I really have nothing against vegetables.

    `

    Posted 2 years ago #
  6. i was going to ask for a link until i realized that you don't really have a recipe site... it was just an example. bummer... i love recipes. anyway i follow you. it is just a lot of queries though to have 4 on top of the default query. i'd suggest storing the results with the transient api and restoring the transient on the save_post action.

    http://codex.wordpress.org/Transients_API

    Posted 2 years ago #
  7. fwunder
    Member

    Thanks for the, erhh, light reading. I was curious about WP Super Cache playing nice with that and found:

    http://www.re-cycledair.com/caching-wordpress-data-with-the-transients-api

    Looks very cool. Thanks! Gives me motivation to work on a high concurrency (sic) site.

    Posted 2 years ago #
  8. lol.... no idea how to implement the chron thing. but in general, the basic transient is very easy to implement. just a matter of knowing it is there and that you should use it.

    the complete example at the codex is pretty perfect for adapting:

    // Get any existing copy of our transient data
    if ( false === ( $postslistRT = get_transient( 'postslistRT' ) ) ) {
        // It wasn't there, so regenerate the data and save the transient
         $postslistRT = get_posts( "category_name=beef-column&numberposts=1" );
         set_transient( 'postslistRT', $postslistRT );
    }
    
    // Use the data like you would have normally...

    you'll need 4 of those, but then refresh them all on save

    // Create a simple function to delete our transient
    function postslistRT_delete_transient() {
         delete_transient( 'postslistRT' );
         //add other delete_transient()
    }
    add_action( 'save_post', 'postslistRT_delete_transient' );
    Posted 2 years ago #
  9. fwunder
    Member

    Hey! Back to what started this whole conversation..the date thing.

    I should have known it would be as simple as a Thematic function, I little digging and I found thematic_postheader() which includes the title, the author *and* the published date. So, in the code at the top:

    <div class="post-meta-title">
    	 <?php the_title(); ?>
     </div>
    	  <div class="post-meta-date">
    		<?php the_date(); ?>
              </div>

    replaces with

    <?php thematic_postheader(); ?>

    I bet if I keep digging I can find something equally as clever for the the_excerpt()

    Oh, and @KIA, I'm gonna use that!

    P.S. Edited for correction

    Posted 2 years ago #
  10. fwunder
    Member

    Chickens almost cooked, but I thought I'd take a sec a look at this:

    function my_stuff_below_content() {
         global $post;
         $postslistRT = get_posts( "category_name=right-top-column&numberposts=1" );
    
          if (is_home() || is_front_page()) {
    	        foreach ($postslistRT as $post) :  setup_postdata($post); ?>
    	            <div class="post-block">
    			<?php thematic_postheader(); ?>
                        <?php if ( has_post_thumbnail() ) { ?>
                           <a href=" <?php the_permalink() ?> "> <?php the_post_thumbnail( 'thumbnail', array('class' => 'alignleft') ); ?></a>
                        <?php  } ?>
    		            <?php the_excerpt(); endforeach; } ?>
                    </div>

    This works perfectly, but I'm thinking the thumbnail link to post could be done more elegantly. I was hoping to fine something like thematic_excerpt() which would include the thumbnail, excerpt and link to post. Maybe I'm just hungry/ Does that make any sense?

    Thanks.

    Posted 2 years ago #
  11. fwunder
    Member

    Just wanted to followup and say Thanks! for the help and suggestions. Although this was really just a proof-of-concept exercise for me, it works great thanks to you folks and Thematic. Please ignore the styling...still got lot's more work to do on that.

    http://grafiks101.com/dev/?theme=Four-by-Four

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.