• Hi
    I am writing a theme in which I hope to seperate 1 category (my photos) and the rest of my posts, and for each season display each under the heading of the season in which they were written.
    So far my loop goes.
    while have posts..
    if cat 32
    Show thumbnails of all photos.
    else
    Display all the other posts.

    and the result is:
    all photos
    all posts

    I have been trying to wrap that in some code which will sort it into seasons, so the output would look:
    Winter 09:
    Photos
    rest of posts
    Autumn/Fall 08:
    Photos
    Rest of Posts

    I have posted this here, becauase it might be useful for others if achieved, So if you have any ideas, please do your best in sharing them.
    Andrew
    P.S. – I would like to assume the beginning of each season occurd on the 21st of Dec, March, Jun, Sept (I’m in the north, so that would be winter, spring, summer autumn here.)
    To view see https://acb.lin48.com/st

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter Andrewcb

    (@andrewcb)

    Anyone help with the code to do this in the index.php,

    $date = current_date
    &year = current_year

    While (have poast) <– notmal loop begining <
    if $date < 21/03/$year < $post_date
    { <p Spring .$year p>}
    if $date < 21/06/$year < $post_date
    { <p summer .$year p>}
    if $date < 21/09/$year < $post_date
    { <p Spring .$year p>}
    if $date < 21/12/$year < $post_date
    { <p Spring .$year p>}

    Do the normal thing i.e. post posts!
    // change the check condition to the last post.
    $data = post_date
    $year = post_year

    end while

    So this is what I have in mind so far. Any better methods or help with coding the conditional aspects of that, much appreciated. I don’t even know how to get the current data, year, post date or post year. I guess I will have to format the meta. then I need to compare the dates, to decide whether or not they come either side of the boundary, and therefore require a new title. e.g. Spring $year.

    Would be great to hear the views of an experianced coder at this point – just to know i’m not off my rocker.
    Thanks
    A

    I don’t have much time right now but look at PHP’s date functions and see if it makes sense. There are a number of ways to deal with time but to get you started maybe the easiest for you in this case is the use something like date('Y-m-d',time()); to get the current date. I changed the order of the year, month, and day because this is how the date will come out of the DB.

    Thread Starter Andrewcb

    (@andrewcb)

    Ihave this so far:

    <div id="MajorContent">
    <h2> Photography! </h2>
    
    <?php
    
    $year = date('y');
    $month = date('m');
    $day = date('d');
    
     if (have_posts()) :
    
    if (($month == 12 && $day >=21) || ($month < 03) || ($month == 3 && $day < 21 )){
    echo '<div id="post"><h2>Winter'; echo " $PostYear"; echo "</h2></div>";
    $Season = 1;}
    if (($month == 3 && $day >=21) || ($month == 04) || ($month == 05) || ($month == 6 && $day < 21 )){
    echo '<div id="post"><h2>Spring'; echo " $PostYear"; echo "</h2></div>";
    $Season = 2;}
    if (($month == 6 && $day >=21) || ($month == 07) || ($month == 08) || ($month == 9 && $day < 21 )){
    echo '<div id="post"><h2>Summer'; echo " $PostYear"; echo "</h2></div>";
    $Season = 3;}
    if (($month == 9 && $day >=21) || ($month == 10) || ($month == 11) || ($month == 12 && $day < 21 )){
    echo '<div id="post"><h2>Autumn'; echo " $PostYear"; echo "</h2></div>";
    $Season = 4;}
    //echo "$Season";
    
    		 while (have_posts()) : the_post();
    
    			 if (in_category('32')) {
    		$PostYear = get_the_time('y');
    		$PostMonth = get_the_time('m');
    		$PostDay = get_the_time('d');
    
    		if (($PostMonth == 12 && $PostDay >=21) || ($PostMonth < 03) || ($PostMonth == 3 && $PostDay < 21 )){
    			$PostSeason = 1;} //Winter
    		if (($PostMonth == 3 && $PostDay >=21) || ($PostMonth == 04) || ($PostMonth == 05) || ($PostMonth == 6 && $PostDay < 21 )){
    			$PostSeason = 2;} //Spring
    		if (($PostMonth == 6 && $PostDay >=21) || ($PostMonth == 07) || ($PostMonth == 08) || ($PostMonth == 9 && $PostDay < 21 )){
    			$PostSeason = 3;}  //Summer
    		if (($PostMonth == 9 && $PostDay >=21) || ($PostMonth == 10) || ($PostMonth == 11) || ($PostMonth == 12 && $PostDay < 21 )){
    			$PostSeason = 4;}  //Autumn
    //echo "Before the If loop Season is $Season and PostSeason is $PostSeason </br>";
    if ($Season == $PostSeason) {
    ;}
    	elseif ($PostSeason == 1){
    echo '<div id="postTitle"><h2>Winter'; echo " $PostYear"; echo "</h2></div>";
    	$Season = 1;}
    	elseif ($PostSeason == 2){
    echo '<div id="postTitle"><h2>Spring'; echo " $PostYear"; echo "</h2></div>";
    	$Season = 2; }
    	elseif ($PostSeason == 3){
    echo '<div id="postTitle"><h2>Summer'; echo " $PostYear"; echo "</h2></div>";
    	$Season = 3; }
    	elseif ($PostSeason == 4){
    echo '<div id="postTitle"><h2>Autumn'; echo " $PostYear"; echo "</h2></div>";
    	$Season = 4; }
    	else {
    	//echo '<h1>Probably Winter, Maybe Summer</>';
    	$Season = 4; }
    //echo "After the If loop Season is $Season and PostSeason is $PostSeason </br></br>";
    
    ?>
    
    				<div class="postThumb" id="post-<?php the_ID(); ?>">
    						<?php the_excerpt() ?>
    				</div>
    		<?php };
    		endwhile; ?>
    <div id="post">
    <h2> Ideas! </h2>
    </div>
    		  <?php rewind_posts(); ?>  // Rewinds to beginning of query.
    
      	<?php while (have_posts()) : the_post(); ?>
    	   <?php if ( ! in_category('32')) { ?>
    				<div class="post" id="post-<?php the_ID(); ?>">
    						<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <br />
    						<?php the_content() ?> <br /><br />
    				</div>
    		<?php };
      		endwhile ;
    
    endif ; ?>
    
    </div>

    I know there must be better methods.
    but if anyone knows how i can get the photos and the text ideas to work such that they show alternatly as the above post suggests, within each season, let me know.

    Think about this for your seasons switch:

    /// set your season markers
    $year = date('Y'); /// this year
    $springstart = strtotime($year.'-03-21');
    $summerstart = strtotime($year.'-06-21'); // make one for each season
    /// switch according to season
    $thisdate = strtotime(substr($post->post_date,0,10)); // the post date stripped of time elements
    if (($thisdate >= $springstart) && ($thisdate < $summerstart)) echo '<div id="post"><h2>Spring ',date('Y',$thisdate),'</h2></div>';
    // elseif (-- same kind of switch as above --) echo 'the season';

    Assuming I did nothing stupid– big assumption–, that should give you a pretty good date comparison with much less effort.

    Thread Starter Andrewcb

    (@andrewcb)

    I have a bigger problem than that, I now have to try and re-code that so it gives:
    Season Title,
    Photos
    Posts
    Season Title
    Photos Posts

    Rather than
    Season title
    photos
    Season Title Photos

    Then all the posts at the end.

    I have just made some progess thinking that out, and I think I will be able to code it tonight! ??

    Well, that doesn’t look like too much of a change. If you have more questions…

    Thread Starter Andrewcb

    (@andrewcb)

    Hello,

    So in my while loop, there are some cat=32 posts, and other.

    I want my code to go through and post:
    Winter 09
    Photos in Winter 09
    Text Posts in Winter 09
    Autumn 08
    Photos in Autumn 08
    Text Posts in Autumn 08

    But in order to collect and post all the photos, the loop has already gone past some text posts, and I don’t know how to get it to go back and look again.
    I thought Current_Post could do it, but when I print it, it appears to have no value.

    So i guess the questoin is, how do I get the loop to output the above sequence, assuming the photo posts are category 32, and any other category post can go in the text posts?
    Thanks for you help

    rewind_posts() will reset the loop.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Display Posts under Seasons titles, (eg Winter 09:)’ is closed to new replies.