Create a Static Home Page

Almost 90% of blogs use the list of most recent posts as a homepage. However, if you prefer to use a static page as a homepage, the choice is yours. This technique allows you to use WordPress and create different kinds of web sites—not only blogs.

The possibility of using a static page as a homepage is built-in in the WordPress—however, a lot of bloggers aren’t aware of it.

How to do it

Step 1: Log in to your WordPress Dashboard and create a page named Homepage and publish it.

Step 2: On your WordPress Dashboard, go to Settings | Reading. You’ll see a title saying Front page displays.

Step 3: Select the A static page radio button and choose your new front page from the drop-down list. If you please, you can also choose a new template for the posts to be displayed.

statichomepage

For more information check the WordPress Codex: http://codex.wordpress.org/Creating_a_Static_Front_Page

Restoring a Live Blog into a Local Development Blog

If you purchased the Intermediate WordPress: Installing a Development Blog, you now have an ‘empty’ blog that is setup locally on your home PC to use for development of themes, plugins, etc.

This is great, but you may need some actual content to test out all your theme or other changes. Creating ‘dummy’ content is one option, but it can take awhile to create and is not the same as the actual content that a ‘live’ blog contains.

So if you already have a blog online, you can follow these steps after you have your local environment (Apache, PHP, and MySQL) up and running (covered in the lesson).

Step 1: Create a backup from your current live blog.

  • Log into phpMyAdmin (from a web host account), and select the “Export” tab.
  • Select the database your WordPress blog uses.
  • Make sure the “SQL” radio button is selected.
  • Click the “GO” button.
  • A new screen will display with a textarea box containing many SQL statements. These will re-create your entire database, tables with content when executed.
  • Copy this script to your favorite text editor

Step 2: Modifying your backup script.

  • Since we are restoring to a database from a different blog, we have to ‘tweak’ it a bit (database name and url parameters).
  • Change name of the database to the database of your development blog. This should be the first command in the script starting with CREATE DATABASE.
  • There are two lines that you need to specify the url of your development (http://localhost/). Do a text search on the ‘wp_options’ table. You will need to change the parameters of two INSERT INTO statements (‘siteurl’ and ‘home’).

Step 3: Copy your blog folder structure.

  • Copy the entire folder struture (and all files) of your live blog to your root directory of your local Apache environment. You can create a subfolder in your root if you wish. I discuss where this location is in the lesson.
  • Once copied, open up the wp-config.php file and make the neccessary changes. This would involve changing the database name (DB_NAME), database user (DB_USER), and database password (DB_PASSWORD) and MySQL host (DB_HOST). I discuss this in the lesson as well.

Step 4: Execute your modified restore script.

  • Open up phpMyAdmin in your local environment
  • Select the “SQL” tab.
  • Paste the restore script in the textarea box.
  • Click the “Go” button.
  • Verify that the database and tables have been created.

Step 5: Open up your local blog

  • Go to your local blog that you just copied all the files to. This will be http://localhost/. You will specify the subfolder if you created that as well.
  • Log into you blog

Now you have an exact local copy of your live blog that you can develop and test.

Note: Since we didn’t change any other parameters in the restore script, some of your plugins may not work. Also, if you use custom permalinks, you may need to modify your .htaccess file. Change your permalinks to the default setting (Settings->Permalinks), if you cannot see certain pages in your local blog.

Highlighting Searched Text in Search Results

I must admit that I’m not a big fan of the WordPress built-in search engine. One of its weakest features is the fact that searched text aren’t highlighted in the results, so the visitor is unable to see the searched text in the context of your article.

Luckily, there’s a nice hack using regular expressions to automatically highlight searched text in search results. This code has been created by Joost de Valk who blogs at www.yoast.com.

1. Open your search.php file and find the following:

1
echo $title;

2. Replace with:

1
2
3
4
5
6
<?php
$title = get_the_title();
$keys= explode(" ",$s);
$title = preg_replace('/('.implode('|', $keys) .')/iu',
'<strong class="search-excerpt">\0</strong>',$title);
?>

3. Save the search.php file and open the style.css file. Append the following line to it:

1
strong.search-excerpt { background: yellow; }

4. You’re done. Now, the searched text will be highlighted in your search results.

How It Works:

This code is using PHP regular expressions to find the searched terms in the text returned by WordPress. When an occurrence has been found, it is wrapped in a HTML element. Then, I simply used CSS to define a yellow background to this element.

Importing and Exporting Content

WordPress features a very useful script to import your posts, comments, and links from another platform to WordPress. Of course, it is possible to export your current blog content.

To access the Import tool, log in to your WordPress Dashboard and click on Tools | Import located at the top of the screen. To access the Export tool, go to Tools | Export.

Importing content
WordPress is able to import your previous blog content and automatically create post with it. WordPress can import content from Dotclear, TypePad/Movable Type, LiveJournal, Greymatter, Textpattern, Blogware, and Blogger.

To import your content from another blogging platform, you have to follow a platform specific procedure.

Importing content from an export file
The blogging clients, namely, LiveJournal, MovableType/Typepad, Blogware, and WordPress allow you to export your content into an xml , opml , or txt file. Follow this procedure to import your content from one of these blogging platforms:

1. Connect to your old blog and export your content. Save the file on your hard drive.
2. Log in to your WordPress Dashboard, then go to Tools | Import.
3. Select the blogging platform from where you’re importing the content.
4. On the next page, click on the Browse button to select the exported file located in your hard drive.
5. Once done, click on the Upload file and import button.
6. You’re done! Please note that depending on your exported file size, this procedure can take a while.

Read the rest of this entry »

Themes – An Overview

Themes determine the look of your blog and save you the time of having to deal with most of the code involved, although WordPress allows you to get your hands into as much code as you like.

Most people (but not us) will be happy keeping the default WordPress theme, which is known simply as WordPress Default (formerly called Kubrick, created by Michael Heilemann)

The WordPress community makes many themes for you to choose from and many are free. The best place to find a theme is the WordPress Theme Directory at http://wordpress.org/extend/themes/.

This directory is run by the same people who control WordPress itself, and they’ve set up some ground rules that a theme has to follow to be listed:

  • All theme files must be included in a single .zip file.
  • The theme must include a file called screenshot.png which is how the theme will look like.
  • The theme has to support widgets.
  • The theme must not contain any hidden or sponsored links.

You can change some of the functionality of your theme in two different ways: by adding widgets or using template tags.

Widgets are known as “side bar” accessories which are defined as WordPress add-ins which allow you to add design elements and functionality to your “sidebar” of your theme. The sidebar is normally an area on the right (sometimes on the left or bottom) that gives more information to the reader about the information in your blog. This can be a category list, a monthly archive of posts, blogroll, calendar highlighting days with posts, tag cloud, images, etc.

A template tag is a code that instructs WordPress to “do” or “get” something. It is a piece of PHP code that is encapsulated in a function. These code snipets are stored in the various PHP (.php) files that make up your WordPress theme.

Here are some videos (.zip) giving an overview of the topics covered in the class. In the class I cover these topics in much more detail as well many other topics.

Understanding Themes
Installing Themes
Customizing Themes
Modifying CSS
Modifying PHP

Code to Display the Most Recent Comments

There are a few plugins that will retrieve the most comments. But if you want a little more control or like to get your hands dirty in a little PHP code, there is a code snippet that will do the trick:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
 
global $wpdb;
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt,
comment_approved, comment_type,comment_author_url, SUBSTRING (comment_content,1,30) AS com_excerpt
FROM $wpdb->comments
LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID)
WHERE comment_approved = '1' AND comment_type = '' AND post_password = ''
ORDER BY comment_date_gmt DESC LIMIT 10";
 
$comments = $wpdb->get_results($sql);
$output = $pre_HTML;
$output .= "\n<ul>";
foreach ($comments as $comment) {
   $output .= "\n<li>".strip_tags($comment->comment_author) .":" . "<a href=\"" . get_permalink($comment->ID) .
   "#comment-" . $comment->comment_ID . "\" title=\"on " . $comment->post_title . "\">" 
   . strip_tags($comment->com_excerpt) ."</a></li>";
}
$output .= "\n</ul>";
$output .= $post_HTML;
echo $output;
?>

Most Recent Posts


Categories



Tag Cloud

Advertising Audience Automattic banner ads blog content Blog Posts CMS Coding Conference Content Customized Search Design Display Most Recent Comments Email Export content first post Google Adsense Gravatar Gravatar.com Highlighting Search Results Import content interview keywords loyal readers Matt Mullenweg Meetup meta tags niche PHP Plugins Posts Ranking search engine optimization SEO Social static home page success Themes USA TODAY WordCamp WordPress WordPress 2.7 WordPress 2.8 WordPress Extended RSS WXR

Recent Comments