WordPress.org

Ready to get started?Download WordPress

Forums

Will this work in v2.3 ? (2 posts)

  1. karimun
    Member
    Posted 6 years ago #

    I use the following code to display the total posts of a category:
    < ? php $count = $wpdb->get_var("SELECT category_count FROM $wpdb->categories WHERE cat_ID=7"); echo $count; ? >

    What happens with the next line which I use pretty often in my templates:
    < ? php query_posts("cat=7&showposts=3"); ? >

    And last but not least I suppose the var $cat probably will not work anymore (I use it to display category specific content and more)

    < ? php
    $headerline = $wpdb->get_var("SELECT cat_name FROM $wpdb->categories WHERE cat_ID=$cat");
    $headerline= strtolower($headerline); echo $headerline;
    ? >

    Will all this (not) be valid for the next version?

  2. karimun
    Member
    Posted 6 years ago #

    Well guys, I did some try&error with the v2.3 beta3 copy now and found out how to solve my probs mentioned above.

    Retrieve current category ID or category name:

    < ? php
    foreach((get_the_category()) as $category) {}
    $cat = $category->cat_ID;
    $catname = $wpdb->get_var("SELECT name FROM $wpdb->terms WHERE term_ID=$cat");
    echo $cat ." - ". $catname;
    ? >

    Total posts in a specific category (could be combined with the code above):

    < ? php
    $totalposts = $wpdb->get_var("SELECT count FROM $wpdb->term_taxonomy WHERE term_ID=THE_CAT_ID");
    ? >

    Show certain numbers of posts of specific category(same as for v2.2.x; place it above the loop):
    < ? php query_posts("cat=7&showposts=3"); ? >

    Maybe someone finds it helpful.

Topic Closed

This topic has been closed to new replies.

About this Topic