Loading page on categories and subcategories url pages


I Have very limited wordpress knowledge and tried many methods but with no luck.
I have categories and subcategories with url domain.com/news/sports/ of Custom Post Type.

I want to display categories page other than default post listings for better control as given below.
I don’t want the categories pages to display as default post list but something with blocks and widgets form
gutenberg ultimate blocks and other plugins functionalities.

I tried a lot to add some shortcuts and some available widgets from gutenberg to descriptions but categories pages have much limitation and can’t be customise much.

Following this

I tried Permalink Settings to load a page on categories pages, categories some how worked but the problem was posts under that categories and subcategories doesn’t work, also it doesn’t seems stable. Even I don’t mind to have post id in url like /%category%/%post_id%/%postname%/ to give wordpress an idea of displaying other post, but it didn’t worked.

Tried this filter.

add_filter( 'category_template', 'get_template_for_category' );

function get_template_for_category( $page_template )
    $cat = get_queried_object();
    $parent_cat_id = $cat->parent;
    $parent_cat = get_category( $parent_cat_id );
    $cultp_Initialization = "";

    if ( $parent_cat->slug == 'news' ) {
        activate_plugins( ABSPATH . PLUGINDIR . '/ultimate-post/ultimate-post.php' );
        $page_template = dirname( __FILE__ ) . '/category-news.php';
    return $page_template;

I know I don’t need filter, just category slug is enough to load above template. But
I just wanted to load all plugins to display page block correctly, which didn’t work as well.

In category-news.php tried this to wrap contents in template part and used

echo $page->contents;

get_template_part( 'template-parts/content', 'category-news' );

Also tried some other filters methods but the problem is the page doesn’t load any plugins for it to display properly.

After trying many things I gave up. Any idea please?

Fazli Hassan 2 months 0 Answers 9 views 0

Leave an answer