Berita

<?php
/**
 * Template Name: Simple Aggregator
 *
 * Simple Agregator
 * Contributor: Dedhy kurniawan.net
 * Last Update: 2013/16/05
 */
/**
 * Parameter, feed url, maximum items per feed
 */
 // Feed urls, alamat feed yang akan digrab
$feed_urls = array(
            'http://www.sajianku.com/feed',
            'http://www.seksehat.info/feed'
            );
// banyaknya item yg ingin ditampilkan
$max_items = 5;
/**
 * Fungsi untuk membatasi deskripsi postingan
 */
function shorten($string, $length)
{
    $suffix = '...';
    $short_desc = trim(str_replace(array("r","n", "t"), ' ', strip_tags($string)));
    $desc = trim(substr($short_desc, 0, $length));
    $lastchar = substr($desc, -1, 1);
    if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?') $suffix='';
    $desc .= $suffix;
    return $desc;
}
/**
 * Fungsi untuk mengambil feed
 */
function getME_my_feed($feed_url, $maxitems='') {
    $rss = fetch_feed($feed_url);
    if ( '' == $maxitems) {
        $maxitems = $rss->get_item_quantity(1); // 1 = banyaknya postingan yang ingin di tampilkan
    }
    $rss_items = $rss->get_items(0, $maxitems);
    ksort($rss_items);
    $htmldata = '<ul>';
    if ($maxitems == 0) {
        $htmldata .= '<li>No items found.</li>';
    } else {
        foreach ( $rss_items as $item ) {
        $feed = $item->get_feed();
        $htmldata .= '<li style="text-align: justify;">
            <strong>' .$item->get_date('j M Y'). ' : </strong><a rel="nofollow" href="' .$item->get_permalink(). '" title="' .$item->get_title(). '" target="_blank">' .$item->get_title(). '</a> | <a rel="nofollow" href="' .$feed->get_permalink(). '" title="' .$feed->get_title(). '" target="_blank">' .$feed->get_title(). '</a>';
        $htmldata .= '<p>' .shorten($item->get_description(), 200). '</p>';
        $htmldata .= '</li>';
        }
    }
    $htmldata .= '</ul>';
    return $htmldata;
}
?>
<!-- Start header block -->
<?php get_header(); ?>
        <div id="container">
            <div id="content" role="main">
                <article class="post-content">
<!-- End header block -->
<?php
/**
 * Disini kita akan menampilkan Feed nya sbg postingan/page, dari feed url yg telah didefinisikan di $feed_urls
 */
foreach ($feed_urls as $feed_url) {
    echo '<h3>Latest News from '. $feed_url . '</h3>';
    echo getME_my_feed($feed_url, $max_items);
}
?>
<!-- Start footer block -->
                </article>
            </div><!--content-->
            <?php get_sidebar(); ?>
            <div class="clearfix"></div>
        </div><!--container-->
<?php get_footer(); ?>
<!-- End footer block -->

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s