Creating a shortcode to show rss from any site with scrolling effect

hi guys,
The following codes will add a shortcode to your wp, with which you can add any sites RSS feed content(only the title) to your site with wp’s fetch_rss function and add a news ticker style scrolling effect to it.

function readRss($atts) {
extract(shortcode_atts(array(
"feed" => 'http://',
"numsc" => 1,
"numps" => 1
), $atts));
$asfjQ ='<script type="text/javascript">// <!&#91;CDATA&#91;
jQuery(document).ready(function($) { $(".asf-olabbd").vTicker({ showItems: '.$numsc.' } ); });
// &#93;&#93;></script>';
// return fetch_feed($feed);
include_once( ABSPATH . WPINC . '/feed.php' );
$rss = fetch_feed($feed);
$max_items= $num;
$maxitems = 0;
if ( ! is_wp_error( $rss ) ) :
$maxitems = $rss->get_item_quantity( $numps );
$rss_items = $rss->get_items( 0, $maxitems );
endif;
$feed_asf = '';
if ( $maxitems == 0 ){
return '</p>
<ul>
<li>'._e( "No items", "asf-olabbd" ).'</li>
</ul>
';
}
else{
$feed_asf = '</p>
<div class="asf-olabbd">
<ul>
<ul>';</ul>
</ul>
<ul>
<ul>foreach ( $rss_items as $item ) :</ul>
</ul>
<ul>
<ul>$feed_asf .= '</p>
<li>';
$feed_asf .= '<a title="'.esc_html( $item->get_title() ).'" href="'.esc_url( $item->get_permalink() ).'" target="_blank">';
$feed_asf .= esc_html( $item->get_title() );
$feed_asf .= '</a>';
$feed_asf .= '</li>
</ul>
</ul>
';
endforeach;
$feed_asf .= '</p>
</div>
';
$feed_asf .= $asfjQ;
// return $feed_asf;
return $feed_asf;
}
}
add_shortcode('rss', 'readRss');
function add_vticker(){
wp_enqueue_script( 'asf-olabbd-vticker', get_stylesheet_directory_uri() . '/js/jquery.vticker.min.js', array(), '1.0.0', true );
}
add_action('wp_enqueue_scripts','add_vticker');

I am planning on creating a plugin with this code so will explain it when time comes. cheers.
BTW this code is free to use by anybody and the ticker jQuery script is written by Tadas Juozapaitis

Leave a Reply