ThemeShaper Forums » Thematic

[closed]

Trying to add class to every other post, starting over each new year

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

    I'm blown away by Themeatic and have managed to overcome many challenges as a cutter-paster but have hit a wall trying to add a class name to posts similar to "alt" but that starts over for each new year. In other words I need to add a class to the 2nd, 4th, etc. post of each year, rather than for all posts in a page.

    I've been trying to modify thematic_post_class, specifically this part:

    // If it's the other to the every, then add 'alt' class
    if ( ++$thematic_post_alt % 2 )
    $c[] = 'alt';

    Within a childtheme_override_post_class() function in my child functions.php, I have the following conditional:

    if (is_category('7')){

    $currentyr = mysql2date('y', $post->post_date, false);

    if ($currentyr != $previousyr) {

    if ( $thematic_post_alt % 2 ){

    $c[] = 'alt';
    }

    $previousyr = $currentyr;

    }

    ++$thematic_post_alt;

    } else {

    // If it's the other to the every, then add 'alt' class
    if ( ++$thematic_post_alt % 2 )
    $c[] = 'alt';

    }

    I used the above "if ($currentyr != $previousyr) {" conditional in my child category loop successfully to echo line breaks for new years, but can't seem to resolve it in the thematic_post_class function.

    I've tried re-declaring $thematic_post_alt = 1; every time there's a new year, but that just gives me a post ID of 1 across the board…any assistance is greatly appreciated!

    Posted 8 years ago #
  2. avalon54
    Member

    Good grief this has been humbling.

    The solution I came up with was to add $thematic_post_alt = 1; to the category loop where it executes when there is a post with a new year displayed.

    I have the this in my child category loop just after the_post();

    if (is_category('7')) {

    global $post, $thematic_post_alt;//grab the global var

    $currentyr = mysql2date('Y', $post->post_date, false);//get the post year

    if ($currentyr != $previousyr) {//if they differ there's a post with a new year

    echo '<div class="year-break">YEAR ';
    echo $currentyr;
    echo '</div>';

    $previousyr = $currentyr;//set previousyr to currentyr

    $thematic_post_alt = 1;//reset this var to 1, which is its original value

    }
    }

    Posted 8 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.