Site logo

Archived topic

generate_before_entry_title not working in WP Query loop

6 replies · Started by Germaine on January 18, 2021

Viewing posts 1–7 of 7

Hi guys,

When I'm trying to loop through posts on the homepage with code in a custom template, and for each post use a template part that contains code very similar to the 'content-single.php' file, generate_before_entry_title and other do_action's are not working, and therefore not showing post categories, date and Read more buttons.

What am I doing wrong? I've tried setting up postdata but that doesn't help.

Thanks

Here's the foreach -

<?php $latest_news = get_posts(array(
'post_type' => 'post',
'posts_per_page' => '3',
)); ?>

<section class="latest-news grid-container grid-parent">
<div class="latest-news-grid three-column-grid">

<?php foreach($latest_news as $post): setup_postdata($post); ?>
<?php get_template_part( 'news', 'card'); ?>
<?php endforeach; wp_reset_postdata(); ?>
</div>
</section>

And this is what is in the news-card template part -


<article id="post-<?php the_ID(); ?>" <?php post_class('grey-border'); ?> <?php generate_do_microdata( 'article' ); ?>>
	<div class="inside-article padding-20">

	<header class="entry-header">
		<?php do_action( 'generate_before_entry_title'); ?>
			<?php $params = generate_get_the_title_parameters();
			the_title( $params['before'], $params['after'] ); ?>
		<?php do_action( 'generate_after_entry_title' ); ?>
	</header>

	<?php do_action( 'generate_after_entry_header' );
	$itemprop = '';
		if ( 'microdata' === generate_get_schema_type() ) {
		$itemprop = ' itemprop="text"';
		}
	?>
	<?php do_action( 'generate_after_entry_content' );
	do_action( 'generate_after_content' ); ?>
		
	</div>
</article>

The news card template part is working in the loop on index.php but doesn't show the post date, category, or read more on my custom homepage template.

Sorry I had the wrong news-card code but have updated the above post

Hi Tom,

This isn't a custom post type, just the standard WordPress posts. The entry and footer meta isn't appearing on the homepage when I use the template part.

Does this display anything?:

add_action( 'generate_before_entry_title', function() {
    echo 'hello';
} );
This archived topic is closed to new replies.