Forums

Different category post templates with term_slug ??? (4 posts)

  1. creativelifeform
    Member
    Posted 2 years ago #

    Hi all,

    found this nifty bit of code:

    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;' ));

    from this site

    I am wondering, since 2.9 now supports category templates via slugs, would there be some way to use term_slug in that code instead of term_id? So I guess what I'm asking is, are these global WordPress variables now?

    Thanks in advance!

  2. creativelifeform
    Member
    Posted 2 years ago #

    Its okay I guess, I'm using the ID, no big deal. Might be cool to edit that code to take slugs. Will work on it.

  3. alchymyth
    The Sweeper
    Posted 2 years ago #

    have you tried to change $cat->term_id into $cat->slug ?
    and tested if that works?

    http://codex.wordpress.org/Database_Description#Table:_wp_terms

  4. creativelifeform
    Member
    Posted 2 years ago #

    Haha yeah that worked...I thought I tried it already but I guess not! Thanks a lot.

Topic Closed

This topic has been closed to new replies.

About this Topic