SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jul 2003
    Location
    Toronto, Ontario
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Function Skipping Numbers

    Hey guys & gals,

    I'm using a function in Wordpress to display the number of posts in each category.

    The function is...

    Code:
    function the_category_count( $cat_id ){
    	$o = wp_cache_get( $cat_id, 'category' );
    	print $o->count;
    }
    However when I call the functions like this...

    Short Version:

    Code:
    <?php the_category_count(146); ?>
    <?php the_category_count(119); ?>
    <?php the_category_count(28); ?>
    Long Version:

    Code:
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(146); ?></div><a href="#" class="categories_right">3D</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(119); ?></div><a href="#" class="categories_right">Abstract</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(28); ?></div><a href="#" class="categories_right">Animals</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(118); ?></div><a href="#" class="categories_right">Anime</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(696); ?></div><a href="#" class="categories_right">Architecture</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(1003); ?></div><a href="#" class="categories_right">Celebrity</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(115); ?></div><a href="#" class="categories_right">City</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(413); ?></div><a href="#" class="categories_right">Closeups</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(379); ?></div><a href="#" class="categories_right">Comics</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(300); ?></div><a href="#" class="categories_right">Cultures</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(1146); ?></div><a href="#" class="categories_right">Food & Drinks</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(434); ?></div><a href="#" class="categories_right">Games</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(9); ?></div><a href="#" class="categories_right">Girls</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(105); ?></div><a href="#" class="categories_right">Grunge</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(122); ?></div><a href="#" class="categories_right">Holidays</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(1290); ?></div><a href="#" class="categories_right">In The Water</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(77); ?></div><a href="#" class="categories_right">Logos</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(25); ?></div><a href="#" class="categories_right">Movies</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(117); ?></div><a href="#" class="categories_right">Music</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(215); ?></div><a href="#" class="categories_right">Nature</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(1714); ?></div><a href="#" class="categories_right">Paintings</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(121); ?></div><a href="#" class="categories_right">Patterns</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(20); ?></div><a href="#" class="categories_right">Plain</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(793); ?></div><a href="#" class="categories_right">Politics</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(114); ?></div><a href="#" class="categories_right">Scenery</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(116); ?></div><a href="#" class="categories_right">Space</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(120); ?></div><a href="#" class="categories_right">Sports</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(102); ?></div><a href="#" class="categories_right">Textures</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(482); ?></div><a href="#" class="categories_right">Vectors</a></div>
    				<div class="single_categories"><div class="categories_left"><?php the_category_count(113); ?></div><a href="#" class="categories_right">Vehicles</a></div>
    Some categories are left blank, you can see an example of this in action here...

    http://idesigniphone.com/

    I tried to look for a pattern as to why this might be happening but I'm all out of ideas. Does anybody know why the function is skipping these numbers?

    Thanks for looking,
    Mario
    $ Available For Hire
    Need a website designed or coded? Then feel free to contact me!

    PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net

  2. #2
    SitePoint Addict
    Join Date
    Jul 2003
    Location
    Toronto, Ontario
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just noticed that when you click on another page the numbers change their mind which categories they want to show up beside.

    Anybody know what may be causing this?

    Is there a way to close the function once I'm done using it and reopen it?

    Thanks,
    Mario
    $ Available For Hire
    Need a website designed or coded? Then feel free to contact me!

    PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net

  3. #3
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It looks like some sort of caching issue. That would explain it varying per page.
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •