Recursive category tree in php and mysql

Tags

, , ,

Sometime you face problem in php to manipulate hierarchical data. This code will show you that how to display category tree in php. Here Mysql database used to store data. I have used here recursive method which search data in n Level . for example level 1 , level 2 , level 3 , level N…. as on. This simple code will work for multiple level as par your requirement. For example level 0 have ‘year’ category and its subcategory has ‘Jan’ ,’Feb’ as on. Continue reading

Applying the Category to Attachments in WordPress

Tags

,

You can assign category to media in wordpress using following php code.

function ptt_add_categories_to_attachments() {
	register_taxonomy_for_object_type( 'category', 'attachment' );
}
add_action( 'init' , 'ptt_add_categories_to_attachments' );

Continue reading

Force file download instead of open in browser

Tags

,

We can configure apache servers to force download files instead of shown in browser window. For example if you want to download Image , MP3 file when you click on that file link , you can use following code in .htaccess file.

<FilesMatch "\.(mov|mp3|jpg|png|pdf)$">
 ForceType application/octet-stream
 Header set Content-Disposition attachment
</FilesMatch>

Add post id to admin column in WordPress

Tags

,

Following example will shows how to add a custom column ‘ID’ in WordPress post.

To add a custom column for page ,  post in WordPress use ‘manage_post_posts_columns’ filter. I create a function named wp_add_post_ids_to_columns() which called via ‘manage_post_posts_columns’ filter to add column. Continue reading