Support » Fixing WordPress » How to alternate post styles in twentyeleven

  • Resolved billionstrang

    (@billionstrang)


    All I want to do is alternate the posts in a twentyeleven child theme, so I can have one float left, and the next one float right, etc. There are some fairly simple and some more complicated ways to do this on the www, but none of them seem to work for twentyeleven.

    Has anyone ever pulled this off (in Twentyeleven) and if so, could you share how you did it?

    I’ve spent about a week trying to figure this one out.

    Yes, Esmi, I’m using a child theme, thanks.

Viewing 2 replies - 16 through 17 (of 17 total)
  • OK, So this is what I did to alternate the thumbnails left and right in Standard format only:
    In the index.php,

    <?php while ( have_posts() ) : the_post(); ?>
    <?php $format = get_post_format();
    if ( false === $format )
    $format = 'standard'; ?>
    <?php get_template_part( 'content', $format ); ?>

    Then create content-standard.php, and at the top, you put:


    <?php global $oddeven; $oddeven = ( $oddeven == 'odd' ) ? 'even' : 'odd'; ?>
    <article id="post-<?php the_ID(); ?>" <?php post_class($oddeven); ?>>

    I left content.php in its original state, and adjusted “standard” post display in the content.standard.php.

    It appears that this is working perfectly, though I don’t understand why “global” makes the difference. Any chance of an explanation?

    Thanks everyone who helped.

    though I don’t understand why “global” makes the difference. Any chance of an explanation?

    not really in this case – my first idea was to use ‘static’ which did not work;
    i suppose ‘global’ helps the system to ‘remember’ the value while switching between the template parts (?)

Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘How to alternate post styles in twentyeleven’ is closed to new replies.