Getting the number of posts in a category
-
Ok, I’ve found a couple different resources that deal with this issue but not quite in the way that I need it. I’m not very fluent in PHP so I’m having a hard time nailing down the syntax and whatnot.
Here’s what I’m trying to do: I want to take my category “Videos”, get the number of posts in the category an then chop it into 3 numbers so I can display all of the posts in 3 close-to-equal columns.
Here’s the code I have, I’m fairly certain it’s close just not quite working, so if I could get some help I would really appreciate it. Thanks in advance.
<?php /* Template Name: Vids */ ?> <?php get_header(); ?> <?php $vidsTotal=(get_categories('15')->count); <strong>This is the problem I think</strong> $vidsFirst=floor($vidsTotal/3); $vidsSecond=floor(($vidsTotal-$vidsFirst)/2); $vidsThird=ceil($vidsTotal-($vidsFirst+$vidsSecond)); ?> <div id="VidsLeft" style="width: 600px; margin: 2px 2px 2px 0;float:left;"> <div id="LeftLeft" style="float:left;width:300px"> <?php query_posts('showposts=$vidsFirst&offset=0&cat=15'); ?> <?php while (have_posts()) : the_post(); ?> <div class="text" align="center"> <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Continue reading <?php the_title(); ?>"><?php the_title(); ?></a></h3> <br /> <?php $values = get_post_custom_values("vid"); if($values != "") { echo "<object width='200'><param name='movie' value='$values[0]'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='$values[0]' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='200'></embed></object>"; } ?> <?php $values = get_post_custom_values("vidAlt"); echo $values[0]; ?> <br /> <?php the_excerpt(); ?> <?php endwhile; ?> </div> <div id="LeftRight" style="float:Right;width:300px"> <?php query_posts('showposts=$vidsSecond&offset=$VidsFirst&cat=15'); ?> <?php while (have_posts()) : the_post(); ?> <div class="text" align="center"> <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Continue reading <?php the_title(); ?>"><?php the_title(); ?></a></h3> <br /> <?php $values = get_post_custom_values("vid"); if($values != "") { echo "<object width='200'><param name='movie' value='$values[0]'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='$values[0]' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='200'></embed></object>"; } ?> <?php $values = get_post_custom_values("vidAlt"); echo $values[0]; ?> <br /> <?php the_excerpt(); ?> <?php endwhile; ?> </div> </div> <div id="RightVids" style="float:Right;width:300px"> <?php query_posts('showposts=$vidsThird&offset=($VidsFirst+$VidsSecond)&cat=15'); ?> <?php while (have_posts()) : the_post(); ?> <div class="text" align="center"> <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Continue reading <?php the_title(); ?>"><?php the_title(); ?></a></h3> <br /> <?php $values = get_post_custom_values("vid"); if($values != "") { echo "<object width='200'><param name='movie' value='$values[0]'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='$values[0]' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='200'></embed></object>"; } ?> <?php $values = get_post_custom_values("vidAlt"); echo $values[0]; ?> <br /> <?php the_excerpt(); ?> <?php endwhile; ?> </div> <?php get_footer(); ?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Getting the number of posts in a category’ is closed to new replies.