- This topic has 13 replies, 3 voices, and was last updated 1 year, 1 month ago by
Tom.
-
AuthorPosts
-
December 14, 2019 at 1:55 pm #1104523
Artem
Hi,
I’m trying to get the following layout for a single post:Post Title
Author | Date | Category
Featured image
ContentI show Featured Image via Header Element.
The Post Title I show via Hook Element using this PHP<?php the_title( '<h1>', '</h1>' ); ?>
Would you be so kind to explain what PHP code should I add to my Hook Element in order to show inline:
Author | Date | CategoryI tried:
<?php the_category( ' ' ); ?>
– It shows the category.
However
<?php the_date( 'Y-m-d', '<h2>', '</h2>' ); ?>
or
<?php the_author(); ?>
don’t show anything.Thanks a lot.
December 14, 2019 at 5:24 pm #1104584Leo
StaffCustomer SupportHi there,
Don’t think we need to use the hook for this.
Can you try this filter first?
https://docs.generatepress.com/article/generate_header_entry_meta_items/The function should be:
add_filter( 'generate_header_entry_meta_items', function() { return array( 'author', 'date', 'categories', ); } );
Adding PHP: https://docs.generatepress.com/article/adding-php/
Let me know ๐
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/December 15, 2019 at 10:05 am #1105133Artem
Thanks, Leo.
This filter works fine by putting all the meta in one line.
However:
1 – with this filter, I still have the category displayed (duplicated) at the end of a single post.
2 – another issue is that with this filter I can’t have my featured image full width, with my content “contained”. That’s why I was thinking about the hook. In fact, I took this idea from the Merch site in your site library.
3 – how can I have separator like this | between different meta: Author | Date | Category?
4 – one more question. What is the preferable way of tweaking the GeneratePress style/layout: code snippets or hooks? I was thinking that it’s preferable to use hooks (whenever possible) instead of using third-party plugins.Thank you.
December 15, 2019 at 11:16 am #1105168Leo
StaffCustomer Support1. You would need a second filter:
https://docs.generatepress.com/article/generate_footer_entry_meta_items/2. So you’d like to duplicate the single post layout from Merch?
If so this page explains it in details:
https://docs.generatepress.com/article/generate_footer_entry_meta_items/3. Let’s solve 1/2 first.
4. That depends on what you are trying to add. If it can be done with hooks then definitely use the hook element module. But if it’s a filter or custom function then Code Snippets or a child theme is needed:
https://docs.generatepress.com/article/adding-php/Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/December 15, 2019 at 12:59 pm #1105207Artem
Thank you, Leo.
Definitely, I didn’t explain clearly what I need. Sorry about that. I’ll try once again.
1 – I needed to remove category at the end of a single post as I have it already at the beginning of the post just below the Title.
I found the filter on your forum and it wors fine:add_filter( 'generate_footer_entry_meta_items', function( $items ) { return array_diff( $items, [ 'categories' ] ); } );
2 – Yes, I try to do the single post layout similar (but not identical) to Merch.
Something like this: http://prnt.sc/qb8gg3
I need my title and meta above the featured image (full width) and my single post content width – 700px. So, what’s the best way to do this? How to adjust the width of the featured image independently of the content width?
Thanks.December 15, 2019 at 3:28 pm #1105269Leo
StaffCustomer SupportSo, whatโs the best way to do this? How to adjust the width of the featured image independently of the content width?
This isn’t very easy as the featured image is inside the content container with the same width.
The workaround is to set the single post container layout to be the wider/featured image width with a layout element:
https://docs.generatepress.com/article/layout-element-overview/#content-1Then wrap your single post content in like this:
<div class="single-post-content-container"> post content </div>
Then target it with CSS;
.single-post-content-container { max-width: 700px; margin-left: auto; margin-right: auto; }
I also linked you to the wrong page in the previous reply. David explained the single post layout for Merch as well:
https://gpsites.co/merch/the-single-post/Let me know if this helps at all ๐
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/December 17, 2019 at 1:28 pm #1107214Artem
Thanks for the reply, Leo.
Anyway, I still don’t understand why these two functions:<?php the_title( ); ?>
and<?php the_category( ); ?>
work inside the Hook, and these two<?php the_date( ); ?>
or<?php the_author(); ?>
don’t work.
I still need to show the post author and the post date inside the hook. Which function should I use?
Thank you.December 17, 2019 at 6:13 pm #1107362Tom
Lead DeveloperLead DeveloperHi there,
You could try these functions:
<?php generate_do_post_meta_item( 'date' ); ?> <?php generate_do_post_meta_item( 'author' ); ?>
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentDecember 18, 2019 at 3:58 am #1107607Artem
Thank you, Tom.
The function for the date<?php generate_do_post_meta_item( 'date' ); ?>
works fine. However, the function for the author<?php generate_do_post_meta_item( 'author' ); ?>
gives me just “by”. No author name displayed.December 18, 2019 at 12:19 pm #1108161Tom
Lead DeveloperLead DeveloperWhat hook are you adding it to?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentDecember 18, 2019 at 1:24 pm #1108218Artem
Hook after_header
Execute PHP – on
Priority – 5
Display on all postsDecember 18, 2019 at 6:05 pm #1108352Tom
Lead DeveloperLead DeveloperAh, since it’s outside the loop, you need to specify the author ID.
For example, this is the code we use in the Header Element:
<?php global $post; $author_id = $post->post_author; $author = sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author"><a class="url fn n" href="%1$s" title="%2$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%3$s</span></a></span>', esc_url( get_author_posts_url( $author_id ) ), esc_attr( sprintf( __( 'View all posts by %s', 'gp-premium' ), get_the_author_meta( 'display_name', $author_id ) ) ), esc_html( get_the_author_meta( 'display_name', $author_id ) ) ); echo $author; ?>
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentDecember 18, 2019 at 11:34 pm #1108485Artem
Great. This works fine.
Many thanks.December 19, 2019 at 9:50 am #1109004Tom
Lead DeveloperLead DeveloperYou’re welcome ๐
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.