Custom Shortcode Functions to List Category Posts with Post Thumbnail
-
I have used a function code snippet I found somewhere to create a list of posts from a specific category displayed in a specific order together with the featured images (post thumbnails).
Currently having difficulty trying to get the featured images to render correctly and the page’s feature image is also being affected despite the inclusion of an additional
<div></div>
around the custom shortcode.The provided link is to the sandbox page and the way that I am tying to get it to look is on the “Start Here” page linked in the top menu bar of my site.
Any ideas on why it is not quite there yet?
Many thanks in advance. <3
function FAQposts() { $args = array( 'posts_per_page' => 100, 'category_name' => 'FAQ', 'order' => 'ASC', 'orderby' => 'link' ); $last_100_posts_query = new WP_Query( $args ); while($last_100_posts_query->have_posts()) : $last_100_posts_query->the_post(); $link = get_permalink(); $title = get_the_title(); $date = get_the_date(); if ( has_post_thumbnail() ) { set_post_thumbnail_size( 250, 104 ); $featured_image = get_the_post_thumbnail( array( 'class' => 'alignleft' ) ); } $content .= '<div class="latest-posts">'; $content .= '<h3><br/><a href='.$link.' target="_top">'.$title.' </a></h3>'; $content .= '<h7>Posted: '.$date.' </h7>'; $content .= '<p class="excerpt">'.$featured_image.' '.get_the_excerpt(). '</p>'; $content .= '</div>'; endwhile; return $content; } add_shortcode('FAQposts', 'FAQposts' );
- This topic was modified 3 years, 4 months ago by .
- This topic was modified 3 years, 4 months ago by .
- This topic was modified 3 years, 4 months ago by .
- This topic was modified 3 years, 4 months ago by .
The page I need help with: [log in to see the link]
- The topic ‘Custom Shortcode Functions to List Category Posts with Post Thumbnail’ is closed to new replies.