How To: Showing Only a Post Excerpt in WordPress

Depending on the type of blog you run, you may at some point have an interest in only showing only a short excerpt of a post on your blog’s homepage. This could be for a variety of reasons, ranging from attempting to increase page views to trying to make your homepage more easily navigated and organized.

Another really popular place for using the post excerpt is for your archive pages, which helps you to avoid being penalized for duplicate content by the search engine spiders.

No matter what the reason is, if you are interested in switching some of your templates to show post excerpts, it isn’t very difficult to do. Go to the template you want to make the change on and find the following code:

< ?php the_content(); ?>

Depending on your theme, it may include something in the parenthesis. Change this code to the following:

< ?php the_excerpt(); ?>

This will cause your blog theme to only display the first 55 words (and strip pictures/formatting). If you’d like to add a link to allow readers to then click over and read the full post, you can instead use something like the following excerpt code:

<?php the_excerpt(__('Continue Reading This Entry'));?>

You can of course adjust the wording to fit your personal needs.

If you’d prefer to show an excerpt longer than 55 words, or want to display your pictures and formating, you’ll have to do a little manual work. You currently have two choices:

More Excerpt

  1. Use the More tag – Once you’ve written your post, you can switch over to Code view in your WordPress Write panel, click where you want the excerpt to stop and click the More button.  (See the screenshot above)
  2. Optional Excerpt field – Paste the part of the post you’d like to display as an excerpt in this field of your WordPress Write panel. It should correctly display everything in the excerpt including links and specific formating.

If you use either of these methods, you’ll notice that your feed is only displaying partial posts. If you’d prefer to have the feed display the entire post, but keep the partial post on your actual website, I recommend using the Full Text RSS Feed WordPress plugin to override this and have the feed display the entire post.

Questions?  Let me know in the comments below.

  • Leave a Comment
  • How To: Add Smilies To Your WordPress Blog with Smilies Themer

    Have you ever noticed those cute little smilies that some WordPress bloggers use to show emotions within their posts? Offering these has become quite the trend around the blogosphere.

    As a user of WordPress, there are a few WordPress plugins available for you to easily offer smilies to commentators on your blog. My plugin of choice to accomplish this is the Smilies Themer plugin. Once uploaded and activated, you can then pick a smilies theme to use.

    A variety of people have submitted smilies themes for this plugin, and many come in a variety of colors. My favorite was provided by Nyssa J Brown called the XPressions Emoticon Pack. You can choose from a variety of colors:

    XPressions Emoticon Pack

  • Leave a Comment
  • How To: Blocking Your WordPress Categories and Archives From Google

    We all know that duplicate content can be a problem. People copy your work, re-post it on their website, then you both are penalized for duplicate content! Unfortunately, there isn’t much that can be done about that, but did you know that often blogs have duplicate content within their own blog? The biggest culprit for duplicate internal content is your archives page, which is usually used for categories and monthly archives. Unless you only display partial posts in your archives, you’ll want to make sure Google doesn’t index it. If you aren’t handy with Robots.txt, you can instead use this code to easily tell Google not to index your archive.php page.

    <?php if(is_archive()){ ?><meta name="robots" content="noindex"><?php } ?>

    You’ll want to grab that code and paste it anywhere in the header of your theme above the closing of the head tag. That way, Google will not index these, and search engines won’t refer traffic to your archive pages instead of your single post pages.

  • Leave a Comment
  • How To: Adding An Author Page To Your WordPress Blog

    Due to the small number of WordPress blogs that have multiple authors, very few WordPress themes seem to come with a custom author page. This means whenever someone goes to the author page, WordPress will by default use your archives.php file, or if that isn’t available, then use your index.php file. This generally doesn’t make for a very nice author page because it just displays that authors posts in the same format as your archives.

    In order to create an author page, you will want to make a copy of your archives.php file and name it author.php, then upload it to your site via FTP. Now go into your theme and edit the author.php page you just created. From here, it will vary a little bit depending on your theme, but we basically have to redo the post loop for this page. A typical archive page will call the header, then finish with calling the sidebar and footer. We will be changing the code in between. Here is the code that a standard theme would use between the header and sidebar/footer calls:

    <div id="content" class="narrowcolumn">
    <!-- This sets the $curauth variable -->
    <?php
    if(isset($_GET['author_name'])) :
    $curauth = get_userdatabylogin($author_name);
    else :
    $curauth = get_userdata(intval($author));
    endif;
    ?>
    <h3>About: <?php echo $curauth->display_name; ?></h3>
    <p><strong>Website:</strong> <a href="<?php echo $curauth->user_url; ?>"><?php echo $curauth->user_url; ?></a></p>
    <p><strong>Profile:</strong> <?php echo $curauth->user_description; ?></p>
    <h3>Posts by <?php echo $curauth->display_name; ?>:</h3>
    <ul>
    <!-- The Loop -->
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <li>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>">
    <?php the_title(); ?></a>
    </li>
    <?php endwhile; else: ?>
    <p><?php _e('No posts by this author.'); ?></p>
    <?php endif; ?>
    <!-- End Loop -->
    </ul>
    </div>

    This will display the author’s nickname, their website, and whatever is in the description field, as well as a bulleted list of all their posts. Once set up, you can control everything from within your Users panel of your WordPress dashboard. To see a list of other arguments you can get, I recommend checking out the official WordPress Author template.

    As an added bonus, if you want your authors name link to point towards the authors page, you can do so with the following code:
    <?php the_author_posts_link(); ?>

  • Leave a Comment
  • WordPress Blogroll Code: Separating Your Categories

    I had a reader request for some help with their blogroll recently. The WordPress blogroll has gone through many changes over the past year, and a lot of the WordPress themes authors out there didn’t update their themes with the new code used to call the blogroll.

    The old code still works, but it doesn’t let you take advantage of the new blogroll capabilities.  If you have set up your blogroll with different categories, but noticed that all of them display under a single category, it is probably because your blog’s theme is still using the original code that didn’t allow for much configuration. You’ll probably find something like this:

    <?php get_links()' ?>

    or

    <?php get_links_list()' ?>

    If you want a more configurable code, you will want to use something like the following:

    <?php wp_list_bookmarks('categorize=1&before=<li>&title_before=<h2>&title_after=</h2>&category_before=</n>&category_before=</n>&after=</li>&orderby=url'); ?>

    This code will display your blogroll, but will let you have separate lists for your different blogroll categories. I’ve customized it to display the category title as a Header 2 and use bullet points to display the content, but you can do a variety of things. For more customization options, you’ll want to check out the WordPress List Bookmarks page and adjust the code as needed.

  • Leave a Comment
  • How To: Converting The Author Display To Link To The Author

    If you are setting up a WordPress blog to work with a variety of authors, it is probably a good idea to also set up the author display to actually be a link to the bloggers website.

    For whatever reason, many themes are created to simply display the author’s name using text by default instead of converting it to a link to the author’s website. Fortunately, this is an easy change to make with a minimal amount of coding adjustments required.

    Here is what you need to do. When editing your theme, you’ll want to look for the following code:

    <?php the_author() ?>

    Remove that code and replace it with the following:

    <?php the_author_link(); ?>

    Now test it out! It will automatically display a link to the author’s site, as specified in the users profile.

  • Leave a Comment
  • Code: Adding Recent Comments To Your WordPress Theme

    By default, most WordPress themes display Recent Comments in some form or another. Unfortunately, it isn’t usually very user-friendly, so it will often get removed.

    Until now, most of your other options required the use of a WordPress plugin, but today I ran across a great code snippet you can use to display recent comments in a useful format. I just tested it out on my test site and it looks good. Here is the code you will want to paste into your theme’s sidebar:

    <h2>Recent Comments</h2>
    <?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;?>

  • Leave a Comment
  • How To: Remove Ads From Individual Categories

    Have you ever wondered how exactly you could choose which categories do and which don’t display your advertisements?   Maybe you have a Sponsored Review category and want to make sure that all posts filed in that category don’t display any ads.

    This is something that you as a user of WordPress have the ability to do without to much effort.  What you need to do is paste the following code into your blog around your advertisement code:

    <?php if ( !in_category(10) && !in_category(11) ) { ?>

    This is your existing advertising code.

    <?php } ?>

    Where it says 10 and 11 you will want to place the number assigned to your categories that you want to censor advertisements from. You can repeat where it says ‘&& !in_category(12)’ as needed until you’ve censored all categories.

    Enjoy!

  • Leave a Comment
  • How To: Setting Up Auto-Discovery for Your WordPress Feeds

    Have you ever noticed that many next generation web browsers will often detect a blog’s feed by displaying a feed icon on the right side of the address bar?  This is something many estabalished sites have taken the time to set up to encourage feed subscribers, but something that most WordPress themes don’t do by default.  

    In order to instruct next generation web browsers to automatically detect your WordPress blog’s feed(s), you’ll simply need to do is make a quick modification to your header.php file and add the following code:

    <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="<?php bloginfo('rss2_url'); ?>" />

    <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Comments Feed" href="<?php bloginfo('comments_rss2_url'); ?>" />

    If your theme already has the first code in place for the RSS Feed, then you’ll just need to paste the second set of code in to display your RSS Comments Feed.  You can also swap out the PHP code and instead use your Feedburner feed address if you’d like.

    If you aren’t sure if you should bother to do this or not, never underestimate the power of suggestion.  It is an unobtrusive way to promote your RSS Feed and Comments Feed while not using up any valuable screen real estate.

  • Leave a Comment
  • How To: Avoid Blog Disasters With WordPress Database Backup

    Comments Off on How To: Avoid Blog Disasters With WordPress Database Backup

    Disasters are unavoidable and could happen any day, your server could have a crash one day and you will be left with nothing. Maybe your database will crash and you will lose all your posts. Your blog could be hacked too and someone may just delete all your posts. These are some things that could happen any day to anyone.

    Taking precautions to safe guard your WordPress Blog is one of the best option to stay on top of it. The key to remember is that your database is the backbone of your blog, if you lose it your blog will be bankrupt, having a regular backup is they key to keep your blog up and running at all times.

    WordPress is a platform that has many great developers working for it and providing with numerous amounts of plugins that could help to overcome the unavoidable.

    WordPress Database Backup is a handy and blog saving plugin that will help you take daily backups of your database, you can either run the backup manually or setup cron tasks (scheduled tasks) to send you a backup of your database on a day to day basis.

    The cron tasks have been introduced since WordPress 2.1 and if you do not have the latest version you should upgrade your WordPress installation first.

    Below are some detailed instructions and tips on how to use the WordPress Database Backup plugin to setup cron tasks to automatically send you emails every day so you have the latest copy whenever you require it.

    Step 1

    Download and activate the WordPress Database Plugin for your blog.

    Step 2

    Click on the Manage option in the Admin panel navigation and from there click on the Backup link in the submenu.

    Step 3

    Once you are in the backup page, you will see a lot of options. Scroll down till you see an option to schedule a backup. In the scheduled backup you will see various options to schedule you backup.

    You can schedule a backup varying upon how frequently you post on your blog. The best option is too choose a daily backup of your database. You will also be given an option to choose the database tables you want to backup. By default all core WordPress tables are backed up.

    While making a choice to backup other tables you should only choose those that are critical to running of your blog, if you choose all the tables there are chances that the script may fail due to reading huge data.

    If you want to backup all the tables the best option is to run the task manually and only email critical data to you every day.

    That’s it with three simple steps you can save your blog from liquidation and always be sure that you are one step ahead of failures. You just have to follow the steps once and then you can ensure that you have a plan against disaster.

  • Leave a Comment