ThemeShaper Forums » Thematic

[closed]

Custom Design for Page Within a Certain Category

(7 posts)
  • Started 8 years ago by andycheeseman
  • Latest reply from andycheeseman
  • This topic is not resolved
  1. Hi,

    How would I go around creating a custom post design (like you can create a custom page design) for posts within a certain category?

    I've found some useful code in the following website, but I can't figure out where this would sit in Thamatic?

    http://melandri.net/2009/08/09/wordpress-single-post-template-based-on-category-2/

    Any help would be greatly apreciated.

    Thanks,
    Andy.

    Posted 8 years ago #
  2. Thanks. If I were to use this method, how would I go around making my own single-template.php?

    If I try and copy single.php and paste it into my child theme to customise, I can only customise the design when removing thematic_singlepost(); and adding my custom fields into there.

    In your opinion, is there a cleaner way of doing this?

    Thanks,
    Andy.

    Posted 8 years ago #
  3. there isn't anything wrong w/ removing thematic_singlepost() from the new customized template. i'd probably copy the guts of the function right into the new template and then hack a way. i think it would be more difficult to create the correct conditional to filter thematic_singlepost() anyway.

    Posted 8 years ago #
  4. awesome, cheers. so for a definitive list of all of thematics functions should I just look through the files in library / extensions?

    thanks for your help!

    Posted 8 years ago #
  5. i don't know about a 'definitive list' but i think all the functions are in the library/extensions folder

    Posted 8 years ago #
  6. Thanks. Here is a solution that I have found and customised from http://www.nathanrice.net/blog/wordpress-single-post-templates/

    add_filter('single_template', create_function('$t', 'foreach( (array) get_the_category() as $cat ) { if ( file_exists(TEMPLATEPATH . "/single-{$cat->term_id}.php") ) return TEMPLATEPATH . "/single-{$cat->term_id}.php"; } return $t;' ));

    You insert the code into functions.php, then when WP displays a single post, it searches for single-X.php (where X is the ID of your template) and uses that as a post template (a la page template) if the custom file exists in your child theme path.

    I customised it to use the category slug rather than the category id and also switched from using TEMPLATEPATH to STYLESHEETPATH (to avoid problems when using child themes). So simply add the below code to functions.php and create something like single-MEMBERS.php (with the contents of single.php, customised as you need). Now any post in the category MEMBERS will display using the custom template.

    add_filter('single_template', create_function('$t', 'foreach( (array) get_the_category() as $cat ) { if ( file_exists(STYLESHEETPATH . "/single-{$cat->slug}.php") ) return STYLESHEETPATH . "/single-{$cat->slug}.php"; } return $t;' ));

    Posted 8 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.