WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Sub-categories to use parent category template? (13 posts)

  1. SooTyLaD
    Member
    Posted 5 years ago #

    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?

  2. MichaelH
    Member
    Posted 5 years ago #

  3. SooTyLaD
    Member
    Posted 5 years ago #

    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...

  4. MichaelH
    Member
    Posted 5 years ago #

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

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

  5. SooTyLaD
    Member
    Posted 5 years ago #

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

  6. MichaelH
    Member
    Posted 5 years ago #

    Thank you.

  7. PuNK DeSi
    Member
    Posted 5 years ago #

    ThankS moderator!
    i used "Elevate Parent Category Plugin" for similar purpose
    http://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 !

  8. MichaelH
    Member
    Posted 5 years ago #

  9. PuNK DeSi
    Member
    Posted 5 years ago #

    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');
    ?>
  10. PuNK DeSi
    Member
    Posted 5 years ago #

    @Michael
    one more issue there?
    when i use plugin described here
    http://codex.wordpress.org/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

  11. refugee43
    Member
    Posted 5 years ago #

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

  12. Arnii
    Member
    Posted 5 years ago #

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

    Thanks!

    Arnii

  13. emanoelmelo
    Member
    Posted 4 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic