Showing posts with label Tutorials. Show all posts
Showing posts with label Tutorials. Show all posts

Thursday, December 23, 2010

Turn Your WordPress Into A Private Twitter-like System

inhouse-twitter-mainWordPress is best known as a blogging platform, but it can be a versatile piece of software as well, allowing you to turn it to almost anything you want. Here is how you can turn a WordPress installation into a in-house private Twitter-like microblogging system.

There is little or no coding required. What you need here is a custom theme and some plugins. There are currently two themes that can instantly turn your blog into a status update system: Prologue and P2.

Both themes require little or no configuration. As soon as you activate the theme, your blog frontend instantly become a Twitter clone.

WordPress Prologue Theme
Prologue Theme

WordPress P2-Theme
P2 Theme

Prologue theme is just a basic Twitter-like theme with no configuration option. On the other hand, P2 theme is more comprehensive and allows you to switch between "status update", "blog post", "Quote" and "Link".

With the P2 theme, you can also configure who can post update, the background image/color, show/hide sidebar etc.

inhouse-twitter-p2-options

Adding a login form to the sidebar


Instead of getting your users to go to the wp-login page, it will be great if you can add a login form to your sidebar and let your users login from the front page.

What you need here is the sidebar-login plugin. Install the plugin and add the widget to your sidebar.

inhouse-twitter-sidebar-login

At the sidebar-login option page, remember to set the "Login Redirect Url" to your Home page.

inhouse-twitter-login-options

Show status update only for logged in users


If you want to use this as a in-house private Twitter system, you won't want the public to see your update. The best way is to show the update only for logged in users.

Open the index.php file in your P2 theme folder.

Scroll down until you see the code:

[php]</h2>
<ul id="postlist">
<?php if ( have_posts() ) : ?>[/php]

Insert in the following code after </h2>

[php]<?php if(!is_user_logged_in()): ?>
<p>You need to log in to view the status update!</p>
<?php else : ?>[/php]

So now you should have:

[php]</h2>
<?php if(!is_user_logged_in()): ?>
<p>You need to log in to view the status update!</p>
<?php else : ?>
<ul id="postlist">
<?php if ( have_posts() ) : ?>[/php]

and don't forget to close the loop. Insert <?php endif; ?> before the </div><!-- main-->.

[php] <?php endif; ?>
</div> <!-- main -->[/php]

Repeat the same for the single.php file as well. You should see the following for non-logged in users.

inhouse-twitter-not-logged-in

Alternatively, you can also use the Private-WP plugin to force your users to login before they can read your status update. This is an easier implementation, but a less elegant solution.

This tutorial only touches the tip of the iceberg. If you have added your own modifications/enhancement, do let us know in the comments.

Monday, December 20, 2010

How to Make Your Theme Printer-Friendly Without Plugins

printer-iconIf you consistently provide good content on your blog, there is a high chance that some of your readers will print out your articles for future reference. The problem is, while your blog might look nice in the browser, it could be in a mess when you print it out. While there are several plugins that can format your site to printer-friendly layout, they can add extra overhead to your system and mess up your permalink structure (some plugins add a "/print" behind your URL). Here's a little trick to make your site printer friendly, without using any plugin.

Thursday, December 16, 2010

How to Show Related Posts in WordPress Without Using Plugin

related-posts-wordThere are many plugins that allow you to display related posts on your site, but most of them are either too bloated, too complicated or too simple. A better way is to implement the related posts function directly into your theme and reduce the server overhead. In this way, you can also theme it up the way you want it.

This tutorial will teach you how you can show related posts in your site without using any plugin.

Monday, December 13, 2010

How to Embed Tweets In Your Posts

embed-tweet-blackbirdBlog posts,Twitter, Facebook and many other social networks often go hand in hand. When you publish a blog post, you will often tweet the link to your Twitter account. Sometime when you send a tweet, you will also embed it in your blog post. The problem is, embedding a tweet in your post is not as easy as it should be. It often involves taking screenshot of the tweet, crop/edit it before you upload it to your post. With the introduction of Blackbird Pie, the whole process just become much easier.

Blackbird Pie is a method created by Twitter Media to easily embed a tweet on your site. Feed it with the tweet's URL and it will generate the necessary code for you to copy/paste to your site.

Thursday, December 2, 2010

How to Add Custom Navigation Menus to Your Themes

menus-compassWordPress 3.0 comes with support for custom navigation menu. The new feature is a good way for you to add navigation menu to your theme with little configuration. Best of all, it allows you to administer the menus from your dashboard. No longer do you need to tamper with the code to add/remove items from the menus.

Now, unless you are using an updated theme, chances are, your old theme does not support this new custom navigation menu feature. Here is how you can modify your current theme to support the menus feature.

Sunday, November 28, 2010

How to Replace WordPress Cron With A Real Cron Job

wpcron-missed-scheduleWe are all too familiar with the "Missed Schedule" status, aren't we? I am sure it is very frustrating to see that all your scheduled posts went MIA.

WordPress comes with its own cron job that allows you to schedule your posts and events. However, in many situations, the WP-Cron is not working well and leads to posts missed their publication schedule and/or scheduled events not executed.

To understand why this happen, we need to know that the WP-Cron is not a real cron job. It is in fact a virtual cron that only works when a page is loaded. In short, when a page is requested on the frontend/backend, WordPress will first load WP-Cron, follow by the necessary page to display to your reader. The loaded WP-Cron will then check the database to see if there is any thing that needs to be done.

Reasons for WP-Cron to fail could be due to:

  • DNS issue in the server.

  • Plugins conflict

  • Heavy load in the server which results in WP-Cron not executed fully

  • WordPress bug

  • Using of cache plugins that prevent the WP-Cron from loading

  • And many other reasons



There are many ways to solve the WP-Cron issue, but the one that I am going to propose here is to disable the virtual WP-Cron and use a real cron job instead.

Why use a real cron job?


By using a real cron job, you can be sure that all your scheduled items are executed. For popular blogs with high traffic, using a real cron job can also reduce the server bandwidth and reduce the chances of your server crashing, especially when you are experiencing Digg/Slashdot effect.

Scheduling a real cron job


To configure a real cron job, you will need access to your cPanel or Admin panel (we will be using cPanel in this tutorial).

1. Log into your cPanel.

2. Scroll down the list of applications until you see the "cron jobs" link. Click on it.

wpcron-cpanel

3. Under the Add New Cron Job section, choose the interval that you want it to run the cron job. I have set it to run every 15minutes, but you can change it according to your liking.

wpcron-add-new-cron-job

4. In the Command field, enter the following:
[bash]wget -q -O - http://yourwebsite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1[/bash]

Replace http://yourwebsite.com with your website URL.

5. Click the "Add New Cron Job" button. You should now see a message like this:

wpcron-current-cron-job

6. Next, using a FTP program, connect to your server and download the wp-config.php file.

7. Open the wp-config.php file with a text editor and paste the following line:

[php]define('DISABLE_WP_CRON', true);[/php]

8. Save and upload (and replace) this file back to the server. This will disable WordPress internal cron job.

That's it.

To test it out, it is best to schedule a post 5 - 10 minutes after you have completed the above configuration. Wait and see if the WordPress internal cron job is fired. If yes, then congratulation, you have successfully scheduled a real cron job for WordPress. If no, go through the steps above and see if you have made any mistake. Alternatively, contact your web host and get them to configure for you.

Wednesday, November 24, 2010

How to Add Featured Images to Your Theme

WordPress first introduced the "Post Thumbnail" feature in version 2.9. This feature allows the user to set an image as the featured image for the particular post. In version 3.0, the "Post Thumbnail" feature was renamed as "Featured Image".

By default, this featured image option is not turned on. You will need to place a simple code snippet in your theme file to activate the function. Here's how you can get it to work in your current theme.

In your theme folder, open the functions.php file. Add the following code to the end of the file:

[php]add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 150, 150, true ); [/php]

Explanation of the code


The line add_theme_support( 'post-thumbnails' ); activates the "featured image" function. You should be able to see the "Set featured image" link on the right sidebar of the post editing page or when uploading any image.

featured-image-link

The second code set_post_thumbnail_size( 150, 150, true ); determines the size of the thumbnail image. In this case, we have set it to be 150px wide by 150px tall. You can change it to suit your theme.

Displaying thumbnail images in your theme


Now that we have activated the feature, it is time to get it to display in the front end.

Open your index.php (or whatever place that you want the thumbnail image to appear). Within the loop, insert the following code:

[php]<?php
if ( has_post_thumbnail() ):
the_post_thumbnail();
endif;
?>[/php]

Note: The above code must be within the loop.

This will first check if there is any post thumbnail for the particular post. If yes, it will display the post thumbnail. If not, it will do nothing.

For more advanced uses, you can get it to display a default image when the post thumbnail is not available:

[php]<?php
if ( has_post_thumbnail() ) :
the_post_thumbnail();
else:
//url to the default image, or write your own code here
endif;
?>[/php]

That's it.