Hello!
Trying to get a horizontal layout working for a new portfolio site, where each different story is in its own category and gets a page of its own. Problem being the horizontal container must have a fix width corresponding to the number of posts within the shown category.
This might be trivial, but I haven't quite got the hang of php yet. I'm guessing it's possible to calculate the div width by creating a variable which multiplies the post count in the shown category with the post width. But how?
Any ideas? There's a test site up at http://www.fhoto.se/nytest
Would really appreciate help/advice/ideas! Thanks!
Fred
richarduk
Member
Posted 1 year ago #
It's a hack, but how about two loops? The first one gives the count, which is passed on to the second 'real' loop?
<?php $count=1; ?> // before the first loop
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<php $count++;?>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
<?php $total=$count*100; ?> //within the second loop
<div style="width:<?php echo "$total"; ?>px;">
blah
</div>
Which might output this:
<div style="width:100px;">
blah
</div>
If I understand your question correctly :-)
Great! Don't know if it's the best way to fetch the post count, but it works a charm. Here's what I used:
<?php $count=0; ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if ( in_category('6') && is_home() ) continue; ?>
<?php $count++;?>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
<?php $total=$count*670; ?>
<div id="bilder" style="width:<?php echo "$total"; ?>px;">
//second loop here
Excluded one category, got to test it some more once I get more of the site going. But as for now, this seems to do the trick. Already have two loops on the page though and I don't know if this will interfere, but we'll see.
Thanks!
richarduk
Member
Posted 1 year ago #
just put the standard query_post in front of each loop, that's all you need to keep everything happy
:-)