huhu liebes forum,
also das thema hat sich von meiner seite her ersteinmal (nach ein paar stunden gebastel) erledigt ...
mein denkfehler war, dass ich ja keinen secondary wp-loop ansich brauche sondern vielmehr einen äußeren simplen "loop" der filtert und kategorisiert.
so hab ich dass dann auch gelöst ... falls später mal jemand auf diesen post hier stoßen sollte, soll er natürlich auch nich ohne lösung nach hause gehen ... sozusagen mein kleiner einstand hier im forum ;)
PHP
// config this
$hide_cats = array('About');
//autogenerate hide items of
$hide_items_of = array();
foreach($hide_cats as $cat) {
$hide_items_of[] = get_cat_ID( $cat );
}
//get the types to collect categories
$type_map = array('post');
$args=array(
'public' => true,
'_builtin' => false
);
$output = 'objects';
$operator = 'and';
$post_types=get_post_types($args,$output,$operator);
foreach ($post_types as $post_type=>$definition ) {
$type_map[] = $post_type;
}
//prepare categories and scopemap
$categories = array();
$scopes_map = array();
foreach($type_map as $type) {
$categories = array_merge($categories, get_categories('type='.$type));
}
//scopes (parent categories)
foreach($categories as $scp) {
if($scp->parent != 0 || in_array($scp->cat_ID, $scopes_map) || in_array($scp->cat_ID, $hide_items_of)) continue;
$scopes_map[] = $scp->cat_ID;
}
//scopechilds
foreach($categories as $scp) {
if(!in_array($scp->parent, $scopes_map)
|| (is_array($childs_map[$scp->parent]) &&in_array($scp->cat_ID, $childs_map[$scp->parent]))
|| in_array($scp->cat_ID, $hide_items_of)) continue;
$childs_map[$scp->parent][] = $scp->cat_ID;
}
//enable hide items of
$query = '';
foreach($hide_items_of as $hide) {
$query .= ',-'.(string)$hide;
}
$query = substr($query, 1);
global $query_string;
query_posts( $query_string . '&cat='.$query );
//set basics for looping
global $wp_query;
$toDo = $wp_query->post_count;
$used = array();
$act_scope = 0;
// the whole loop-process
while($toDo > count($used)): //starts the outer loop (usage-loop)
while(have_posts()): //starts the inner loop (wp-loop)
the_post();
//check-functionality
$post_cats_raw = get_the_category();
$post_cats = array();
foreach($post_cats_raw as $pc) {
$post_cats[] = $pc->cat_ID;
}
if(in_array($post->ID, $used)) continue;
$match = false;
$prevent_scopejump = false;
if(is_sticky()) {
$prevent_scopejump = true;
$match = true;
} elseif(in_array($scopes_map[$act_scope], $post_cats)) {
$match = true;
} else {
foreach($post_cats as $pc) {
if(!is_array($childs_map[$scopes_map[$act_scope]])) break;
if(in_array($pc, $childs_map[$scopes_map[$act_scope]])) { $match = true; break; }
}
}
if(!$match) continue;
//set as used item
$used[] = $post->ID;
// <--------- ITEM ------------->
get_template_part( 'loop-item', 'index' );
//reset
rewind_posts();
break;
endwhile; // End the inner loop.
//scopejumps
if(!$prevent_scopejump) {
if($act_scope < count($scopes_map)) {
$act_scope++;
} else {
$act_scope = 0;
}
}
endwhile; // End the outer loop. ?>
Alles anzeigen
also es funktioniert für meine belange tadellos und is recht performant, da ich ja das paging nich anrühre.
falls jemand fragen haben sollte ... einfach hier posten ;)
lg
some