İn this post i will give a small php code for wordpress which displays your wordpress categories in a nice pie-chart. It might be useful for every blog which owner is interested to share statictics of his(her) blog.
This is code solution of this small task:

//Author: Elvin Haci
//Author url:
$ch_cats = get_categories(array('orderby'=>'count','order'=>'desc') );
$sayy= count($ch_cats);
$chd=''; $chl='';
for ($i=1;$i<=$sayy;$i++)
$ch_title="My blog categories by post count"; 
$ch_size="450x200"; // You can change it feet to your post
echo '<img src="'.$ch_title.'

If you want to place pie chart into your post or page, you must install InlinePHP at first. After install you will be able to execute php codes inside posts. You can put this code into any post, with phpinline tag [ exec ] …code here… [/exec]
But if you have enough practise working with theme editor, you can put this php code to any place of your theme, for example to sidebar widget(sidebar.php in your theme folder).

At the end i show you the result of this code(i place inside blog post, it means that i have used phpinline plugin for it), of course here it shows categorie-chart for :).

$ch_cats = get_categories(array(‘orderby’=>’count’,’order’=>’desc’) );
$sayy= count($ch_cats);
$chd=”; $chl=”;
for ($i=1;$i<=$sayy;$i++) { $chd=$chd.','.$ch_cats[$i-1]->count;
$ch_title=”My blog categories by post count”;
$ch_size=”450×200″; // You can change it feet to your post
echo ‘‘;

I can easily turn this code to new wordpress plugin if users who don’t like any coding need it.
Good luck. If any question, please don’t hesitate to write comment.

6 thoughts on “Displaying WordPress categories via Google chart

  1. Pingback: » Site Arxivi » Wordpress kateqoriyalarının Google chart ilə qrafik təsviri

  2. Hi Elvin,

    This would make a great plugin either for insertion into a page or as a widget.

    As the widget area is quite small a vertical bar would be better for those and pivotal question is:

    Can you make the categories links? So that the chart becomes “usable” to viewers?


  3. Hi Elvin,

    Is there an option, we can have separate charts for separate (Parent) categories, showing the count of their sub categories respectively?

    I have two different categories: Geographies and Trends, with many sub-categories. Would like to see two different charts there.


    • Hello Abishek. Yeah, it is possible. Just add parent argument(parent category id) to this code

      $ch_cats = get_categories(array('orderby'=>'count','order'=>'desc','parent'=>'your_cat_parent_id_here') );

Leave a reply

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>