[Support request] How to set custom pages instead of category/archive pages?

Home Forums Support [Support request] How to set custom pages instead of category/archive pages?

Home Forums Support How to set custom pages instead of category/archive pages?

  • This topic has 2 replies, 2 voices, and was last updated 1 week ago by Leo.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #2081072
    Ricardo

    Hi team,

    Is my first post here.

    So what i need is to create a custom archive template for showing posts by category.

    So my question is can this code applys to the generetepress theme or need customization?

    i see this code at:

    function loadPageFirst() {
        // get the actual category
        $actualCategory = get_category( get_query_var('cat') );
        // get the page with the same slug
        $matchingPage = get_page_by_path( $actualCategory->slug );
    
        // If no match, load the normal listing template and exit (edit if you are using a custom listing template, eg. category.php)
        if (!$matchingPage) {
            include( get_template_directory() . '/archive.php');
            die();
        }
    
        // Make a new query with the page's ID and load the page template
        global $post; $post->ID = $matchingPage->ID;
        query_posts( 'page_id=' . $matchingPage->ID );
        include( get_template_directory() . '/page.php');
        die();
    }
    add_filter( 'category_template', 'loadPageFirst' );

    I know there is other option like wp show posts, but i whant to limit plugins.

    Can you help me on this one?

    Best regards

    #2081074
    Ricardo
    #2081460
    Leo
    Staff
    Customer Support

    Hi there,

    The category/archive pages are handled by WordPress core so if the code works in a Twenty series WP theme, then it should work in GP as well.

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