Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi there,

    I already replied to your question here.

    Thread Starter shivika

    (@shivika)

    Hi Hector,

    So I”m having a little trouble figuring out how to merge my custom category function into the custom html filter.

    I’d like the category of my wpp posts to output the result of this:

    function ohd_get_the_category(){
       $output = '';
        foreach((get_the_category()) as $childcat) {
          $parentcat = $childcat->category_parent;
          if($childcat->category_parent == 0) echo '';
          else echo '<a href="' . get_category_link($parentcat) .'">' .get_cat_name($parentcat) .'</a> ';
    
      }
    }

    so I’ve been trying a whole host of variations in the filter like this;

    // Category option checked
            if ($instance['stats_tag']['category']) {
                $child_cat = get_the_category($popular->id);
                $parent_cat = (isset($childcat->category_parent))
                  ? '<a>term_id) . '">' . $parent_cat->cat_name . '</a>'
                  : '';
    
                if ($parent_cat != '') {
                    $stats[] = '<span class="wpp-category">' . sprintf(__('under %s', 'wordpress-popular-posts'), $parent_cat) . '</span>';
                }
            }

    to no avail.

    I call it in the output like this:

    $output .= "<p class=\"excerpt-category\">" . $parent_cat . "<span><a href="">id ) . "\"> Read <i class=\"fa fa-long-arrow-right\"></i></a></span>";

    I know I’m missing something but I can’t quite figure out what. Any help would be greatly appreciated. Thanks!!

    Thread Starter shivika

    (@shivika)

    I forgot to backtick

    // Category option checked
             if ($instance['stats_tag']['category']) {
                $child_cat = get_the_category($popular->id);
                $parent_cat = (isset($childcat->category_parent))
                  ? '<a href="' . get_category_link($parent_cat->term_id) . '">' . $parent_cat->cat_name . '</a>'
                  : '';
    
                if ($parent_cat != '') {
                    $stats[] = '<span class="wpp-category">' . sprintf(__('under %s', 'wordpress-popular-posts'), $parent_cat) . '</span>';
                }
            }

    Plugin Author Hector Cabrera

    (@hcabrera)

    Hi there!

    You used the backticks wrong πŸ˜› I’m asking a moderator to fix it for you (or use pastebin to share the entire code so I can take a better look at it).

    Thread Starter shivika

    (@shivika)

    Here it is – not so versed in backticks

    http://pastebin.com/yXqs38LR

    Plugin Author Hector Cabrera

    (@hcabrera)

    Your code seems incomplete. Here’s a full example using your category function: http://pastebin.com/Diqk7v5X

    Thread Starter shivika

    (@shivika)

    Hi,

    Yeah sorry – i just pasted the relevant code but it was wrapped in the whole function. The first thing I tried, actually, was just adding my function the way you did
    $post_cat = ohd_get_the_category($popular->id); but that didn’t seem to work. How are you calling the category in the output? I only see title, stats, and excerpt.

    Thanks!
    Shiv

    Thread Starter shivika

    (@shivika)

    I got it – it’s all in $stats. What you sent works great!! Thanks so much for your help.

    Shiv

    Plugin Author Hector Cabrera

    (@hcabrera)

    No problem, I’m glad to help!

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Custom category function instead of [category]’ is closed to new replies.