I have a news page on a site I’ve built, and I made two shortcodes to insert the news items. This had worked when I first built it, but I just noticed that one shortcode (the columns of headlines on the bottom) appears in the correct place, but the other (latest news item) now appears outside of where the content area element is. I tried changing that element to a raw content element but got the same results. The page is here:
https://lifelearningacademysf.org/news
I didn’t change anything on my end that I know of, so I don’t know what the first news item is appearing outside of where it should be.
Here’s the shortcode code:
function latestNews() {
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'category_name' => 'news',
'posts_per_page' => 1,
);
$arr_posts = new WP_Query( $args );
if ( $arr_posts->have_posts() ) :
while ( $arr_posts->have_posts() ) :
$arr_posts->the_post();
?>
<div class="firstnewsitem">
<a href="<?php the_field('newsurl'); ?>" target="_blank">
<img src="<?php the_field('mainimage'); ?>" style="width: 100%;">
<h3><?php the_time( 'F j, Y' ); ?></h3>
<h2><?php the_title(); ?></h2></a>
<?php if( get_field('subhead') ): ?>
<p><?php the_field('subhead'); ?></p>
<?php endif; ?>
</div>
<?php
endwhile;
endif;
wp_reset_query();
}
add_shortcode('latestnews', 'latestNews');
I’ll upload login info in the secure note. Thanks for your help.