Site logo

Archived topic

add Author image, name, date and category to posts and pages

15 replies · Started by Carlo on June 12, 2019

Viewing posts 1–15 of 16

looking to style my published pages and posts and inside of the content (not the header element) im wanting to add some extra element, so seeing if it is possible to do so?

this is what im trying to achieve.

category (styled with underline and color)

H1 title

author image & name | Date (published or updated)

note, as i mentioned, i want to add this info to my pages too as ive used the category plugin to set categories for my pages too.

im ok if i need to use shortcodes or whatever i need to do to try and accomplish it.

thanks

thanks Leo,

1. got the categories to show above the H1 title, but how can i make categories visible inside of pages? i am using the Category Tag Pages plugin to assign categories to pages currently.

2. any way to style the categories text at the top of the posts (and pages)? i would like to remove the folder icon and make the category text all capitals.

3.i added the entry meta style (example-1) and got that working fine, i also wanted it to be added to pages so i added the snipped code...

add_action( 'generate_after_entry_header', 'tu_page_meta' );
function tu_page_meta() {
if ( 'page' == get_post_type() ) : ?>

<!-- .entry-meta -->
<?php endif;
}

the code above does work, except author icon, name and date are on every single page, home page , category pages, privacy policy... any way to filter it so it only shows on certain pages? or exclude certain pages?

4. trying to add the following additions from this page https://docs.generatepress.com/article/generate_post_date_output/
-Only Show Updated Date
-Add Icon to Date
-Remove Link from Date

but not getting any of those to have any effect when i add them via snippets?
is it because ive use the code from https://docs.generatepress.com/article/entry-meta-style/#example-1?

thanks

Can we try one thing at the time?

Try this snippet for #1 first and see if it works:

add_filter( 'generate_category_list_output','lh_remove_categories' );
function lh_remove_categories( $categories ) {
		return '';
}

add_action( 'generate_before_entry_title','lh_single_cats_above_title' );
function lh_single_cats_above_title() {
		$categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );
		if ( $categories_list ) {
			printf( '<span class="entry-meta cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
				_x( 'Categories', 'Used before category names.', 'generatepress' ),
				$categories_list
			);
		}
}

unfortunately that made no difference.

i deactivated the old snipped from this link: https://generatepress.com/forums/topic/display-post-categories-above-title/#post-645410

and activated the one you just mentioned but still the same result. it shows on "posts" but not on "pages".

any other ideas?
also if we get this working well, will it be possible to exclude certain pages from show the category tag? like homepage, category pages ect..?

Hmm I guess generate_before_entry_title hook doesn't exist on static pages.

Can you give this a shot?

add_action( 'generate_before_content','lh_single_cats_above_title' );
function lh_single_cats_above_title() {
		$categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );
		if ( $categories_list ) {
			printf( '<span class="entry-meta cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
				_x( 'Categories', 'Used before category names.', 'generatepress' ),
				$categories_list
			);
		}
}

ok that worked, got the "categories" to show in pages.

now, is there a way to filter this so not show the category on certain pages (like homepage, privacy ect..)

how about filter out anything that has a "uncategorized" category?

I would:

1. Create a Hook Element: https://docs.generatepress.com/article/hooks-element-overview/
2. Set the hook to before_content
3. Check the "Execute PHP" checkbox
4. Add this Hook content:

<?php
$categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );

if ( $categories_list ) {
    printf( '<span class="entry-meta cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
        _x( 'Categories', 'Used before category names.', 'generatepress' ),
        $categories_list
    );
}
?>

Then you can use the Display Rules to choose where (or where not) to include the hook.

got that working fine Tom, thankyou.
i filtered out certain categories so now only showing where it needs to :)

As far as styling the "category" text that is above the H1 Title,
1.how can we remove the "folder icon" before the category?
2.make the category text in capitals
3.underline the category text (with a colored line)

Give this CSS a shot:

.entry-meta.cat-links:before {
    display: none;
}

.entry-meta.cat-links {
    text-transform: uppercase;
    border-bottom: 1px solid red;
    display: inline-block;
}

that looks so good. very happy with that, now just a few small things and it'll be exactly as i was hoping for.

im currently using the following php code and CSS to show entry meta data.
from: https://docs.generatepress.com/article/entry-meta-style/#example-1

i have been trying to adjust the publish date with no effect? have used the code from:
https://docs.generatepress.com/article/generate_post_date_output/
but the only change was a second date became visible when i activated it.

How can i make the following changes:
-Remove Link from Date
-Show Updated Date- with the word "Updated" before the date (if more that 1 week from original publish date - is this possible?)

Hi there,

Try this function instead of the one from docs:

add_filter( 'generate_post_author', '__return_false' );
add_filter( 'generate_show_comments', '__return_false' );

add_filter( 'generate_post_date_output', function( $date, $time_string ) {
    printf( ' <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' ) )
        )
    );

    if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
        echo '<span class="comments-link">';
            comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) );
        echo '</span>';
    }

    printf( '<span class="posted-on">%s</span>',
        $time_string
    );
}, 10, 2 );

As for the updated date, try this: https://docs.generatepress.com/article/show-the-updated-post-date/

Hy Tom, if i deactivate the old snippet and replace it with the new one i get:

The site is experiencing technical difficulties. (and page wont load) i deactivate it and all goes back to normal.

any other ideas?
Just so were on the same page, this is what i've currently got thats working, but wont allow the date adjustments i mentioned earlier:

add_filter( 'generate_post_author', '__return_false' );
add_filter( 'generate_show_comments', '__return_false' );
add_filter( 'generate_post_date_output', 'tu_fancy_byline' );
function tu_fancy_byline( $date ) {
	printf( ' <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' ) )
		)
	);

	if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
		echo '<span class="comments-link">';
			comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) );
		echo '</span>';
	}

	echo $date;
}

That worked, the link is removed from the date now.
Just one more thing and were done..

Is it possible to work out a solution for this?
Show Updated Date- with the word “Updated” before the date (if more that 1 week from original publish date)

This archived topic is closed to new replies.