Pogledajte određenu poruku
Staro 22. 10. 2011.   #3
ivanhoe
Ivan Dilber
Sir Write-a-Lot
 
Avatar ivanhoe
 
Datum učlanjenja: 18.10.2005
Lokacija: Bgd
Poruke: 5.320
Hvala: 104
2.344 "Hvala" u 583 poruka
ivanhoe je ime poznato svimaivanhoe je ime poznato svimaivanhoe je ime poznato svimaivanhoe je ime poznato svimaivanhoe je ime poznato svimaivanhoe je ime poznato svimaivanhoe je ime poznato svimaivanhoe je ime poznato svimaivanhoe je ime poznato svimaivanhoe je ime poznato svimaivanhoe je ime poznato svima
Pošaljite poruku preko Skype™ za ivanhoe
Default

Nije tako jednostavno, evo napisao sam jedan mini-plugin koji resava problem (samo se ubaci u functions), pa ako nekom treba slobodno ga koristite:

PHP kôd:
/**
 * Allows you to include and/or exclude posts by category from wp_get_archives() call
 * @author        Ivan Dilber (http://dilber.info)
 * @copyright     Copyright (c) 2011, Ivan Dilber 
 * @license        http://creativecommons.org/licenses/by/3.0/
 *
 * Usage:
 *      - Add the code below to the functions.php file (in you theme's folder)
 *      - Use wp_get_archives() as usual. You now have an additional param 'cat', that
 *        can be used to include/exclude one or more categories by ID. Negative value excludes
 *        the ID, positive includes only it (and you can mix the negative and positive values)
 * Example:
 *   - wp_get_archives('cat=-1,-2,3'); // exclude categories 1 and 2, include 3
 *   - wp_get_archives(array('show_post_count=1&cat=4'); //you can combine params
 *   - wp_get_archives(array('cat' => 4)); //another way to pass params
 */

/**
 * Register some hooks
 */
add_filter('getarchives_where''ivan_set_archives_where'102);
add_filter('getarchives_join''ivan_set_archives_join'100);

/**
 * WP Filter: Adds categories to the wp_get_archives() query
 * @author    Ivan Dilber (http://dilber.info)
 */
function ivan_set_archives_join() {
    global 
$wpdb;

    return 
" INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)";
}

/**
 * WP Filter: Change where condition to filter by category ID
 * @author    Ivan Dilber (http://dilber.info)
 */
function ivan_set_archives_where($where$args) {
    global 
$wpdb;

    if(empty(
$args['cat'])) // don't alter the query
        
return $where;

    
$cats is_numeric($args['cat'])? array($args['cat']) : explode(','$args['cat']);

    
$in $not_in = array();
    foreach(
$cats as $cat_id) {
        if(
$cat_id 0)
            
$not_in[] = -$cat_id;
        else
            
$in[] = (int) $cat_id;
    }

    
$sql $where ." AND $wpdb->term_taxonomy.taxonomy='category'";

    if(
$in)
        
$sql .= sprintf(" AND $wpdb->term_taxonomy.term_id IN (%s)"implode(', '$in));

    if(
$not_in)
        
$sql .= sprintf(" AND $wpdb->term_taxonomy.term_id NOT IN (%s)"implode(', '$not_in));

    return 
$sql;

Ukoliko neko ovo bude koristio u temama pls. ostavite copyright info, nije da cu ja to da proveravam, ali ipak...
__________________
Leadership is the art of getting people to want to do what you know must be done.

Poslednja izmena od ivanhoe : 22. 10. 2011. u 04:59.
ivanhoe je offline   Odgovorite uz citat