Adding RSS Feed from Another WordPress Website

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>

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Article

Anchor link to Oxygen Builder Tabs
JS code to create anchor link for Tabs component of Oxygen Builder
Change Video Playing Speed with Javascript
If you want to play html tag "video" slower 80%, you can use this code:
Accordion
Accordion code snippet
COMPLETE PACKAGE OF WEBSITE DESIGN & DEVELOPMENT
Digitalizer offers website design & development services for company profiles, online shops, event organizers, educational institutions or other fields. You don't need to think about domains, web hosting / servers, DNS, email, design, development, security and other technical issues. Just prepare your website content, we do the rest.
All website design & development packages include 1 year maintenance!
Free Consultation
Back to top
cross