Skip to main content

Posts

Showing posts from September, 2010

Inserting custom content after each post programmatically

There are time when you may want to automatically display a custom text below each of your posts. You can hard-code it, but why do it when there is better way to do so using a WordPress hook. Here’s how to do. Paste the following code into your functions.php and save the file. Custom content will be inserted below each of your posts. function add_post_content($content) { if(!is_feed() && !is_home()) { $content .= ' This article is copyright © '.date('Y').' '.bloginfo('name').' '; } return $content; } add_filter('the_content', 'add_post_content'); Related Articles: Inserts Posts Programmatically to WordPress Insert Categories & Tags Programmatically to WordPress

Get popular posts by comments counts

Big the biggest challenge of blogger is to retain readers in their blog. One of the best technique to do this showing the most popular posts or related posts on the site where user is bound to see it. Keep this just below the current post may increase the chance of user seeing it. The reason to choose popular ones is because there might be a reason for it to be popular. So the chance for the reader like it is more. Getting the Popular Post Just copy & paste this piece of code where you want the list to display: $pop = $wpdb->get_results("SELECT id, post_title, comment_count FROM {$wpdb->prefix}posts WHERE post_type='post' ORDER BY comment_count DESC LIMIT 10"); foreach($pop as $post) : ?> post_title; ?>

Add categories & tags to post programatically

There often time when you want to add categories or tags to a post from code. Wordpress codex has a good deal of resource on this but most of the time it's hard for the beginners to grasp. In this post we will try to crack this the easiest way. First let us create an array of categories id. Then we simply have to use the wp_set_object() function, which by default take 3 parameters: The post id. Array of categories to add to the post. taxonomy type (category in this example). $category_ids = array(4, 5, 6); wp_set_object_terms( $post_id, $category_ids, 'category'); Here is how tags can be added: Adding tags to a post is extremely easy as well. The only difference with the code to add categories is the taxonomy "post_tag" instead of "category". Related Posts: Inserting Posts Programatically to WordPress Insert Custom Content After Each Post

Inserting posts programmatically to worpress

There times when you want to add post from your code. For example for creating a custom post panel for your users in a classifieds site. But most of them don't know that this can be achieved very easily. Just paste the following code anywhere on WordPress theme files. If you want to test,But for testing pasting it in your  'functions.php ' file is recommended. global $user_ID; $new_post = array( 'post_title' => 'My New Post', 'post_content' => 'Lorem ipsum dolor sit amet...', 'post_status' => 'publish', 'post_date' => date('Y-m-d H:i:s'), 'post_author' => $user_ID, 'post_type' => 'post', 'post_category' => array(0) ); $post_id = wp_insert_post($new_post); That's all you have to do. Once executed, this code will insert a new post into WordPress database. Related Posts: Add Categories & Tags programmatically to WordPress Insert Custom

Custom Fields and Verve Meta Box Plugin

Ever wanted a better way to add custom fields? Wanted  to add really usable and good custom field meta box so that your client is happy? Well then Verve Meta Box plugin is your answer. It's very easy to use and best one out there for the purpose. Verve Meta Boxes  allows for creation of text, textarea, image, file, date, time, datetime, select, radio, and checkbox custom fields for posts and/or pages. A Meta Box added by the Plugin Values for custom fields are stored in wp_postmeta and can be accessed in templates through standard WordPress functions such as: the_meta, get_post_meta, get_post_custom, get_post_custom_values, etc. Once installed, it adds a configuration screen to your admin page which will be located under Tools in the left navigation. There you can create multiple meta boxes each with a set of user defined drag and drop sortable custom fields. The Admin Panel added by the Plugin Getting the values on to the template:  Getting the values submit

Change the WordPress Login page logo link without plugin.

Are you making a site for your client and frustrated with the login page logo linking to the WordPress site? Well you are not the only one. But there is a very easy way to change this behavior without any plugin. All you have to do is add the following line to your functions.php file within your theme folder. add_filter("login_headerurl","the_url"); function the_url($url) { return get_bloginfo('siteurl');//return the current wp blog url } This will link the logo to your own wordpress blog. If you don't know how to change the default WordPress logo with one of your logo, then follow this post that wonderfully illustrates the same. More On The Topic: The official wordpress documentation on this can be found here . If you have any queries please use the comment form below.

Customizing the wordpress login page without Plugin

Every one love to see their site totally branded. It does feel good when your users see the WordPress login page when they have to login, may be just to post a comment. Biggest problem come when you are developing for a client. Well though most of them don't know the solution is simple. You don't have to rely on any plugin just to do few modifications on the login page. You just have to add few lines to your functions.php file within your theme folder. "This is the final result, after adding the below code to functions.php" add_action("login_head", "my_login_head"); function my_login_head() { echo "<style>body.login #login h1 a { background: url('".get_bloginfo('template_url')."/styles/logo.gif') no-repeat scroll center top transparent; height: 49px;width: 229px; margin-left:auto;margin-right:auto; } body {background: url('".get_bloginfo('template_url')."/styles/bg.jpg') re

Adding Custom Post Type in Wordpress

WordPress is no more a blogging platform. People always tried to use it as CMS by applying their own techniques and ways. Wordpress kept on adding new feature in this direction in their releases. One of the most important addition to wordpress in this direction is Custom Post Types. One of the major requirement when using wordpress as a CMS. For example, say you are creating a Travel website listing restaurants & hotels. You would need 2 post types. Restaurant Hotel Ofcourse people used to do this by using categories and all. But that was not a good solution when developing for a client. Now you could add custom post type by adding this small piece of code to your functions.php file within your theme folder: //Add restaurant function post_type_restaurant() { register_post_type( 'restaurant', array( 'label' => __('Restaurant'), 'public' => true, 'show_ui' => true ) );

Using Featured Image in WordPress

Today there are innumerable blogs on any topic you would choose. If you are a blogger your main priority would be to make your blog, stand out! Make it more attractive and tempt people to read what you right. One of the most important technique that major blogs use is setting a featured image for each post. This can be achieved very easily as it 's there in-built in wordpress. But you have to enable it in functions.php file within your theme folder. Here is how you do that: add_theme_support( 'post-thumbnails' ); Paste this within your functions.php file. Additionally you can specify which should have this feature in an array like this: // Add it for posts add_theme_support( 'post-thumbnails', array( 'post' ) ); // Add it for pages add_theme_support( 'post-thumbnails', array( 'page' ) ); You also additional control over this, you explicitly decide the dimension or hard crop the thumbnails etc. The dimension can be set like this: //the scale