Wordpress PHP Problem

Hi all,

I’m hoping someone could just check the following code for me. Basically I had my website coded for me and I’m not quite sure how to fix this problem.

It’s a Wordpress site, I’m using one plugin which lists the most popular content. The way the site was setup was so that I have widgets featuring our latest/most popular and random articles in a tabbed box. These work if you only link to one category (must be the actual category not a parent category).

For example, these are the two parent categories:

Blogs - category 1
(sub categories = 1a, 1b, 1c etc)

Reviews - category 2
(sub categories = 2a, 2b, 2c etc)

It will only display articles if I put the id as 1a or 1b or 2c etc. It will not display more than one id. So if I put the category id as 1, nothing will display, only if I put 1a or 1b etc then it will display articles from that one sub category.

I’m trying to create a tabbed box to display content from 2 categories (which contain multiple child categories)…however it just doesn’t seem to work. I did hire someone to fix it, they said they changed the code (which is below)…but it’s still not working. I just wanted to see if anyone can spot any issues with it?

This is part of the code from the widgets.php file from the theme folder. I think this is the relevant part for this plugin:

// Widget Custom Archive
class Widget_Category_info  extends WP_Widget{
   function Widget_Category_info(){
       $widget_ops = array('description' => __( "Category Info." ));
       $this->WP_Widget('category-info', __('Category Info'), $widget_ops);
   }
   function widget($args, $instance){
       extract( $args );
       $title = apply_filters('widget_title', empty($instance['title']) ? __('') : $instance['title']);
       $numb = (int) $instance['number'];
       $cat_ids = explode(',', $instance['cat_id']);
       $cat_id = $instance['cat_id'];
       if(!$numb) $numb = 5;

       echo $before_widget;
       if($cat_id) echo '<div class="category-'.get_category($cat_ids[0])->slug.'">';
       if($title && $title != '') echo $before_title . $title . $after_title;
       if($cat_id) echo '</div>';

       $posts_args = 'numberposts='.$numb.'&orderby=date&order=DESC';
       if($cat_id) $posts_args .= '&category='.$cat_id;
       $latest_posts = get_posts($posts_args);

       $posts_args = 'numberposts='.$numb.'&orderby=rand&order=ASC';
       if($cat_id) $posts_args .= '&category='.$cat_id;
       $rand_posts = get_posts($posts_args);

       $posts_args = 'limit='.$numb.'&pages=0';

       if($cat_id){
            $pos = strpos($cat_id, ",");
            if($pos){
           $cat_id= explode("," ,$cat_id);
          
           $all_cat = get_categories('hide_empty=0');
           foreach($all_cat as $el){$cats_list[] = $el->cat_ID;}           
           $available = array();
           $available = array_diff($cats_list,$cat_id);
           $available = implode(",", $available);
           $posts_args .= '&cats_to_exclude='.$available;
           
            }else{
           $cats_list = array();
           $all_cat = get_categories('hide_empty=0');
           foreach($all_cat as $el){ if($el->cat_ID != $cat_id) $cats_list[] = $el->cat_ID;}
           $cats_list = implode(",", $cats_list);
           $posts_args .= '&cats_to_exclude='.$cats_list;
           
            }
          

Any advice/help would be appreciated.

Thanks