Different widgets on different page templates?

You will need to create more sidebars in your functions.php file and then edit the page templates to call the sidebar you want. Adding sidebars Go in to your functions.php file. You should see some sidebars already being registered. The code will look something like this: //Adds default sidebar if ( function_exists(‘register_sidebar’) ) register_sidebar(); To … Read more

Add custom fields when specific templates are selected

Can you do that? Absolutely! You simply need to query the _wp_page_template meta key value of the $post object, and act accordingly. Perhaps something like so: // Globalize $post global $post; // Get the page template post meta $page_template = get_post_meta( $post->ID, ‘_wp_page_template’, true ); // If the current page uses our specific // template, … Read more

How do you check if a WordPress template file exist?

So I would add to the Answer the following: function foo_function() { $located = locate_template( ‘home.php’ ); if ( !empty( $located ) ) { // ‘home.php’ found in Theme, do something } } add_action(‘init’, ‘foo_function’); // remember to change both of the parameters above, first one for where you want the // action to happen … Read more

WP frontend output of custom textarea fields not respecting line breaks. In admin it’s OK

Explode your $options value by “/n” ( new line ), then do a echo in foreach: $options = get_option(‘my_custom_plugin_options’); $textarea = $options[‘my_custom_plugin_options_textarea’]; $lines = explode(“\n”, $textarea); foreach( $lines as $line ){ echo $line; } UPDATE #1 For reference, it’s possible to store this function in functions.php to use later in template files. function the_textarea_value( $textarea … Read more

How do I display two separate taxonomy archives for two post types that share a single taxonomy?

According to the WordPress Codex archive-{post_type}.php So, in your case (depending on your naming): archive-products.php If you have a custom taxonomy archive also, then the challenge is structuring your archive to represent the proper taxonomy template. If you need to have a custom taxonomy archive, I would recommend that you use the post-type archive structure … Read more

Loading partial templates with AJAX/PJAX

If you’re concerned about the performance I would recommend using the WordPress API instead of trying to load markup using ajax. If you look at wp-includes/template-loader.php you can see how WordPress itself figures out which template to use. You could in theory just load that file, but you might have problems with template_redirect. require_once( ABSPATH … Read more