• Hi,

    I fancy getting a snippet of 90 characters from the most recent news item and displaying it on my home page.

    Can someone show me the way to do this in WP?

    Many thanks!

Viewing 14 replies - 1 through 14 (of 14 total)
  • You can use multiple loops.

    Something like:

    <?php query_posts('showposts=1'); ?>
    
     <?php while (have_posts()) : the_post(); ?>
        the_excerpt();
     <?php endwhile;?>
    Thread Starter michaelmcguk

    (@michaelmcguk)

    And would this keep it to roughly 90 characters?

    Or would it be like the_excerpt(90) ??

    The function you want is the_content_rss(). It lets you specify a character limit.

    Thread Starter michaelmcguk

    (@michaelmcguk)

    Brilliant, thanks again Ivovic, comin to the rescue ??

    I knew there had to be a reason I wore my underwear on the outside ??

    LOL

    Thread Starter michaelmcguk

    (@michaelmcguk)

    Hehehe, plus the brass band starting up just as you flew by was a dead give away! ??

    OK, RSS Feed is working great, but when I try this in my index.php page it doesn’t work

    <?php the_content_rss('', TRUE, '', 90); ?>

    Any ideas?

    yeah, you need to put it into a loop, as described by wp_guy above…

    take what he gave you, and just substitute the rss line, where he puts the_excerpt

    we’re actually more of a dynamic duo.

    Thread Starter michaelmcguk

    (@michaelmcguk)

    Hehe and I’m the damsel in distress. But wearing Bapesta’s and my arms don’t “flail” nearly as much ??

    Have you got a name yet?

    Oh and almost there: <?php query_posts('showposts=1'); ?><?php while (have_posts()) : the_post(); ?><?php the_content_rss('', TRUE, '', 90); ?><?php endwhile;?> except it displays the full post and doesn’t chop up the string at 90 characters ?? Any takers?

    ahh, that’s my mistake actually… the_content_rss limits the number of WORDS not the number of CHARACTERS… oops.

    I guess that’s better actually but you might want to lower the number dramatically for desired effect.

    sorry about your kitty m’am, sometimes I don’t know my own strength ??

    as for a name, I think given mistakes like this, it’s better we remain mysterious than to risk getting sued.

    Thread Starter michaelmcguk

    (@michaelmcguk)

    Hahaha ??

    Here have a nickel.

    Watch out! Here comes Marvel, they wanna make a movie. Run!

    *makes a wooshing sound and leaves wp_guy to smile for the cameras*

    Thread Starter michaelmcguk

    (@michaelmcguk)

    ??

    :^)

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Substr function’ is closed to new replies.