Loop categories by recent post

First set a function to be used later with a usort to sort the categories by date of most recent post:

    function orderByDate( $a, $b ) {
        return strtotime($a['date']) - strtotime($b['date']);
    }

Get your categories as you were doing:

    $args = array(
       'hide_empty'=> 1
    );
    $categories = get_categories($args);
    $categoriesWithDates = array(); // Create an array variable to be used in a moment
    $counter = 0;
    foreach($categories as $category) { 
        $the_query = new WP_Query(array(
            'post_type' => 'article',
            'posts_per_page' => 1, //This time only get one post
            'category_name' => $category->slug,
            'order' => 'DESC'
        ));

In the while loop, we create an array containing the category slug and the date of it’s most recent post:

        while ( $the_query->have_posts() ) : 
            $the_query->the_post();
            $categoriesWithDates[$counter] = array('slug' => $category->slug, 'date' => get_the_date(DATE_RFC2822));
        endwhile;
      $counter++;
    }
    wp_reset_query();

Sort the categories by date using usort and the function orderByDate()

    usort($categoriesWithDates, "orderByDate");

Create a new loop to display the posts, this time using the newly created and date sorted array, categories with dates. This will have ordered your category slugs in order of which has the most recent posts, putting this into your query with a foreach will therefore display the categories in the order you want them to be:

    foreach($categoriesWithDates as $categoryWithDate) { 
                $the_query = new WP_Query(array(
                    'post_type' => 'article',
                    'posts_per_page' => 100,
                    'category_name' => $categoryWithDate['slug']
                ));

                while ( $the_query->have_posts() ) : 
                $the_query->the_post();
                  // Post studd 
                endwhile;
    }

There might be a better way to craft this all into one loop, but it would take more thinking, and this should get you started anyway! Something like this should do the trick, though I’ve not tested it.

EDIT:

I’ve added in a counter which I think might help resolve the issues. Also, I’ve set the date format on get_the_date() to DATE_RFC2822 (See: http://php.net/manual/en/function.date.php). Also, wp_reset_query(); has been added between the two queries.