Wordpress has a very simple database schema. And it is well documented. You can access the complete description of the wordpress core database from here, http://codex.wordpress.org/Database_Description.
Anyway first time I looked at the database I was confused with the term and the term_taxonomy table, why we need two tables for term and taxonomies. In fact in wordpress, the table ‘posts’ is associated with the table ‘term_taxonomy’ and not the table ‘term’ itself. In the term taxonomy table the terms are associated to a link category, post category or a tag. So the associations of posts to a tag or category is something like this.
wp_term_post association
So in a case you try querying for posts with a given tag it will be like this. (Note that I have skipped the optional database table prefix which is by default ‘wp_’)
SELECT post_title,
post_content,
post_date
FROM posts p,
terms t,
term_relationships r,
term_taxonomy tt
WHERE p.post_status='publish'AND
tt.taxonomy = 'post_tag'AND
p.id=r.object_id AND
r.term_taxonomy_id=tt.term_taxonomy_id AND
tt.term_id = t.term_id AND t.name LIKE ?
It is really easy to write a widget to the wordpress blog. So I thought of writing my own widget to show Google ads in my Blog. Here is how I did it.
First generate the JavaScript code for your adsense account from the Google Adsense Page. You can do this by sigining in to the Dashboard of Adsense from https://www.google.com/adsense/. Then click the “Adsense Setup” tab and follow the wizard.
Inside the “wp-content/plugins” directory of your Wordpress installation create a file for your plugin. (Say myadsense_widget.php)
Then first write the code that should be appeared in your widget. In this case you can just echo the the code provide by the Google. Anyway In order to make your widget complaint with the current theme, you have to use the code similar to the following.
// the function for the widgetfunction widget_myadsense($args){// being aware of the themeextract($args);
echo$before_widget;
echo$before_title . "Google Adsense". $after_title;
// here you just echo the code provided by the google echo <<<GOOGLE_JS
<!-- in this space you have to copy paste
the code provided by the google-->
GOOGLE_JS;
// again being aware of the themeecho$after_widget;
}
Then write the code to register the above function as a widget with the following piece of code.
We are almost done here, But don’t forget you can mention your information as the widget plugin author with a comment similar to the following template.
/*
Plugin Name: MyAdsense
Plugin URI: http://dimuthu.org
Description: Adsense Plugin for my blog
Author: Dimuthu Gamage
Version: 0.1
Author URI: http://dimuthu.org
*/
That is all you have to code. Now just go the Plugins section of the wordpress from your Dashboard and enable the plugin (”myadsesne”) you just created.
Go to the Design->Widget section and add your Widget to the Sidebar and click “Save Changes”. And go to your blog URL and make sure that the Ads are shown in there.