• 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 15 replies - 1 through 15 (of 17 total)
  • You’ll need to use mod to accomplish this and assign a class to each post.

    Here is a brief of mod:
    https://snook.ca/archives/php/the_modulo_oper

    Does that make sense?

    Thread Starter billionstrang

    (@billionstrang)

    Thanks, tomaltman,

    I’ve seen and tried about 50 different variations on the odd/even or the $i++ modulus operator, and none of them work in twentyeleven.

    I have a fairly weak grasp of php, so I can’t figure out the solution, but I fear that it either isn’t possible (in twentyeleven) or extremely complicated.

    Did your method work in twentyeleven?

    So what file are you overriding in your child theme to get to the loop?

    Thread Starter billionstrang

    (@billionstrang)

    The loop seems to be split between the index.php and the content.php. I’m trying to alternate the posts that have standard formatting, since those are the ones that have thumbnails. I thought it would be simple to do, so I designed a mock-up for my client, but now I’m not sure I can deliver.

    in content.php, change:

    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

    for instance to:

    <?php if( $wp_query->current_post%2 == 0 ) { $oddeven = 'odd'; } else { $oddeven = 'even'; } ?>
    	<article id="post-<?php the_ID(); ?>" <?php post_class($oddeven); ?>>
    Thread Starter billionstrang

    (@billionstrang)

    Thanks alchymyth, That’s getting close. It only alternates the first two posts though. I suppose I have to rewind the loop maybe?

    Here’s the basic illustration of what I’m trying to do:
    https://zoom-level.com/wolf-audio-mockup/

    I won’t be able to work on this today, but I’ll let you know if I get it figured out. Thanks for your time.

    Thread Starter billionstrang

    (@billionstrang)

    Actually, I see the problem. If I have a post formatted differently, like “link” or “aside” it breaks. If I have them all formatted standard it works.

    You would have to add that code to all the variations of content-whatever.php

    You would have to add that code to all the variations of content-whatever.php

    Out of my own curiosity..would that work?

    if yu have 2 normal posts, 1 aside, 2 normal

    would that end up being

    odd, even, odd, odd, even? if the count starts over in each content type?

    (sorry, just trying to follow along)

    @tomaltman
    good idea – this should work;

    (i only briefly tested the initial code in my test blog which does not use asides or so)

    just tested with a random ‘aside’ post in the list, and it seems to alternate nicely.

    Thanks @alchymyth, I really should have just tested it myself! Best way to learn!

    This, too I have been trying to get working. I saw the posts go back and forth for 5 intervals, yet then stops. Appreciate any new updates on this.

    Thread Starter billionstrang

    (@billionstrang)

    Thanks you guys!

    With alchymyth’s code and Tom’s suggestion of putting it in each content-whatever.php it alternates all the way through.

    But actually, I only want the standard formatted posts to alternate. I figured out that I can create a content-standard.php file and only apply the code to that, and it would work (in theory) except that “standard” is the only format that doesn’t have a format! I know it will work, because I tried it on one of the other formats.

    Codex says to put in: `$format = get_post_format();
    if ( false === $format )
    $format = ‘standard’;`
    https://codex.www.ads-software.com/Function_Reference/get_post_format
    which makes sense to me to define “false” as “standard” but I tried putting it in the loop, and in the function.php, with no results.

    Does anyone know how to make wordpress see content.standard.php, or should I start a new thread for this?

    Thread Starter billionstrang

    (@billionstrang)

    I take that back – It won’t work applying the odd/even code to just one format.

    this appears to alternate the ‘odd/even’ class only in the content.php (i.e. standard format):

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

    (code added to content.php only)

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