• Resolved paa1605

    (@paa1605)


    Hi guys,

    I have some code which retrieves the meta data associated to a categories parent. I’ve just added another child layer so therefore need to amend the code so that it now retrieves the grandparent instead. Does anyone know how to tweak the following to make this happen? I have tried myself but not had any joy. Thanks.

    <?php
    			$current = get_query_var('cat');
    			$cat = get_category($current);
    			$parent = $cat->category_parent;
    			if(function_exists('get_terms_meta')) {
               		$screen =  get_terms_meta($parent, 'logo');
         			$screen = $screen[0];
                		} ?>
    
       <a href="<?php echo get_category_link($parent); ?>"><img src="<?php echo ($screen); ?>" border="0" /></a>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Don’t have a good way to test this, but I think it should get you started. You didn’t say what to do if there is no grandparent, so I added a check for the existence of $top_cat in the if test.

    If you prefer to show the highest level found, simply uncomment the lines that assign a value to $top_cat.

    $current = get_query_var('cat');
       // $top_cat = $current;
       $cat = get_category($current);
       $parent = $cat->category_parent;
       if ( $parent ) {
          // $top_cat = $parent;
          $parent_cat = get_category($parent);
          $grandparent = $parent_cat->category_parent;
          if ( $grandparent ) $top_cat = $grandparent;
       }
       if( $top_cat && function_exists('get_terms_meta')) {
          $screen =  get_terms_meta($top_cat, 'logo');
          $screen = $screen[0];
       } ?>
    
       <a href="<?php echo get_category_link($parent); ?>"><img src="<?php echo ($screen); ?>" border="0" /></a>
    Thread Starter paa1605

    (@paa1605)

    Absolutely perfect!!

    Thanks Mac, very much appreciated ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get category grandparent help!’ is closed to new replies.