Forums

How to style 4th, 8th, 12th posts differently? (2 posts)

  1. greg9885
    Member
    Posted 2 years ago #

    How do I go about styling the 4th, 8th, 12th posts differently? Not just the css, but I was to add different xhtml markup as well.

    I know it has something to do with the counter in the loop somewhere, but I'm not sure where or how to do this??

    I'm going crazy over this, any help would be greatly appreciated.

  2. vtxyzzy
    Member
    Posted 2 years ago #

    Below is an adaptation of the code I pointed to in your other post. Use the Admin->Settings->Reading->'Blog pages show at most' for all pages other than the first.

    To show the 'featured' post, use a separate loop ahead of this code.

    <?php $max_first_page = 8;  // Show this many posts on front page
          $args = $wp_query->query;
          $args['caller_get_posts'] = 1; // Using stickies messes up the count
          $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
          $posts_per_page = get_query_var('posts_per_page');
          $posts_to_skip = $posts_per_page - $max_first_page;
          if ($page == 1) {
             $max_posts = $max_first_page;
          } else {
             $max_posts = $posts_per_page;
             $args['offset'] = (($page - 1) * $max_posts)- $posts_to_skip;
          }
          query_posts($args);
          if ($wp_query->max_num_pages < ceil(($wp_query->found_posts + $posts_to_skip)/$posts_per_page))
            ++$wp_query->max_num_pages;
          $counter = 0;
          ?>
       <?php if (have_posts()) :
          $count4 = 0;
          while (have_posts()) : the_post();
             if (++$counter > $max_posts) continue;
             if (!(++$count4 % 4)) {
                 // Do the special code for every 4th post
             } else {
                 // Do the code for other posts
             }
          endwhile;
       else:
          // Do the code for no posts found
       endif; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.