View Full Version : Problems with excerpts on WP blog site

03-26-2010, 03:30 PM
Hi Guys,

I've got a slight problem with excerpts on a theme I've been trying to sort out on my website.

What it is , the home page is made up of numerous blocks showing excerpts from various articles. These exceprts are 100 characters in length, but are returned for display on the home page as plain text, when in fact the first sentence of each article is using a H3 heading tag.

<div class="limit">

<?php the_content_limit('100'); ?>


The code above is what I think is returning the 100 character excerpt, but what I want to try to do is get the first sentence only as H3 & not the full 100 characters.

If anyone can shed some light or at least point me in the right direction, I would be most grateful.

Thanks Taffy

03-26-2010, 04:02 PM
Without seeing the whole script that you have, it's going to be hard
to say how it's actually displaying the first 100.

But below is a little test you can try that will pick-out text between
two HTML tags ... in your case <h3> and </h3>. You can't just stick
it into your WP script ... but maybe if you find where their functions are,
you can do something with the parts that pertain to the first 100 characters.


$string="This is a test for <h3>Text in the Header</h3> function to extract text.";

echo ExtractString($string,"<h3>","</h3>");

function ExtractString($str, $start, $end){
$str_low = strtolower($str);
$pos_start = strpos($str_low, $start);
$pos_end = strpos($str_low, $end, ($pos_start + strlen($start)));
if ( ($pos_start !== false) && ($pos_end !== false) ){
$pos1 = $pos_start + strlen($start);
$pos2 = $pos_end - $pos1;
return substr($str, $pos1, $pos2);


The output of the test script is: Text in the Header


03-26-2010, 06:59 PM
Hi thanks for trying to help me out, I did take a look at the place where the code is, but I just can't seem to make any progress on this at all. I don't know, but looking at the code below, I just thought if "limit" was/is a variable of set length containing different characters, then how would I use the code you posted in order to query that variable and return what is inside the h3 tags..? Sorry but my knowledge of php is terrible :(

This is the entire block of code that deals with an area of the page called featured right. Hope it makes more sense to you than it does to me !

<div id="featuredright">
<?php $recent = new WP_Query("cat=".get_theme_mod('featuredcat')."&offset=1&showposts=4"); while($recent->have_posts()) : $recent->the_post();?>
<div id="featuredpost">
<div class="thumb">
<?php tj_thumbnail('featuredrightthumbw', 'featuredrightthumbh'); ?>
<!--end: thumb-->
<h2><a href="<?php the_permalink(); ?>" rel="bookmark">
<?php the_title(); ?>
<div class="byline">
<?php the_author_posts_link(); ?>
<?php the_time('M jS, Y') ?>
<div class="limit">

<?php the_content_limit(100); ?>

<!--end: limit-->
<div class="clear"></div>
<!--end: featuredpost-->
<?php endwhile; ?>
<!--end: featuredright-->

You will notice there is a H2 tag used also, but this is the actual url of the article & therefore not really what I want.

Regards Taffy

03-26-2010, 07:05 PM
Can you post a link to your test page so we can see the actual output being generated?

03-27-2010, 06:05 AM
Hi guys, sorry I didn't think I should post a link to my site in case it was seen as spamming ?

Anyway the link is: Philippines-Virtual-Guide (http://www.philippines-virtual-guide.com)

As I said earlier, you will notice the main headings throughout the page are using a H2 tag, but these are basically hyperlinks to each article.
What I want to try to do is make the first sentence (in black) to show as H3
text as it was meant to do. I can then style just the H3 text instead of styling the whole 100 characters which is currently my only option!

I don't know if this is relevant, but I was browsing through the code files last night & came across an entry in theme functions.php which was "strip_tags"..? Now not knowing a great deal about php, I could be wrong, but I think maybe this is why I have been unable to style the H3 in the excerpt..? If this is the case, would it not be easy in the long run to just insert an exception to this strip_tags and allow the H3..?

# Limit Post
function the_content_limit($max_char, $more_link_text = '', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]&gt;', $content);
$content = strip_tags($content);

if (strlen($_GET['p']) > 0) {
echo "";
echo $content;
echo "&nbsp;<a href='";
echo "'>"."Read More &rarr;</a>";
echo "";
else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
$content = substr($content, 0, $espacio);
$content = $content;
echo "";
echo $content;
echo "...";
echo "&nbsp;<a href='";
echo "'>"."</a>";
echo "";
else {
echo "";
echo $content;
echo "&nbsp;<a href='";
echo "'>"."Read More &rarr;</a>";
echo "";

Thanks again guys