Skip to main content
Notice removed Canonical answer required by CommunityBot
Bounty Ended with no winning answer by CommunityBot
added 204 characters in body
Source Link
markratledge
  • 8.7k
  • 6
  • 40
  • 62
    global $wp_query;
    if ( have_posts() )
    {
        while( have_posts() )
        {
            the_post();
    
            // Add Class: "post-number-X"
            $current_post = "post-number-{$wp_query->current_post}";
    
            // Add Class: "home" (for index page) or "post-number-X-of-total";
            $current_in_total = 'home';
            if ( is_paged() )
            {
    
                $current_in_total  = "post-number-";
                $current_in_total .= get_query_var( 'paged' ) * get_query_var( 'posts_per_page' ) - $wp_query->current_post;
                $current_in_total .= "-of-total";
            }
    
            // Add Class: Even/Odd
            $even_odd = ( 0 === $GLOBALS['wp_query']->current_post % 2 ) ? ' even' : ' odd';
            // Avoid even/odd class for excerpts (everything after the 2nd post)
            2 > $wp_query->current_post AND $even_odd = '';
    
            // MarkUp: Uses `post_class()` to add classes
            ?>
     <article <?php post_class( "{$current_post}{$even_odd} {$current_in_total}" ); ?>>
                <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                <?php 
                // Home/Index/Front-Page/Archive first page
                if ( ! is_paged() )
                {
                    // Display the_content(); for the first 2 posts, then the_excerpt();
                    2<= $wp_query->current_post ? the_excerpt() : the_content();
                }
                // Paged archives (starts at second page)
                else
                {
                    the_excerpt();
                }
                ?>
            </article>
            <?php
        } 

// Add navigation ... twentyeleven_content_nav( 'nav-below' );

    
// Add navigation ...
    twentyeleven_content_nav( 'nav-below' );
    
    } // endif;
    unset( $current_post, $current_in_total, $even_odd );
global $wp_query;
if ( have_posts() )
{
    while( have_posts() )
    {
        the_post();

        // Add Class: "post-number-X"
        $current_post = "post-number-{$wp_query->current_post}";

        // Add Class: "home" (for index page) or "post-number-X-of-total";
        $current_in_total = 'home';
        if ( is_paged() )
        {

            $current_in_total  = "post-number-";
            $current_in_total .= get_query_var( 'paged' ) * get_query_var( 'posts_per_page' ) - $wp_query->current_post;
            $current_in_total .= "-of-total";
        }

        // Add Class: Even/Odd
        $even_odd = ( 0 === $GLOBALS['wp_query']->current_post % 2 ) ? ' even' : ' odd';
        // Avoid even/odd class for excerpts (everything after the 2nd post)
        2 > $wp_query->current_post AND $even_odd = '';

        // MarkUp: Uses `post_class()` to add classes
        ?>
 <article <?php post_class( "{$current_post}{$even_odd} {$current_in_total}" ); ?>>
            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
            <?php 
            // Home/Index/Front-Page/Archive first page
            if ( ! is_paged() )
            {
                // Display the_content(); for the first 2 posts, then the_excerpt();
                2<= $wp_query->current_post ? the_excerpt() : the_content();
            }
            // Paged archives (starts at second page)
            else
            {
                the_excerpt();
            }
            ?>
        </article>
        <?php
    } 

// Add navigation ... twentyeleven_content_nav( 'nav-below' );

} // endif;
unset( $current_post, $current_in_total, $even_odd );
    global $wp_query;
    if ( have_posts() )
    {
        while( have_posts() )
        {
            the_post();
    
            // Add Class: "post-number-X"
            $current_post = "post-number-{$wp_query->current_post}";
    
            // Add Class: "home" (for index page) or "post-number-X-of-total";
            $current_in_total = 'home';
            if ( is_paged() )
            {
    
                $current_in_total  = "post-number-";
                $current_in_total .= get_query_var( 'paged' ) * get_query_var( 'posts_per_page' ) - $wp_query->current_post;
                $current_in_total .= "-of-total";
            }
    
            // Add Class: Even/Odd
            $even_odd = ( 0 === $GLOBALS['wp_query']->current_post % 2 ) ? ' even' : ' odd';
            // Avoid even/odd class for excerpts (everything after the 2nd post)
            2 > $wp_query->current_post AND $even_odd = '';
    
            // MarkUp: Uses `post_class()` to add classes
            ?>
     <article <?php post_class( "{$current_post}{$even_odd} {$current_in_total}" ); ?>>
                <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                <?php 
                // Home/Index/Front-Page/Archive first page
                if ( ! is_paged() )
                {
                    // Display the_content(); for the first 2 posts, then the_excerpt();
                    2<= $wp_query->current_post ? the_excerpt() : the_content();
                }
                // Paged archives (starts at second page)
                else
                {
                    the_excerpt();
                }
                ?>
            </article>
            <?php
        } 
    
// Add navigation ...
    twentyeleven_content_nav( 'nav-below' );
    
    } // endif;
    unset( $current_post, $current_in_total, $even_odd );
added 80 characters in body
Source Link
markratledge
  • 8.7k
  • 6
  • 40
  • 62

Another updateYet Another Update 11/03/12:

Thanks to kaiser for this; but how do I add paging, i.ethis. One last bug: <?php twentyeleven_content_nav( 'nav-below' ); ?> the second page shows the 2 full posts and excerpts rather than all excerpts.

global $wp_query;
if ( have_posts() )
{
    while( have_posts() )
    {
        the_post();

        // Add Class: "post-number-X"
        $current_post = "post-number-{$wp_query->current_post}";

        // Add Class: "home" (for index page) or "post-number-X-of-total";
        $current_in_total = 'home';
        if ( is_paged() )
        {

            $current_in_total  = "post-number-";
            $current_in_total .= get_query_var( 'paged' ) * get_query_var( 'posts_per_page' ) - $wp_query->current_post;
            $current_in_total .= "-of-total";
        }

        // Add Class: Even/Odd
        $even_odd = ( 0 === $GLOBALS['wp_query']->current_post % 2 ) ? ' even' : ' odd';
        // Avoid even/odd class for excerpts (everything after the 2nd post)
        2 > $wp_query->current_post AND $even_odd = '';

        // MarkUp: Uses `post_class()` to add classes
        ?>
 <article <?php post_class( "{$current_post}{$even_odd} {$current_in_total}" ); ?>>
            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
            <?php 
            // Home/Index/Front-Page/Archive first page
            if ( ! is_paged() )
            {
                // Display the_content(); for the first 2 posts, then the_excerpt();
                2<= $wp_query->current_post ? the_excerpt() : the_content();
            }
            // Paged archives (starts at second page)
            else
            {
                the_excerpt();
            }
            ?>
        </article>
        <?php
    } 

 

// Add navigation ... twentyeleven_content_nav( 'nav-below' );

} // endif;
unset( $current_post, $current_in_total, $even_odd );

Another update 11/03/12:

Thanks to kaiser for this; but how do I add paging, i.e.: <?php twentyeleven_content_nav( 'nav-below' ); ?>.

global $wp_query;
if ( have_posts() )
{
    while( have_posts() )
    {
        the_post();

        // Add Class: "post-number-X"
        $current_post = "post-number-{$wp_query->current_post}";

        // Add Class: "home" (for index page) or "post-number-X-of-total";
        $current_in_total = 'home';
        if ( is_paged() )
        {

            $current_in_total  = "post-number-";
            $current_in_total .= get_query_var( 'paged' ) * get_query_var( 'posts_per_page' ) - $wp_query->current_post;
            $current_in_total .= "-of-total";
        }

        // Add Class: Even/Odd
        $even_odd = ( 0 === $GLOBALS['wp_query']->current_post % 2 ) ? ' even' : ' odd';
        // Avoid even/odd class for excerpts (everything after the 2nd post)
        2 > $wp_query->current_post AND $even_odd = '';

        // MarkUp: Uses `post_class()` to add classes
        ?>
 <article <?php post_class( "{$current_post}{$even_odd} {$current_in_total}" ); ?>>
            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
            <?php 
            // Home/Index/Front-Page/Archive first page
            if ( ! is_paged() )
            {
                // Display the_content(); for the first 2 posts, then the_excerpt();
                2<= $wp_query->current_post ? the_excerpt() : the_content();
            }
            // Paged archives (starts at second page)
            else
            {
                the_excerpt();
            }
            ?>
        </article>
        <?php
    } 

 
} // endif;
unset( $current_post, $current_in_total, $even_odd );

Yet Another Update 11/03/12:

Thanks to kaiser for this. One last bug: the second page shows the 2 full posts and excerpts rather than all excerpts.

global $wp_query;
if ( have_posts() )
{
    while( have_posts() )
    {
        the_post();

        // Add Class: "post-number-X"
        $current_post = "post-number-{$wp_query->current_post}";

        // Add Class: "home" (for index page) or "post-number-X-of-total";
        $current_in_total = 'home';
        if ( is_paged() )
        {

            $current_in_total  = "post-number-";
            $current_in_total .= get_query_var( 'paged' ) * get_query_var( 'posts_per_page' ) - $wp_query->current_post;
            $current_in_total .= "-of-total";
        }

        // Add Class: Even/Odd
        $even_odd = ( 0 === $GLOBALS['wp_query']->current_post % 2 ) ? ' even' : ' odd';
        // Avoid even/odd class for excerpts (everything after the 2nd post)
        2 > $wp_query->current_post AND $even_odd = '';

        // MarkUp: Uses `post_class()` to add classes
        ?>
 <article <?php post_class( "{$current_post}{$even_odd} {$current_in_total}" ); ?>>
            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
            <?php 
            // Home/Index/Front-Page/Archive first page
            if ( ! is_paged() )
            {
                // Display the_content(); for the first 2 posts, then the_excerpt();
                2<= $wp_query->current_post ? the_excerpt() : the_content();
            }
            // Paged archives (starts at second page)
            else
            {
                the_excerpt();
            }
            ?>
        </article>
        <?php
    } 

// Add navigation ... twentyeleven_content_nav( 'nav-below' );

} // endif;
unset( $current_post, $current_in_total, $even_odd );
added 75 characters in body
Source Link
markratledge
  • 8.7k
  • 6
  • 40
  • 62

11Another update 11/0203/12 Partway there:

Thanks to kaiser, for this; but this still adds the even/odd classes - with how do I add paging, i.e.: {$even_odd}<?php twentyeleven_content_nav( 'nav-below' ); ?>- to the content as well as the excerpts; they're only needed on the excerpts.

global $wp_query;
if ( have_posts() )
{
    while( have_posts() )
    {
        the_post();

        // Add Class: "post-number-X"
        $current_post = "post-number-{$wp_query->current_post}";

        // Add Class: "home" (for index page) or "post-number-X-of-total";
        $current_in_total = 'home';
        if ( is_paged() )
        {

            $current_in_total  = "post-number-";
            $current_in_total .= get_query_var( 'paged' ) * get_query_var( 'posts_per_page' ) - $wp_query->current_post;
            $current_in_total .= "-of-total";
        }

        // Add Class: Even/Odd
        $even_odd = ( 0 === $GLOBALS['wp_query']->current_post % 2 ) ? 'even'' even' : 'odd';' odd';
        // Avoid even/odd class for excerpts (everything after the 2nd post)
        2 > $wp_query->current_post AND $even_odd = '';

        // MarkUp: Uses `post_class()` to add classes
        ?>
        <article <?php post_class( "{$current_post} {$even_odd} {$current_in_total}" ); ?>>
            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
            <?php 
            // Home/Index/Front-Page/Archive first page
            if ( ! is_paged() )
            {
                // Display the_content(); for the first number of posts - in this case 2 -posts, then the_excerpt();
                2<= $wp_query->current_post ? the_excerpt() : the_content();
            }
            // Paged archives (starts at second page)
            else
            {
                the_excerpt();
            }
            ?>
        </article>
        <?php
    } 


} // endif;
unset( $current_post, $current_in_total, $even_odd );

11/02/12 Partway there:

Thanks to kaiser, but this still adds the even/odd classes - with {$even_odd}- to the content as well as the excerpts; they're only needed on the excerpts.

global $wp_query;
if ( have_posts() )
{
    while( have_posts() )
    {
        the_post();

        // Add Class: "post-number-X"
        $current_post = "post-number-{$wp_query->current_post}";

        // Add Class: "home" (for index page) or "post-number-X-of-total";
        $current_in_total = 'home';
        if ( is_paged() )
        {

            $current_in_total  = "post-number-";
            $current_in_total .= get_query_var( 'paged' ) * get_query_var( 'posts_per_page' ) - $wp_query->current_post;
            $current_in_total .= "-of-total";
        }

        // Add Class: Even/Odd
        $even_odd = ( 0 === $GLOBALS['wp_query']->current_post % 2 ) ? 'even' : 'odd';

        // MarkUp: Uses `post_class()` to add classes
        ?>
        <article <?php post_class( "{$current_post} {$even_odd} {$current_in_total}" ); ?>>
            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
            <?php 
            // Home/Index/Front-Page/Archive first page
            if ( ! is_paged() )
            {
                // Display the_content(); for the first number of posts - in this case 2 - then the_excerpt();
                2<= $wp_query->current_post ? the_excerpt() : the_content();
            }
            // Paged archives (starts at second page)
            else
            {
                the_excerpt();
            }
            ?>
        </article>
        <?php
    }
} // endif;
unset( $current_post, $current_in_total, $even_odd );

Another update 11/03/12:

Thanks to kaiser for this; but how do I add paging, i.e.: <?php twentyeleven_content_nav( 'nav-below' ); ?>.

global $wp_query;
if ( have_posts() )
{
    while( have_posts() )
    {
        the_post();

        // Add Class: "post-number-X"
        $current_post = "post-number-{$wp_query->current_post}";

        // Add Class: "home" (for index page) or "post-number-X-of-total";
        $current_in_total = 'home';
        if ( is_paged() )
        {

            $current_in_total  = "post-number-";
            $current_in_total .= get_query_var( 'paged' ) * get_query_var( 'posts_per_page' ) - $wp_query->current_post;
            $current_in_total .= "-of-total";
        }

        // Add Class: Even/Odd
        $even_odd = ( 0 === $GLOBALS['wp_query']->current_post % 2 ) ? ' even' : ' odd';
        // Avoid even/odd class for excerpts (everything after the 2nd post)
        2 > $wp_query->current_post AND $even_odd = '';

        // MarkUp: Uses `post_class()` to add classes
        ?>
 <article <?php post_class( "{$current_post}{$even_odd} {$current_in_total}" ); ?>>
            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
            <?php 
            // Home/Index/Front-Page/Archive first page
            if ( ! is_paged() )
            {
                // Display the_content(); for the first 2 posts, then the_excerpt();
                2<= $wp_query->current_post ? the_excerpt() : the_content();
            }
            // Paged archives (starts at second page)
            else
            {
                the_excerpt();
            }
            ?>
        </article>
        <?php
    } 


} // endif;
unset( $current_post, $current_in_total, $even_odd );
added 709 characters in body
Source Link
markratledge
  • 8.7k
  • 6
  • 40
  • 62
Loading
added details and image
Source Link
markratledge
  • 8.7k
  • 6
  • 40
  • 62
Loading
Notice added Canonical answer required by markratledge
Bounty Started worth 50 reputation by markratledge
deleted 83 characters in body; edited title
Source Link
markratledge
  • 8.7k
  • 6
  • 40
  • 62
Loading
details
Source Link
markratledge
  • 8.7k
  • 6
  • 40
  • 62
Loading
Tweeted twitter.com/#!/StackWordPress/status/262842941507244032
Source Link
markratledge
  • 8.7k
  • 6
  • 40
  • 62
Loading