Hana Code Insert Example 1: List of sub pages or sub categories

Hello, this is HanaDaddy and I would like to show you how to quickly add some quick sub categories or sub pages within a page or a post. For all of you that do not know what Hana Code Insert Plugin is, it’s a simple plugin that enables you to add piece of codes (HTML, Javascript, or even PHP) in the middle of post or page. You can use it to add AdSense, Paypal donation button, HTLM forms, Analytics, or anything.

First, you need to install Hana Code Insert Plugin.

Once you installed and activated the plugin, visit the Settings => Hana Code Insert option page. Activate the ‘Enable PHP Execution ‘ check box. You need to enable this checkbox to use PHP. Then create an entry by inserting below code This is to show sub page of the current post.

You should not define <?php or ?> and need to enable ‘Evaluate as php code’ when you create the code entry. Please refer to below image for more info.

image

This function will allow to show the list sub pages. Please note that $post variable has to be defined with ‘global’ modifier. The current post’s ID number is used as one of the function argument.

global $post;
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
if ($children) {
   echo "<ul>$children</ul>";
}

Now once you created the code entry, insert the hana code short code in the parent page.

image

Then click on the Hana Code Button to insert the code that we just created.

image

image

This is the output.

image

Just like this, you can show the list of categories or sub categories within a post or page.

//Shows full list categories except 10.
echo "<ul>";
wp_list_categories('orderby=name&show_count=1&exclude=10'); 
echo "</ul>";
//Shows the child categories of category 8.
echo "<ul>";
wp_list_categories('orderby=id&show_count=1&use_desc_for_title=0&child_of=8'); 
echo "</ul>";

Category ID or Page ID can be found by inspecting the URL of category or page edit links.

image

For more informaiton, here are the wordpress reference pages for wp_list_pages and wp_list_categories function.
http://codex.wordpress.org/wp_list_pages
http://codex.wordpress.org/Template_Tags/wp_list_categories

Hana Code Insert Forum

Leave a Reply