Home>

I'm creating a site with Wordpress, but when I get a list of categories, I want to get and output categories without articles with a table tag without links. I received it.
If this is the first question, I ’m sorry if there ’s anything wrong.
Thanks for your cooperation.

Thanks for your reply.
I will add it.
The following are currently used.

<table>
    <tbody>
<? php
$args = array (
    'orderby' =>'count',
    'order' =>'DSC'
);
$categories = get_categories ('parent = 0');
foreach ($categories as $category) {
    echo '<tr><td><a href = "'. get_category_link ($category->term_id). '">'. $category->name. '</a></td></tr>';
}
?>
    </tbody>
</table>


Normally, the top category is acquired and output, but first, how to get a list of category names that do not have articles, and those with and without articles can be sorted and sorted I do n’t know if.

  • Answer # 1

    $args = array (
        'orderby' =>'count',
        'order' =>'DSC',
        'parent' =>0, // ← 'parent = 0'
        'hide_empty' =>false // ← whether or not to display if there is no post
    );
    // $categories = get_categories ('parent = 0');// ← $args not used
    $categories = get_categories ($args);

    【get_categories – WordPress private manual】

    【get_categories () | Function | WordPress Developer Resources】
    https://developer.wordpress.org/reference/functions/get_categories/