• Resolved jamo_dodger

    (@jamo_dodger)


    Hello,

    I am trying to achieve this particular layout for my posts on my blog page/homepage I hope this makes sense:

    |Most recent post fills whole content area|
    |2nd Post half the size| |3rd post half the size|
    |4th Post half size| |5th post half size|
    |6th post fills whole content area|
    |7th Post half size| |8th post half size|
    |9th Post half size| |10th post half size|
    |11th post fills whole content area|
    |12th Post half size| |13th post half size|
    |14th Post half size| |15th post half size|
    |16th post fills whole content area|
    |17th Post half size| |18th post half size|
    |19th Post half size| |20th post half size|

    |Ajax Load Post Plugin goes here to load more posts|

    I am currently using twenty twelve (child theme).

    I have tried using the transformationpowertools method:

    <article id="post-<?php the_ID(); ?>" <?php $extra = ( $wp_query->current_post % 5 && !is_paged() ) ? 'specialclass' : ''; post_class($extra); ?>>

    And this takes every 5 posts and assigns a class to the last 4 of them and this works great. However when i float these classes left in my CSS so they display next to each other I cannot add a margin to the right of the first half sized post and the left of the second:

    |1st Half sized post|margin margin |2nd half sized post|

    Unless there is something I am not thinking of I am going to have add one class to the half sized posts on the left and a separate class to the ones on the right:

    |Most recent post fills whole content area|
    |special class 1| |special class 2|
    |special class 1| |special class 2|
    |6th post fills whole content area|
    |special class 1| |special class 2|
    |special class 1| |special class 2|
    |11th post fills whole content area|
    |special class 1| |special class 2|
    |special class 1| |special class 2|
    |16th post fills whole content area|
    |special class 1| |special class 2|
    |special class 1| |special class 2|

    Can anyone tell me how I can do this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • you can expand on that logic;

    example:

    <article id="post-<?php the_ID(); ?>" <?php $extra = ( ( $wp_query->current_post % 5 == 0 && !is_paged() ) ? 'full' : 'half' ) . ( ( ( $wp_query->current_post % 5 == 1 || $wp_query->current_post % 5 == 3 ) && !is_paged() ) ? ' left' : '' ); post_class($extra); ?>>

    assigns the CSS class .full to every full width post, the CSS class .half to the other posts, and .left to each ‘special class 1’ post.

    Thread Starter jamo_dodger

    (@jamo_dodger)

    Amazing works a treat!

    I was having trouble using more than one $wp_query. Going to take me a while to figure out how the above actually works but thank you @alchymyth, yet again you have saved the day!

    James

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Given certain posts on blog page, their own class’ is closed to new replies.