• Resolved photo_ed

    (@photo_ed)


    Hi everyone

    I am working on a site want to have three random column widths. I found an example that hows me how to generate the random number for the class

    <a href="<?php the_permalink(); ?>" class="box col<?php echo rand(2,4); ?>">... </a>

    but in my theme I am using post_class() so I am not sure how to add the echo rand statement.

    <article id="post-<?php the_ID(); ?>" <?php post_class('box col'); ?>>
    ...
    </article>

    I am still learning all this and have tried how I thought it should be concatenated but none of them worked. If someone could point me in a direction or tell me a better way it would be greatly appreciated

    Thx

Viewing 2 replies - 1 through 2 (of 2 total)
  • wpismypuppet

    (@wordpressismypuppet)

    Try…

    <?php $num=rand(2,4); ?>
    <article id="post-<?php the_ID(); ?>" <?php post_class('box col'.$num); ?>>
    ...
    </article>

    This isn’t tested, but I don’t see why it wouldn’t work.

    Thread Starter photo_ed

    (@photo_ed)

    That worked Thanks so much, I knew it was something simple I was overlooking.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding a random number to post_class’ is closed to new replies.