[Resolved] Post category on the top

Home Forums Support Post category on the top

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1343774
    Ales

    Hi,

    I want to have author name, publish date and category(ies) on the top of the post together in one line. For example how it is here:
    result

    I found this code, which I have as a snippet:

    add_filter( 'generate_category_list_output','lh_remove_singlecategories' );
    function lh_remove_singlecategories( $categories ) {
    	if ( is_single() ) {
    		return '';
    	}
    	
    	return $categories;
    }
    
    add_action( 'generate_before_entry_title','lh_single_cats_above_title' );
    function lh_single_cats_above_title() {
    	if ( is_single() ) {
    		$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
    			);
    		}
    	}
    }

    But it does this:
    wrong result

    Also there is no space between September 8, 2018 and by Alex because I removed the link from the date with this code:

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

    And this is exactly the same on homepage/category pages with list of posts.

    I would really appreciate if you can help me to style this in the way I showed in the example.

    Thanks a lot!
    Have a nice day,
    Aleš

    #1344023
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    I would do something like this, instead:

    add_filter( 'generate_header_entry_meta_items', function( $items ) {
        return array(
            'author',
            'date',
            'categories',
        );
    } );
    
    add_filter( 'generate_footer_entry_meta_items', function( $items ) {
        return array_diff( $items, [ 'categories' ] );
    } );

    As for the space, try the updated code here: https://docs.generatepress.com/article/generate_post_date_output/#remove-link-from-date

    Let me know 🙂

    #1344076
    Ales

    Hi Tom,

    Thanks a lot for your help! It works now perfectly.

    Can I have one more request for minor tweaks?

    1. There is not that category (folder) icon next to the categories.
    2. Author, date and categories are very close to each other. Is there any way how to do some margin?
    3. On the homepage (or category page) there is still spacing for missing list of categories on the bottom of each post, altough the categories are now correctly under the title. It doesn’t look very well, it’s too much white space. Can I somehow reduce this space?
    smaller spacing

    Thanks a lot!
    Aleš

    #1344344
    David
    Staff
    Customer Support

    Hi there,

    try this CSS:

    /* Display Cat Icon */
    .entry-header .gp-icon.icon-categories {
        display: inline;
    }
    /* Entry meta item spacing */
    .entry-header .entry-meta > a,
    .entry-header .entry-meta .posted-on
     {
        margin-right: 0.75em;
    }
    /* Remove additional footer space from archive */
    body:not(.single) footer.entry-meta {
        margin-top: 0;
    }
    #1347801
    Ales

    Hi David,

    Thanks a lot, this works like a charm!

    Have a nice day,
    Bye

    #1347980
    David
    Staff
    Customer Support
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.