How to display featured pages in WordPress

I was working on a WordPress website for a client and one of the client requirements was to display featured pages on the home page. If you do a Google for this term you are most likely to find results for featured posts, related posts etc. However I found one plugin which fit the requirements completely and that is the Featured Page Widget plugin.

I downloaded and installed it via the Install Plugin option within the WordPress panel. It has quite an easy to use interface and the best part was that it gave options to select featured pages as well as posts.

As you can see from above the plugin provides many options to setup how you require it to work on your WordPress website. Once these changes are done you can then use it as a widget or you can use it via code. Here we will discuss it’s usage via the widget section in WordPress.

The widget provides you the options to display the number of pages on a page, which pages to display on the page, the template to use for displaying the pages (customizable), the amount of content to display for each page as well as the featured image dimensions to configure. Please note that widget only allows featured images to show on the page.

You just have to save the settings now and see it action on your website. As I said it’s very easy to use and the benefits far outweigh any limitations it may have.

Let me know how it went for you. If you need my help in setting this up on your WordPress website then please let me know.

Add WordPress blog to your website in a day

Most of the time I see postings from clients where they require a blog to be added to their websites so they can update latest news regarding their website on it and keep the website “fresh” for search engines and visitors alike. We all know that if a website does not update its content regularly visitors tend to get bored and stop visiting altogether which is a loss of traffic. Same is the case with search engine crawlers and bots.

After some analysis I have found that this requirement usually comes from clients who are running static websites (HTML) or dynamic websites (PHP) without the feature of blog in them. Static website owners cannot update their website content as they are not that skillful in HTML. If they need to add some content they will need to pay someone to update their website content in HTML. Dynamic website owners have the benefit of updating their existing pages through a database but they too are unable to add new pages and articles.

Seeing how WordPress has become popular due to its search engine friendly features, the demand for having a blog on a website becomes more necessary than ever. So it’s better to ask some one to install and customize the WordPress blog on your website and the best part is that is costs less as well. Depending on the template you wish to replicate on your blog it will cost anywhere between $30 to $150 and that’s money well spent considering the benefits one gets afterwards.

If you need my help or you need examples of websites where I have added WordPress in the same theme and style then drop me a line.

How I saved my WordPress blog from hackers

I always read about websites getting hacked and thought to myself “Hey these guys should spend some time on securing their websites”. I always thought that I would not be hacked as I did not leave my passwords on public computers and changed my passwords regularly. Boy was I wrong. Today some one placed a comment on my post. The comment was in Russian or Turkish language and I was really surprised that the comment appeared on the post without giving me the chance of moderating and approving it.

I tried to logging into the WordPress admin panel and was unsuccessful. The only thing I got was the dreaded “Incorrect username/password” message.

This called for drastic actions and I did the following.

  1. First I did damage control by renaming my blog folder via FTP
  2. Then I went into my hosting account and changed the database username and password
  3. I then connected via PHPMyAdmin and deleted the spam users on my blog.
  4. I did a backup of the wp_posts table and exported the SQL to my local computer
  5. I then dropped the complete database
  6. I then deleted the complete blog folder online
  7. I uploaded the latest WordPress 2.9.2 version online and installed a fresh copy
  8. I then uploaded the Lightword theme of WordPress and installed it

All the above steps took 40 minutes or so and my blog was back online. This is the first post I am writing after restoring the blog online.

As I did everything very quickly I did not spend time investigating the reasons how some one got into the WordPress admin panel in the first place and changed the admin password.

The only thing that comes to mind is that I had selected the “Anyone can register” checkbox on the Settings page and this may have allowed any one to register on the website. Then again I have unselected the option for the time being till I get to the bottom of this.

If you have anything to add then do let me know.

How to display specific content on the post page only?

After completing the custom field to display unique content work I found out that there was a problem. The problem was not with the functionality which I had just coded rather it was with how it was working.

Problem was that the $post->ID also existed on the archive and category pages. Due to this the system was displaying the content of the custom field on those pages as well which defeated the purpose which the client wanted.

I was aware of the function is_post() which used to check whether the page was a post of not. However, the said function has now been deprecated as of WordPress 2.8.3. My version of WordPress was 2.9.1 so the function was never going to work on this version. I headed off to the WordPress Conditional Tags page to check which function fulfills my requirements.

I soon found my answer. is_single() function provided the functionality I wanted. So, I made the following changes to the code written earlier

if (is_single()) {
        $custom_fields = get_post_custom($post->ID);
        $my_custom_field = $custom_fields['topcontent'];
        $display_title = $my_custom_field[0];
        echo $display_title;
}

and it worked like a charm. Now the content displayed only on the post page and no other page. The problem was solved and I heaved a sigh of relief.

Hope the above helped.

How to use custom fields in WordPress to display unique content in your post

A client of mine requested for a feature to control a section of the post. He was basically an SEO and he wanted his posts to look unique to search engines so that they get better rankings on them. As you know the more traffic you get the more visible you are on the internet.

I went about my work. I had read about Custom Fields on WordPress and I believed that they provided the answer to my problem. Custom Fields allow you to create fields which you can then use anywhere on your post page.

I created a field by the name of topcontent. I input some value against it and saved it with the post. I then browsed to the post page. I did not see the custom field and its value yet as obviously I had not fetched it and displayed it on the page.

I opened the header.php file in the theme directory. I entered the following code

$custom_fields = get_post_custom($post->ID);
$my_custom_field = $custom_fields['topcontent'];
$display_title = $my_custom_field[0];
echo $display_title;

where get_post_custom retrieves all the custom values associated with the post which I am referencing with the $post->ID.

I saved and uploaded the file and the custom field value started to display on the page.
I made the required number of custom fields for the client which he was able to change the value for each post thereby allowing him to display unique content to the search engines.

Hope the above helped.

How to customize the theme of your WordPress registration page

After implementing the theme on WordPress the client asked for the default WordPress registration page to be also completed in the same theme. He had a point in that the WordPress registration page will look very out to the visitor considering that the whole website theme was quite elegant.

I Googled it a bit and found that even though some people had worked on customization there was no one permanent solution to the problem and every body had more or less hacked the page according to their needs. This is understandable as there are a lot of different versions of WordPress out there.

After going through some code I found that it’s not that difficult to customize the page.

Open the wp_login.php file. You will find this file at the root. Find the function

function login_header($title = 'Log In', $message = '', $wp_error = '') {

and add all the header code of your template here. This function runs every time the page loads for the Login, Register and Forgot Password page so once you have implemented your theme header the theme will apply to the other pages as well.

If you need to edit any thing in the actual code of your registration (like I had to) then you can go to the function

function register_new_user($user_login, $user_email) {

and make the change there.

The footer is the easiest part. You just need to apply the footer code right at the bottom and voila you are all done.

You can see what I have done by going here.

New wordpress theme implemented on AdeelSarfaraz.com

Today I changed the theme of my blog. I sat down in the morning and downloaded WordPress and went to work on developing my own theme.

After a couple of hours here is what you see. It is not fancy in any way but it was my first go and Ill keep on improving its look as much as I can.

If you would like to use this them then you can download my version of the tableplain wordpress theme from here