Forums

Loop with 2 divs (firstpost and post), can't separate thumbnails (5 posts)

  1. betic1
    Member
    Posted 4 months ago #

    I have successfully setup a loop that will make the 'firstpost' of the page it's own div with category and all others will have an id of 'post'. I followed the advice from someone here who had a link to their own blog explaining their idea further: .

    This blog is a video blog, with the 'firstpost' as the video being watched and a (hopefully) list of thumbnail's for all the other videos below that. My issue now is that I can successfully style the 2 divs on their own, but I need to separate the content between the two. They both use the same loop and I need the 'firstpost' to have no thumbnail and the 'post' div to only have a thumbnail and be an excerpt so it doesn't embed the full video.

    I thought something like an if div id='firstpost' then (this is where the story content would be) followed by an else if div id='post' (and it's own content here). I can't find a way in php to even look for an html div id, so there must be some other way to do this or there's something I'm missing. I've tried a few different approaches to this with all of them giving me a blank screen or an endless loop. Hope that long rant makes some kind of sense. Just let me know if anything needs further clarification. I'll include my current code here so you can see exactly what's going on. Thank you for any help you can offer, my brain is officially taxed on this one.

    I added some comments within the code snippet so you can see what I'm wanting to do.

    [code moderated - please use the pastebin]

  2. vtxyzzy
    Member
    Posted 4 months ago #

    I think you could increment a counter in your loop and test if it is equal to one or not to tell which div you are in.

    Can't tell more without seeing your code. Please put it in a pastebin as suggested above and post a link to it here.

  3. betic1
    Member
    Posted 4 months ago #

    Sorry about that...completely missed the fact that it didn't paste. That's what happens when doing too many things at once. Anyway, here's a link to the code at pastebin. Link to Code

  4. vtxyzzy
    Member
    Posted 4 months ago #

    I think something like this will do what you want:

    <?php $firstClass = 'firstpost';
    if (have_posts()) :
       while (have_posts()) : the_post(); ?>
    
          <!-- post -->
          <div id="<?php echo $firstClass; ?>">
          <?php if ($firstClass == 'firstpost') : ?>
             <?php $firstClass = 'post'; ?>
             <!-- code here for firstpost -->
          <?php else : ?>
             <!-- code here for post -->
          <?php endif; ?>
       <?php endwhile; ?>
       <!-- code here for after loop -->
    <?php else : ?>
       <!-- code here for no posts found -->
    <?php endif; ?>
  5. betic1
    Member
    Posted 4 months ago #

    Thank you for the help vtxyzzy, it worked great!

Reply

You must log in to post.

About this Topic