Using custom post template

i’m trying to implement a custom post template for all posts filed under a specific category.

I’m making use of WP-O-Matic plugin that puts in the RSS feeds in this category and would like to make a bit of customization for the branding on posts filed under this particular category.

Read More

I found the below code from here: http://www.nathanrice.net/blog/wordpress-single-post-templates/

But when I add this to my functions.php I get a warning:

Parse error: syntax error, unexpected
T_LNUMBER, expecting T_STRING or
T_VARIABLE or ‘{‘ or ‘$’ in
public_html/wp-content/themes/mytheme/functions.php(16)
: runtime-created function on line 1

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

Any idea on how to figure this out.

P.S: I tried using a different approach where I made single.php as a doorway page to run a WP query. If category id matches then it renders custom-template.php else default-template.php

As mentioned here.

But I continue to get the following error:

Parse error: syntax error, unexpected
T_LNUMBER, expecting T_STRING or
T_VARIABLE or ‘{‘ or ‘$’ in
public_html/wp-content/themes/mytheme/functions.php(16)
: runtime-created function on line 1

Warning: call_user_func_array()
[function.call-user-func-array]: First
argument is expected to be a valid
callback, ” was given in
/public_html/wp-includes/plugin.php on
line 166

Related posts

Leave a Reply

1 comment

  1. $cat->1176 cannot be a property of an object.

    PHP Manual:

    A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: ‘[a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*’

    Use $cat->term_id and compare it’s value with the number you’re out for.

    And … don’t use anonymous functions. They cannot be cached by opcode caches like APC and they are hard to debug – as you have seen. Plus, if someone wants to remove this filter in a child theme, that’s now very, very hard.