• Resolved sootylad

    (@sootylad)


    Hey guys,

    I’m wondering if it is possible to make a sub category follow the template of its parent?

    I have category-4.php for example which will hold the template for the relevant category, but there are a fair few sub categories within that category which need to use the category-4 template…

    is this possible? without a decent solution I will have to copy and paste the category-4.php template code to all the relevant sub category template files ??

    any ideas?

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter sootylad

    (@sootylad)

    ahh great, that has done the job nicely ??

    now what i need to do next, and i have a feeling this wont be as easy as the first problem, is to make it so that when tags are clicked they also use that category-4 template…

    what i am doing is creating a portfolio, which you can filter by client (which is what i did above, the clients were in sub folders and used the parent categories template) but you can also filter by service (website, logo etc) which i have put into tags…

    so when a tag is clicked, i need the same effect as clicking a client only the structure is different…

    i couldn’t actually think of a much better way of doing this, but any help would be appreciated…

    Might have to use a Tag Template that includes the category-4.php template.

    <?php include (TEMPLATEPATH . ‘/category-4.php’); ?>

    Thread Starter sootylad

    (@sootylad)

    once again worked a treat, hats off to you good sir ??

    Thank you.

    ThankS moderator!
    i used “Elevate Parent Category Plugin” for similar purpose
    https://pluginscatalog.com/plugins/elevate-parent-category-template.html

    but still have One problem
    by using this plugin page title , heading etc. all change to parent category name
    (this plugin replace the child categ with its parent categ & use that template for child )

    i want to use child category page title & headings
    but child categ only uses template of parent..

    HELP please !

    Hmm – maybe look at Use Parent Category Template plugin

    thankx a LoT! ??
    Problm solved

    I want similar Function for Single posts also
    i.e. to use parent template single-catid.php while viewing single post for child category
    now i use single-catid.php for each child categ.

    how can i add that function ?
    this function add to use_parent_category_template.php
    or another file for that purpose ?

    is it correct:

    function use_single_parent_template() {
    
        if ( !is_category() || is_404() ) return; // we only care about category views
    
        $cat = get_query_var('cat');
        $category = get_category ($cat);
    
        if ( !($category) ) return; // no category with which to work
    
            if ( file_exists(TEMPLATEPATH . '/single-' . $category->cat_ID . '.php') ) {
                include(TEMPLATEPATH . '/single-' . $category ->cat_ID . '.php');
                exit; }
            elseif ( file_exists(TEMPLATEPATH . '/single-' . $category->category_parent . '.php') ) {
                include(TEMPLATEPATH . '/single-' . $category->category_parent . '.php');
                exit; }
    }
    add_action('template_redirect', 'use_single_parent_template');
    ?>

    @michael
    one more issue there?
    when i use plugin described here
    https://codex.www.ads-software.com/User:MichaelH/MyPlugins
    in use_parent_category_template.php

    its working gr8 for parent category template
    my custom fields in the posts disappeared
    but when i try after disable this plugin custom field appears again

    i use this code for custom field

    <?php $songkey=get_post_meta($post->ID, 'music_song', true);
    <?php  echo $songkey;  ?>

    plz suggest to resolv this problm?
    thankx in advance

    Is it possible to do this with pages and subpages rather than with posts and categories?

    Anyone figured out the problem with the disappearing custom fields, using the elevate plugin?

    Thanks!

    Arnii

    emanoelmelo

    (@emanoelmelo)

    You dont need plugin, just use a few codes at the functions.php
    I’ve found in this article:
    https://brassblogs.com/blog/making-child-categories-recognize-parent-displays

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Sub-categories to use parent category template?’ is closed to new replies.