Post count by Parent Category

Here we’ll use the function – get_categories() to grab all the available categories and store it as array, Then we’ll loop through the array to display the list. Within the foreach loop we did a conditional check that is to determine if category is parent if so print it.

<?php
    $categories = get_categories();
    echo 'We have ';
    foreach($categories as $category) 
    { 
        //to check if category is parent
        if ($category->parent==0)
        {
            echo $category->count . ' '; 
            echo '<a href="' . get_category_link( $category->term_id ) . '">'. $category->name . '</a> , '; 
        }
    }
?>

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)