Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

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

share|improve this question
    
it works fine for me, what is your theme? whats the code you have at line 16 in your functions.php? –  Bainternet May 12 '11 at 7:08
    
I'm using the weekly theme from themejunkie –  Sledge81 May 12 '11 at 7:12

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer
    
Thanks toscho.. I kind of figured out the problem and went ahead with option two, where single.php acts as a filter and renders the post template based on the category id. –  Sledge81 May 12 '11 at 7:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.