Forums

[resolved] Add HTML element after every certain post (3 posts)

  1. bodjiang
    Member
    Posted 1 year ago #

    Hi all,
    I was Googling this all day, but no solution, (or I don't see the solutions with my PHP knowledge), I was hope I can get help from here, where I often had.

    straight to the point, I had posts in "project-gallery" category displayed as gallery posts, more like this one, I wish to add a </hr> Tag after every new row, in my case after ervery fifth post. I think I need work on something on $counter, but I am going no where with my lack skill in php, can anyone help?

  2. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    Something like this should work:

    <?php $c = 0; if (have_posts()) : while (have_posts()) : the_post(); $c++;?>
    [ usual Loop stuff for post display ]
    
    <?php if( $c == 5 ) :?>
    <hr />
    <?php $c = 0;
    endif;?>
    
    <?php endwhile; ?>
    <?php endif; ?>
  3. bodjiang
    Member
    Posted 1 year ago #

    THANK YOU SO MUCH!!!
    You are the legend~!!!
    I manage to modify your code to make mine works, I change $c == 5 to 6 in order for it go after 5th post.
    Thanks again~!

Topic Closed

This topic has been closed to new replies.

About this Topic