WordPress.org

Ready to get started?Download WordPress

Forums

Truncating imported RSS Feeds. (7 posts)

  1. John Robertson
    Member
    Posted 4 years ago #

    Hey guys, Im pulling an RSS feed from my forum to display on my homepage. It displays the titles correctly, but I want to truncate the number of characters per post so it doenst take up a long section if the title is long. How do I do that? here is the code Im using

    <?php // Get RSS Feed(s)
    include_once(ABSPATH . WPINC . '/feed.php');
    
    $rss = fetch_feed('http://examplesite.com/rss');
    if (!is_wp_error( $rss ) ) :
    
        $maxitems = $rss->get_item_quantity(5); 
    
        $rss_items = $rss->get_items(0, $maxitems);
    endif;
    ?>
    
    <ul>
        <?php if ($maxitems == 0) echo '<li>No items.</li>';
        else
    
        foreach ( $rss_items as $item ) : ?>
        <li>
            <a href='<?php echo $item->get_permalink(); ?>'
            title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
            <?php echo $item->get_title(); ?></a>
        </li>
        <?php endforeach; ?>
    </ul>
  2. John Robertson
    Member
    Posted 4 years ago #

    anyone?

  3. John Robertson
    Member
    Posted 4 years ago #

    anyone?

  4. cruxwireweb
    Member
    Posted 3 years ago #

    anyone? I need this answer too.

  5. dome90uk
    Member
    Posted 3 years ago #

    SOLVED - Found this ... worked on 3.1

    Also, you can truncate the number of characters that appear in the content of each feed item by using PHP’s substr() function:

    <?php echo substr($item->get_description(), 0, 180); ?>

    REF - import and display rss feeds in wordpress

    Also, limiting the number of words shown in the_content / the_excerpt

  6. dsided
    Member
    Posted 3 years ago #

    Thank you very much!

  7. cruxwireweb
    Member
    Posted 3 years ago #

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.