• 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]

Viewing 7 replies - 1 through 7 (of 7 total)
  • 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.

    Thread Starter betic1

    (@betic1)

    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

    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; ?>
    Thread Starter betic1

    (@betic1)

    Thank you for the help vtxyzzy, it worked great!

    Perfect, thanks vtxyzzy!

    OK it works fine but I still need some help here:

    I want all categories to have the first post in their own div with their own styling except for category 6.

    So I guess I need a conditional like

    <?php if ( ! is_category("1") ) { ?>
    ////
    <?php } else { ?>
    ////
    <?php } ?>

    But, since the code is already full of conditionals itself I can’t get the syntax right.

    So how would I do that?

    Thanks!

    Took me a while to get it working.
    I have now two seperate loops, one for post in the category and the other for the posts that are not in that category.

    It works as I want it to, but surely it does not deserve a price for efficiency. Anyone who knows of a better way to do this: please feel free to improve on it.

    Cheers.

    <?php if ( is_category("beeld") ) { ?>
    
            <?php if (have_posts()) :
      				 while (have_posts()) : the_post(); ?>
        	<!-- code for posts in "beeld" category -->
    
         <?php endwhile; ?>   
    
          <?php else : ?>
    	<h2>sorry, geen berichten gevonden</h2>
    		<?php endif; ?><
    
         <?php }//End of my conditional?>
    
        <?php if ( !is_category("beeld") ) { ?> 
    
           <?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 --></div>
          	<?php else : ?>
              <div>  <!-- code rest of posts --> </div>
    
    		<?php endif; ?>
       		<?php endwhile; ?> 
    
            <?php else : ?><!-- no posts? -->
    	<h2>sorry, geen berichten gevonden</h2>
    		<?php endif; ?>
    
            <?php }//End of my conditional?>
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Loop with 2 divs (firstpost and post), can't separate thumbnails’ is closed to new replies.