Site logo

Archived topic

Category template

7 replies · Started by Charles on July 2, 2022

Viewing posts 1–8 of 8

How can I change the category post template (Add more words to the snippet; delete the read more button, etc.)

Hi there,

theres a couple of methods:

A. Using a Block Element Content template to visually build your own post template for the category archive:

https://docs.generatepress.com/article/block-element-content-template/

OR

B. Use some PHP to makes those changes:

i) the option_generate_blog_settings filter can be used to enable disable blog options dynamically:

https://docs.generatepress.com/article/option_generate_blog_settings/

heres an example to remove the read more text and button from the category:

add_filter( 'option_generate_blog_settings', 'db_custom_archive_settings' );
function db_custom_archive_settings( $options ) {
    if ( is_category() ) {
		$options['read_more'] = null;
		$options['read_more_button'] = false;	
    }
  
    return $options;
}

you can include any other $options you need in there.

ii) For the excerpt you can use this snippet:

add_filter( 'excerpt_length', function( $length ) {
    if ( is_category() ) {
        return 20;
    }

    return $length;
}, 1000 );

Change the 20 to the word count you require

Thanks, what file does the .php go in?

Aaah sorry i should linked to this doc, which explains how to add PHP:

https://docs.generatepress.com/article/adding-php/

TLDR:
Are you using a child theme ?
If Yes, then add the snippets in the child theme functions.php
If No, then you will need to use the Code Snippets plugin linked in the above doc.

My bad... I should have figured that out.

Ideally I'd like the blog content to be formatted into paragraphs -- Maybe that's not possible?

Can I limit the number of posts that display and then add a "more posts" button?

What's infinite-scroll?

Thank you.

No worries :)

On your blog page - are you wanting all of the post content to be displayed? Or do you just have a larger excerpt?

In the Blog settings you can enable Infinite Scroll ( posts auto load as the user scrolls to the footer ), and then selectd Load More button which will require the user to press to load more. If you want to enable that with the PHP snippet then both of these should be set to true:

$options[‘infinite_scroll’]
$options[‘infinite_scroll_button’]

thanks

Did you resolve the issue with showing paragraphs in the blog ?

This archived topic is closed to new replies.