Site logo

Archived topic

Category list at top of post

45 replies · Started by Randy on May 9, 2018

Viewing posts 16–30 of 46

CSS worked fine, thanks.

The functions didn't -- apparently because of conflict with earlier meta modifications (upstream in this thread). Like can't redeclare tu_categories_to_date, and then (when I remove the duplicate) other problems, like unexpected '=' and unexpected '}'.

Here's the current previous meta tweaks:

//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( '<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( '<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 ( ! 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>';
	}
}

You'll need to replace the previous function with that new one.

Ah. I hope you didn't hurt yourself rolling your eyes. :-)

Works fine, and when the tags icon came up, I was able to fix that -- so I am learning!

Thanks, and all set.

Glad I could help! :)

Well, something broke. :-/

I did do a little site work today: setting expires headers. Can't see how that would affect this, though.

Example (from https://thisistrue.com/035-to-boldly-go/ ):

Posted June 17, 2019Categories Kids/Teens, Military, Podcasts, Space, WorkLeave a comment

...all in one line.

Previously, the "Categories" line and "Leave a comment" (or N Comments) were both on a new line. How can I get back there?

I don't recall any recent work that "could have" an effect on this, but I can't say for sure when it was last working right.

Hi Randy,

I'm guessing you've updated to GeneratePress 2.3?

This is because we've added the post meta ordering filter in the latest theme update which required some tweaks if you are using custom function previously.

So you are wanting post date > categories > comment for entry meta right?

If so you can now replace the big function above with this one:

add_filter( 'generate_header_entry_meta_items', function() {
    return array(
        'date',
        'categories',
        'comments-link',
    );
} );

Reference:
https://docs.generatepress.com/article/generate_header_entry_meta_items/
https://docs.generatepress.com/article/generate_footer_entry_meta_items/

Let me know if you need more tweaks :)

Ah, but of course!

Problem with your replacement code, however:

"Your PHP code changes were rolled back due to an error on line 60 of file wp-content/themes/gp-child/functions.php. Please fix and try saving again."

...where in my case line 60 is the one with "categories" in it, from above.

I wondered about that -- I noticed it was different in the third line, but thought maybe that was because it was the ending line.

OK, it's now correct as "Posted in [category list]" ... but the line under where it should say:

N Comments (which is a link to #comments) is not there. I DO have the Customizer > Layout > Blog > Display comment count box checked. (No change when I uncheck it.)

Ahh wait...I think comment requires something different on single posts.

Will check with Tom and report back.

Sorry Randy.

Comments still don't work on single posts but we are definitely considering adding that in.

Can you revert back to the previous function and I'll provide the necessary CSS?

Let me know :)

Can I? Sure. The functions code and the CSS are upthread (Entries #574223 & #574243), if you need to look at them.

Can you add in the function first?

I just checked the page and still don't see the comment link like before.

Let me know :)

Ah, now that I know what you meant, done!

Try this CSS:

.entry-header .comments-link {
    display: block;
}
.entry-meta .cat-links {
    padding-left: 3px;
}

Let me know :)

This archived topic is closed to new replies.