Menambahkan RSS Feed dari Website WordPress Lain

Kode PHP untuk menampilkan RSS Feed dari situs WordPress lainnya.
Share:
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...
<?php // Get RSS Feed(s)
include_once( ABSPATH . WPINC . '/feed.php' );
  
// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed( 'https://your_url_rss_feed' );
  
if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly
  
    // Figure out how many total items there are, but limit it to 5. 
    $maxitems = $rss->get_item_quantity( 3 ); 
  
    // Build an array of all the items, starting with element 0 (first element).
    $rss_items = $rss->get_items( 0, $maxitems );
  
endif;
?>
 <div class="newsletter_grid">
    <?php if ( $maxitems == 0 ) : ?>
        <div><?php _e( 'No items', 'my-text-domain' ); ?></div>
    <?php else : ?>
        <?php // Loop through each feed item and display each item as a hyperlink. ?>
        <?php foreach ( $rss_items as $item ) : ?>
            <div class="newsletter_item">
              <div class="newsletter_title">
                <a target="_blank" href="<?php echo esc_url( $item->get_permalink() ); ?>"
                    title="<?php printf( __( 'Posted %s', 'my-text-domain' ), $item->get_date('j F Y | g:i a') ); ?>">
                    <?php
                  $title = $item->get_title();
                  $limited_title = substr($title, 0, 70);;
                    ?>
                  <h3><?php echo $limited_title; ?></h3>
                </a>
              </div>           
              
            	<div class="newsletter_excerpt">
                  <?php 
                      $description = $item->get_description(); // Get the description
                      $limited_description = wp_trim_words( $description, 20 ); // Limit to 20 words
                      echo $limited_description; 
                  ?>
           		</div>
                    
                <div class="newsletter_date">
                  <?php 
                      //echo esc_html( $item->get_date('j F Y') ); 
                      echo date_i18n( 'j. F Y', false, false);    
                  ?>
            	</div>

  				<a target="_blank" class="newsletter_link" href="<?php echo esc_url( $item->get_permalink() ); ?>">Weiterlesen</a>
            </div>
        <?php endforeach; ?>
    <?php endif; ?>
</div>

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

Artikel Terkait

Javascript Merubah Kecepatan Putar Video
Jika anda ingin memperlambat pemutaran video dengan tag HTML "video", bisa menggunakan kode seperti dibawah ini:
Akordion
Kode HTML, CSS dan JS untuk membuat efek akordion
Modifikasi Tampilan Fluent Form
PAKET LENGKAP PEMBUATAN WEBSITE
Digitalizer menawarkan jasa pembuatan website untuk company profile, toko online, event organizer, lembaga pendidikan ataupun bidang lainnya. Anda tidak perlu memikirkan tentang domain, webhosting/server, DNS, email, desain, development, security serta masalah teknis lainnya. Cukup siapkan content website anda saja, sisanya kami yang mengerjakannya.
Semua paket pembuatan website sudah termasuk maintenance 1 tahun!
HOT LINK!
Kembali ke atas
cross