• We moved our blog to a separate install https://blog.empow.me and kept the main website at the root domain https://empow.me This is not a multi-site install.

    On the bottom of main page there are our “recent posts”. I found that the only way to do this on 2 separate sites is to use a news reader. Most of the plugins do not include images or require a fee for the plugin so I am attempting this on my own. I have made great progress but now need help to shorten things up.

    The code I used in functions.php to include the image in the news feed is:
    /*********************************************************************
    *Add featured images to RSS feed output. To change image size replace ‘medium’ with different size.
    *
    */
    function featuredtoRSS($content) {
    global $post;
    if ( has_post_thumbnail( $post->ID ) ){
    $content = ‘<div>’ . get_the_post_thumbnail( $post->ID, ‘medium’, array( ‘style’ => ‘margin-bottom: 15px;’ ) ) . ‘</div>’ . $content;
    }
    return $content;
    }
    add_filter(‘the_excerpt_rss’, ‘featuredtoRSS’);
    add_filter(‘the_content_feed’, ‘featuredtoRSS’);

    Which works great but then I found a code that parsed the image separate from the description:
    add_action(‘rss2_item’, function(){
    global $post;
    $output = ”;
    $thumbnail_ID = get_post_thumbnail_id( $post->ID );
    $thumbnail = wp_get_attachment_image_src($thumbnail_ID, ‘thumbnail’);
    $output .= ‘<postimage>’;
    $output .= ‘<url>’. $thumbnail[0] .'</url>’;
    $output .= ‘<width>’. $thumbnail[1] .'</width>’;
    $output .= ‘<height>’. $thumbnail[2] .'</height>’;
    $output .= ‘</postimage>’;
    echo $output;

    });
    Which works as well but I can’t figure out how to call it in the feed reader. I also only want a short “excerpt”, which is what this supposedly is but it’s still too long and I don’t want the “appeared first on…” included either.

    Can someone give me a helping hand with this?

    Here is the feed reader code I am currently using:
    <?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://blog.empow.me/topics/News/feed&#8217; );

    $maxitems = 0;

    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( 4 );

    // Build an array of all the items, starting with element 0 (first element).
    $rss_items = $rss->get_items( 0, $maxitems );
    endif;
    ?>
    <?php if ( $maxitems == 0 ) : ?>
    <?php _e( ‘No items’, ‘my-text-domain’ ); ?>
    <?php else : ?>
    <?php // Loop through each feed item and display each item as a hyperlink. ?>
    <?php foreach ( $rss_items as $item ) : ?>
    <div class=”empowblog-block”>
    get_permalink() ); ?>”
    title=”<?php printf( __( ‘Posted %s’, ‘my-text-domain’ ), $item->get_date(‘j F Y | g:i a’) ); ?>”>
    <?php echo esc_html( $item->get_title() ); ?>

    <p><?php echo $item->get_description(); ?></p>
    </div>
    <?php endforeach; ?>
    <?php endif; ?>

    p.s. I am using “php code” plugin to insert the code – so far it is working great as well!

    Just need a little coding help here if you don’t mind.
    Thank You!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘News feed help desperately needed’ is closed to new replies.