Site logo

Archived topic

Latest author-Avatar + Meta + Categories on: Archives, Posts, Pages method?

11 replies · Started by Morgan on March 23, 2021

Viewing posts 1–12 of 12

I haven’t been able to get an authors avatar to appear on posts with 2 different snippets I’ve used (maybe conflict with Ethos post header element?)

Can you pls advise?

Latest snippet I've tried:

add_filter( 'generate_post_author_output', 'tu_add_author_gravatar' );
function tu_add_author_gravatar() {
	printf( ' <span class="byline">%1$s</span>',
		sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s %5$s<a href="%2$s" title="%3$s" rel="author"><span class="author-name" itemprop="name">%4$s</span></a></span>',
			__( 'by','generatepress'),
			esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
			esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
			esc_html( get_the_author() ),
			get_avatar( get_the_author_meta( 'ID' ) )
		)
	);
}

Hi there,

do you have a link to a post where this should be working ?

Sorry David, you asked me to create new post for this, forgot to add.
It's:
Screen.coach

Apologies, yes I found that exact article and used that instead, the original issue was a "conflict" as the blog post header was a page hero element for Posts, so instead of my above snippet I used the example_2 page hero titles & snippet, but then forgot to update here - soz!

Post singles are working great now with my tweaked css (although customizer meta colours aren't working).

Can you pls advise how to get this exact same author/meta layout as per: http://screen.coach/settingup/ across all posts, pages and archives (and remove cats from below "read more")?

Hi there,

Can you pls advise how to get this exact same author/meta layout as per: http://screen.coach/settingup/ across all posts, pages and archives (and remove cats from below “read more”)?

Try entry meta style 1:
https://docs.generatepress.com/article/entry-meta-style/#example-1

As for removing the category on post lists, go to Appearance > Customize > Layout > Blog and click on the archive tab and make sure "Display post category", "Display post tags" and "display comment" are unchecked.

https://share.getcloudapp.com/qGuE09DO

That's great, thanks, but missing categories: http://screen.coach/blog/

Adding 'categories', to the below section didn't help.

add_filter( 'generate_header_entry_meta_items', function() {
    return array(
        'author',
        'date',
	'categories',
    );
} );

Make sure it's activated in Appearance > Customize > Layout > Blog.

On Archive tab, make sure "Display post category" is checked:
https://share.getcloudapp.com/QwuExxOX

Also, make sure you have a filter for the footer entry meta items removing the category. Else it'll disable on both header and footer entry meta.

Example:

add_filter( 'generate_footer_entry_meta_items', function( $items ) {
    return array(
        'post-navigation',
    );
} );

This one only returns the post-navigation. Completely removes category.

This is important because, on archive post pages, the category is added to the footer entry meta by default.

Sorry, I got confused, you said above:

As for removing the category on post lists, go to Appearance > Customize > Layout > Blog and click on the archive tab and make sure “Display post category”, “Display post tags” and “display comment” are unchecked.

But then said to do the opposite, which shows the cats below "read more", and not in meta.

EDIT: This worked:

I changed the section below from https://docs.generatepress.com/article/entry-meta-style/#example-1 - which includes removing the categories after return array('post-navigation',

add_filter( 'generate_post_author_output', function() {
    return sprintf( ' <span class="byline">%1$s</span>',
        sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>',
            esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
            esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
            esc_html( get_the_author() ),
            get_avatar( get_the_author_meta( 'ID' ) )
        )
    );
} );

add_filter( 'generate_header_entry_meta_items', function() {
    return array(
        'author',
        'date',
        'categories',
    );
} );

add_filter( 'generate_footer_entry_meta_items', function( $items ) {
    return array(
        'post-navigation',
    );
} );

Then tweaked CSS (replacing the comments css, for a date class) to give the vertical bars around date:

time.entry-date.published {
    border-left: 1px solid #ddd;
    padding-left: 10px;
    margin-left: 10px;
    border-right: 1px solid #ddd;
    padding-right: 10px;
    margin-right: 10px;
}

But then said to do the opposite, which shows the cats below “read more”, and not in meta.

ah yeah my bad. The context of that was from your previous reply asking "(and remove cats from below “read more”)?"

My suggestion was one way of removing it but I completely missed the context of you intending to move that particular meta item. My bad.

Glad you got it sorted. :D

No worries, thanks for your help.

Almost there! Outstanding matters:

1. How do I make this exact same meta style standard across everything? Pages, Media, etc, etc?

2. How do I hide this meta on Pages by default, and enable it when I want it to appear? (Thinking this would be simpler - apply the style to everything, hide if required).

In other news - Page-Hero meta needed css for link colors (this needs to be added to your docs IMHO, no reason to have meta with non-standard link colors).
Do tell me if simpler way for page-hero to use the customizer meta colours:

div.page-hero a:link {color: #;}
div.page-hero a:hover {color: #;}
div.page-hero a:visited {color: #;}

1. How do I make this exact same meta style standard across everything? Pages, Media, etc, etc?

For media attachment pages, you'll have to create a template.

Check these conversations:
https://generatepress.com/forums/topic/template-for-attachments-image/

2. How do I hide this meta on Pages by default, and enable it when I want it to appear? (Thinking this would be simpler – apply the style to everything, hide if required).

entry metas are not added on pages by default. You have to manually hook meta functions to make it appear on pages.

In other news – Page-Hero meta needed css for link colors (this needs to be added to your docs IMHO, no reason to have meta with non-standard link colors).
Do tell me if simpler way for page-hero to use the customizer meta colours:

You can set it here as well:
https://share.getcloudapp.com/2NuwkJAj

https://docs.generatepress.com/article/header-element-overview/#colors

This archived topic is closed to new replies.