[Resolved] Creating custom layout for archives and single posts

Home Forums Support Creating custom layout for archives and single posts

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #1034992

    I need to create unique layouts for archive and single posts (depending on the category of each post).

    Basically I need to move items around the page and style them, eg Put “Category and tags” higher up the page (below featured image), add a new on page sub menu above featured image, and add some sort of category filter (maybe using “search and filer” plugin https://wordpress.org/plugins/search-filter/ )

    I can see I can add some basic layout options in “Layout Elements”.

    Usually I would create copies in child theme of single.php, content-single.php and edit them.

    Q1. Is this still the best way to do this in GP?

    Q2. Would I need to consider the “inc/structure/” files as well?

    Q3. Is there a preferred way to do this, eg using hooks?
    Many thanks

    Lead Developer
    Lead Developer

    Hi there,

    1. Custom template files are useful if you need to change the structure of the core template files.

    2. It isn’t possible to overwrite those files right now.

    3. I would likely use hooks in this case. Our Hook Element might be worth checking out: https://docs.generatepress.com/article/hooks-element-overview/

    If you need help un-hooking/hooking, we can go through things one by one and I’ll help with the code 🙂


    child templates worked fine, plus I used following in functions.php to change category outpu

    add_filter( 'generate_category_list_output','jb_remove_categories' );
    function jb_remove_categories( $categories ) {
    	if ( is_single() || is_archive()  ) {
    		return '';
    add_action( 'generate_before_entry_title','jb_single_cats_above_title' );
    function jb_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 && (is_single() || is_archive() ) ) {
    			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' ),
    Lead Developer
    Lead Developer

    Perfect – thanks for sharing your solution! 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.