For custom templates, is it better to use `template_include` or `type_template`?

{type}_template is a filter inside the get_query_template function. That function is called by a series of functions called get_home_template, get_category_template and so on. It allows you to very specifically target templates. You can see it in action in template-loader.php, where the $tag_templates variable is defined, binding conditions like is_home, is_category and so on to the … Read more

php ajax problem – weird 301 responses!

I’m guessing the page your calling executes an wp_redirect with a 301 response somewhere. Dont really have an answer for you but maybe you can try the following. Ajax does not know what type of page your calling from and there might be some strange query_vars loaded that trigger a redirect. Your using a permalink … Read more

Change template dynamically

Just in case someone comes here to copy pasta without looking at the codex. THE APPROPRIATE FILTER IS »template_include« See: Codex – Filter Reference As Radek pointed out that method can destroy your theme. Additional information: The article »Don’t use template_redirect to load an alternative template file« by Mark Jaquith, where he says, in a … Read more

Display a specific dynamic sidebar widgets on a specific page

I think what you might need is simply to run register_sidebar() in an ‘widgets_init’ hook. The TwentyTen theme has examples for register_sidebar() in its functions.php file, but here’s what it might look like: add_action( ‘widgets_init’, ‘twentyten_widgets_init’ ); function twentyten_widgets_init() { register_sidebar( array( ‘name’ => __( ‘News Sidebar’, ‘yoursite’ ), ‘id’ => ‘sidebar-news’, ‘description’ => __( … Read more

Custom page template not working

I think you’re muddling up the Template Hierarchy, so make sure to start by reading that. page-blog-page.php is for a page with the slug “blog-page.” If you’re using a page template, then you should name it something outside of the template hierarchy-reserved name spaces (e.g. page-{slug}, etc.) such as template-swapnesh.php. Also, WordPress has the blog … Read more

Changing the template hierarchy

Try this filter function wpse_63614_restructure_template_hierarchy( $template ){ return get_template_directory().’/filename.php’; } add_filter( ‘template_include’, ‘wpse_63614_restructure_template_hierarchy’ ); The filename would be the file you would want to call in your theme folder. For child themes you would use get_stylesheet_directory instead. EDIT: Or as suggested by Chip Bennett and what I too feel would be better; you can use … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)