WordPress.org

Ready to get started?Download WordPress

Forums

Top-Cat-ID from Cat-ID? (2 posts)

  1. shadowrider
    Member
    Posted 6 years ago #

    Hi,

    i have any cat-id and would find the id from Top-category

    can me help?

  2. shadowrider
    Member
    Posted 6 years ago #

    please, if can no find the error of this code, i would find the Top-Cat-ID of the topic, cat or subcat if active:

    <?php
    function post_child_of_cat($child_post_id, $categorie, $art)
    	{
    if ($art=='1'){
    		$cat_array = wp_get_post_categories($child_post_id);
    		foreach ($cat_array as $category)
    		{
    			if (cat_is_ancestor_of((int)$categorie, (int)$category))
    			{
    				return true;
    
    			}
    
    		}
    
    } Elseif ($art=='2')
    
    if (cat_is_ancestor_of((int)$categorie, (int)$child_post_id)or ($child_post_id == $categorie))
    			{
    				return true;
    
    			}
    
    return false;
    }
    /* ende der function */
    
    ?>
    
    <?php
    
    if ( is_category() ) {
    $catb = get_the_category();
    $catb = $catb[0];
    echo $catb->cat_id; 
    
              while ($catb != 0) {
              $titel = $catb.','.$catb;
    
              $catb = $catb->category_parent;
              }
              $titel2 = '<p class="w"> '.single_cat_title('', FALSE).'</p>';
              $quernavi= $titel.' &raquo; </p>'.$titel2;
               } 
    
    elseif ( is_single() ) {
    $cats = get_the_category();
    foreach ($cats as $catu) {
    $catu=$catu->term_id;
    echo '<br />post-kat '.$catu;
    		}
    }
    
    while ($catu != 0) {
    $catu = $catu->category_parent;
    }
    echo '<br />a '.$catu;
    /* echo '<br />'.$cat->category_parent;
    $category = get_the_category($cat); */
    echo '<br /> b '.$cats[0]->category_parent;
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.