What is currently there:
<!–?php global $post; $myposts = get_posts(‘numberposts=1&category=1’); foreach($myposts as $post) : ?–>
<!–?php the_title(); ?–>
<!–?php the_content(); ?–>
<!–?php endforeach; ?–>
Thank you.
]]>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’ );
$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!
I wonder if anyone could help me? One of the footers on all my pages has mysteriously aligned itself randomly in its area, as opposed to being neatly on the right. I don’t think this looks good and would like to change it. A website designer created the site for me but left it like this, which I think is poor. Is there a way to get the ‘Recent Blog Posts’ footer nicely right aligned?
https://www.jackiegriffithsauthor.com/
]]>Here is the code block on my home.php which I think needs a bit refinement.
<!-- <h3><?php $featcat = cat_id_to_name(get_theme_mod('featured_top_left')); echo $featcat; ?></h3> -->
<?php $recent = new WP_Query("cat=".get_theme_mod('featured_top_left')."&showposts=".get_theme_mod('featured_top_left_num')); while($recent->have_posts()) : $recent->the_post();?>
<?php if( get_post_meta($post->ID, "thumb", true) ): ?>
<a href="<?php the_permalink() ?>" rel="bookmark"><img class="thumb" src="<?php bloginfo('template_directory'); ?>/tools/timthumb.php?src=<?php echo get_post_meta($post->ID, "thumb", $single = true); ?>&h=<?php echo get_theme_mod('featured_top_left_thumb_height'); ?>&w=<?php echo get_theme_mod('featured_top_left_thumb_width'); ?>&zc=1" alt="<?php the_title(); ?>" /></a>
<?php else: ?>
<?php endif; ?>
]]>Take a look at this site I am working on. You will see that the recent blog posts are “over running” the box”. I have uploaded another zip file of this template (fromm a differnet source)thinking that there must have been a file discrepancy, but it hasn’t fixed it.
It’s supposed to look like this.
Can anyone help me get this straightened out?
Muchas gracias,
Maxine
]]>