WordPress Customized Feature Post

I was first intrigued by the Word­Press theme Squible to have one fea­tured post on the front page with links to pre­vi­ous posts. I liked the imple­me­na­tion, and Mr. Par­lin did a good job work­ing with an exist­ing plu­gin. After chang­ing themes on my main blog I decided that I wanted to imple­ment that same look and feel. Let’s go through a tutorial.

The Nec­es­sary Components

First, you need to go and grab the Limit Posts plu­gin (if you need help con­sult the Codex). Once we have the plu­gin installed we are now ready to move into edit­ing the plugin/theme.

Edit­ing the Plugin

Let’s say that I want to limit the fea­tured post pre­view to 450 char­ac­ters, but let’s add onto that fact that this excerpt is ital­i­cized in your main post. What this does is then bring that unclosed tag onto the main page so some of your front page con­tent is now ital­i­cized. How can we pre­vent this? We need the strip­tags() PHP func­tion.

Then open up the plu­gin in an edi­tor (sug­gest CHMOD on the plu­gin and edit­ing it inside Word­press), and look for the fol­low­ing line:

$content = str_replace(']]>', ']]>', $content);

Under this line we are going to strip the HTML tags from the $con­tent vari­able. Add the fol­low­ing line:

$content = strip_tags($content);

Edit Index Page

The fol­low­ing instruc­tions come from the Limit Posts page:

Go into your index.php file and change the func­tion the_content() with the_content_limit($max_characters, $link_text) where:
$max_characters: max­i­mum amount of char­ac­ters shown for an entry in the main page (index.php)
$link_text: text that is used to gen­er­ate the link to the whole article.

I use the fol­low­ing in my theme:

Excep­tions

Say you would like for anchor tags to be allowed but not other HTML; the PHP func­tion can accept an argu­ment to allow code. Here is code to allow anchor tags:

$content = strip_tags($content, '

No Comments

Got Something to Say?

(Required)
(Required)