Archived topic
Category list at top of post
45 replies · Started by Randy on May 9, 2018
Sorry for the delay: I took a dinner break.
We're further along, but not quite there yet. We have:
Posted June 17, 2019 Categories Kids/Teens, Military, Podcasts, Space, Work Leave a comment
when it used to be:
Posted June 17, 2019 in Categories Kids/Teens, Military, Podcasts, Space, Work
Leave a comment
(adding "in" and the Comments link on a new line)
Can you try the edited CSS?
https://generatepress.com/forums/topic/category-list-at-top-of-post/page/2/#post-936425
Let me know :)
Yes, that fixed the Comments part. How can we get "in" in there?
(Almost there! Thanks.)
Sorry final update.
Update the snippet to this:
//Change the GeneratePress post meta function
add_filter( 'generate_post_date_output', 'tu_categories_to_date' );
add_filter( 'generate_category_list_output', '__return_false' );
add_filter( 'generate_tag_list_output', '__return_false' );
add_filter( 'generate_show_comments', '__return_false' );
function tu_categories_to_date() {
$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time class="updated" datetime="%3$s" itemprop="dateModified">%4$s</time>' . $time_string;
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
// If our date is enabled, show it.
$time_string = sprintf( 'Posted <span class="posted-on">%s </span>', // WPCS: XSS ok, sanitization ok.
$time_string
);
$categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );
$categories_list = sprintf( 'in <span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
_x( 'Categories', 'Used before category names.', 'generatepress' ),
$categories_list
);
$tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );
$tags_list = sprintf( '<span class="tags-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
_x( 'Tags', 'Used before tag names.', 'generatepress' ),
$tags_list
);
echo $time_string . $categories_list;
if ( ! 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>';
}
}
And the CSS to this:
.entry-header .comments-link {
display: block;
}
I tested the code so it should all work :)
"Should" being the operative word. :-)
The posted line looks perfect. But no Comments count/link.
Oh wow my bad. Getting too late here.
Updated the snippet:
https://generatepress.com/forums/topic/category-list-at-top-of-post/page/3/#post-936492
I feel your pain (getting late here too).
Just noticed the word "Posted" is not on the front of the date line.
No worries if you need to sleep on it first.
Edited the snippet again:
https://generatepress.com/forums/topic/category-list-at-top-of-post/page/3/#post-936492
Woo hoo! Looks like everything is set.
Tell Tom not to break it again. ;-)
Thanks, and have a good night.
No problem :)
Me again.
See https://randysrandom.com/independence-day/
...another of my sites. This one uses Facebook comments, rather than WP's, so I don't need a Comments link. I've tried a few iterations of the ideas here to get:
Posted on 4 July 2017 in Holidays, Thinking, Wow
...but I haven't cracked it yet. (It currently shows "Categories" but I don't actually need that word.) This is in Posts, not Pages. TIA
Don't actually see the word Category:
https://www.screencast.com/t/knZyvBrjvDj3
Have you figured this out?
All but the "in" part.
I'm using this code:
//Change the GeneratePress post meta function
add_filter( 'generate_header_entry_meta_items', function() {
return array(
'date',
'categories',
);
} );
Try this CSS:
span.posted-on:after {
content: " in";
}
Thanks, Leo, that fixed it.