Warning: ob_start(): non-static method wpGoogleAnalytics::get_links() should not be called statically in /home/ronggur/public_html/sandbox/wp-content/plugins/wp-google-analytics/wp-google-analytics.php on line 259
Ronggur Hutasuhut Playground - Web developer and designer Jakarta, Indonesia

WordPress : How to get category ancestor

by ronggur on October 31, 2011

Here is code I usually use to find ancestor or parent of a category

function getCategoryAncestor($cat,$index=0){

$parentCatList = get_category_parents($cat,false,',');
$parentCatListArray = @split(",",$parentCatList);
$topParentName = $parentCatListArray[$index];
$charReplace = array(" " => "-", "(" => "", ")" => "");
$topParentSlug = strtolower(strtr($topParentName,$charReplace));
$catAncestor['ancestor'] = $topParentName;
$catAncestor['ancestor_slug'] = $topParentSlug;
return $catAncestor;


// How to use :
// if you have this category (by term ID) structure : 1 > 2 > 3
// to get ancestor of a category ID 3

$ancestors = getCategoryAncestor(3);

// to get parent of a category ID 3

$ancestors = getCategoryAncestor(3,1);

I know this code is premature, it’s only works when you didn’t modify the category slug. But at least it is working in almost all my projects :p.


WordPress : Custom Action Hook in Action

by ronggur on August 9, 2011

There are two types of hook in WordPress, filter and action. And in this occasion I will try to give examples about Actions hook.

According to codex.wordpress.org:

Actions: Actions are the hooks that the WordPress core launches at specific points during execution, or when specific events occur. Your plugin can specify that one or more of its PHP functions are executed at these points, using the Action API.

You can find more complete explanation about this hooks in http://codex.wordpress.org/Plugin_API and right now I only give simple example to create custom hook that would give us benefit if we want to build wordpress plugin.

Read the rest of this entry »

Newscoop Contest Design

by ronggur on July 27, 2011

Newscoop is an open source CMS used by hundreds of independent news organisations to publish content online. Sourcefabric are looking for individuals to create a new theme that brings together quality journalism, with quality design. The prize? A chance to meet media experts and develop their design with an all-expenses paid trip to Sourcecamp Prague 2011.

The contest is looking for designers and developers to invent new ways to display news content, new ways to integrate comments and social media into the user experience, and new ways to adapt site design to mobiles and tablets.

The contest is free to enter and open until October 5th 2011. Interested parties can visit http://contest.sourcefabric.org to find out more.

RH Yahoo! Messenger WordPress Plugin

by ronggur on May 24, 2011

Hi, there. In this post I want to introduce my first WordPress plugin :D . This plugin is a widget plugin that will shows multiple Yahoo! Messenger Status of your own. So here it is..


The plugin is simple to use:

1. Download `rh-ym-status.zip` you can download here RH Yahoo! Messenger Status WP Plugin | size : 66.22 kB
2. Unzip
3. Upload `rh-ym-status` directory to your `/wp-content/plugins` directory
4. Enable the plugin via plugin managament page
5. Go to widget area and fill your Yahoo Name(s) and Yahoo ID(s) to show your Yahoo! Messenger status in widget area

Read the rest of this entry »

WordPress : Get page permalink by name, slug or title outside loop

by ronggur on April 19, 2011

I know we have get_permalink() in WordPress to get permalink by id of specific page. So this post is only alternative how to get the permalink by name, slug or title.

1. Get Page ID by name, slug or title

function rh_get_page_id($name)
global $wpdb;
// get page id using custom query
$page_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE ( post_name = '".$name."' or post_title = '".$name."' ) and post_status = 'publish' and post_type='page' ");
return $page_id;

Read the rest of this entry »

WPTrick : Add new element into wp menu

by ronggur on January 9, 2011

A simple trick to add new element into your wp menu.In this case I want to add custom search form to may

Just add this codes to your wp code I usually put in in functions.php


// Filter wp_nav_menu() to add additional links and other output
function custom_nav_menu_items($items, $args) {

 $search = '<li id="search">';
 $search .= custom_searchform();
 $search .= '</li>';
 $items = $items .$search;

return $items;
add_filter( 'wp_nav_menu_items', 'custom_nav_menu_items', 10, 2 );

function custom_searchform(){
 $search = get_search_query();
 if($search) $search_text = $search;
 else $search_text = "Search";

 $form = '<form method="get" id="searchform"  action="'.get_bloginfo('home').'">';
 $form .= '<fieldset>';
 $form .= '<input type="text" value="'.$search_text.'"  name="s" id="s"  />';
 $form .= '<input type="hidden" id="searchsubmit" />';
 $form .= '</fieldset>';
 $form .= '</form>';

 return $form;


Method above will add search form to all wp menu. So how about if I only want to add to specific menu location?

Here we goes


# apply only ini 'header-menu' location

if($args->theme_location == 'header-menu'){
 $search = '<li id="search">';
 $search .= rh_searchform();
 $search .= '</li>';
 $items = $items .$search;



quote of the day

by ronggur on September 14, 2010

quote of the day :

wordpress makes your life seem easier

Capturing it

by ronggur on April 15, 2010

Let me introduce my new photoblog http://shoot.ronggur.com :D . New hobby and of course need new extra time :p. Still and always need more knowledge about this new hobby.


Houston, We’ve Got a Problem

by ronggur on February 2, 2010

houston we've got problem

houston we've got problem

Last nite i found my blog down for several hours, i don’t know what happened and now it’s up again but unfortunately there are some comments lost (sorry). But it’s okay since i’, not losing the whole database

images taken from here

jQuery Tutorial : Simple ajax star rating with php (extended)

by ronggur on January 19, 2010

Some people ask me question about how to implement my last star rating in multiple star rating, and here is the answer on how to implement it.

1. Upgrade latest table

Since you’ll need to add ‘id’ on multiple record then we need to upgrade the existing table. Here is the full sql

 `id` int(11) NOT NULL auto_increment,
 `desc` varchar(50) NOT NULL,
 `counter` int(8) NOT NULL default '0',
 `value` int(8) NOT NULL default '0',
 PRIMARY KEY  (`id`)

-- Dumping data for table `vote`

INSERT INTO `vote` (`id`, `desc`, `counter`, `value`) VALUES
(1, 'star - 1', 0, 0),
(2, 'star - 2', 0,0);

2. CSS

We still can stylesheet from the previous post. No need to modify it.

Read the rest of this entry »

You can give me some coffee if you want to :D