- This topic has 6 replies, 3 voices, and was last updated 1 year, 6 months ago by
Tom.
-
AuthorPosts
-
January 18, 2021 at 4:55 pm #1624310
Germaine
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
January 18, 2021 at 5:14 pm #1624320Elvin
StaffCustomer SupportHi,
Can you share us the code you’re using?
generate_before_entry_title
doesn’t do anything by itself, it’s a hook location.The one in charge of generating meta is function is found in generatepress/inc/structure/.
The
post-meta.php
file. Seegenerate_post_meta
function.
https://github.com/tomusborne/generatepress/blob/master/inc/structure/post-meta.phpA wise man once said:
"Have you cleared your cache?"January 18, 2021 at 7:25 pm #1624379Germaine
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.
January 18, 2021 at 8:01 pm #1624395Germaine
Sorry I had the wrong news-card code but have updated the above post
January 19, 2021 at 9:13 am #1625260Tom
Lead DeveloperLead DeveloperHi there,
Just to confirm, is this a custom post type where you’ve set up a custom file structure, and now things like post meta etc.. aren’t being displayed?
If so, these filters may help:
https://docs.generatepress.com/article/generate_entry_meta_post_types/
https://docs.generatepress.com/article/generate-footer-meta-post-types/Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentJanuary 25, 2021 at 11:28 pm #1633707Germaine
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.
January 26, 2021 at 9:50 am #1634560Tom
Lead DeveloperLead DeveloperDoes this display anything?:
add_action( 'generate_before_entry_title', function() { echo 'hello'; } );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.