What are the current recommended best-practices for comments.php?

You really don’t need much. A headline with id=comments <h2 id=”comments”><?php comments_number(); ?></h2> This will be the target for comments_link() in the article loop. Links for paginated comments. Usually, I put these links into a function and call the function above and below the comments list: class TTT_Template { function comment_pager() { if ( get_comment_pages_count() … Read more

How to stop wordpress to make the default query?

Stop WordPress to run main query is hard: you have to dig inside the deep heart of WordPress. WordPress frontend workflow: wp-blog-header.php call the function wp() wp() function creates an instance of wp class, and call main() method on it main() method code: public function main($query_args=””) { $this->init(); $this->parse_request($query_args); // build query vars starting from … Read more

How to set a fall back template for a custom post type in a plugin?

To provide a default template that can be overwritten by a theme hook into template_include like the linked questions suggest. You get the template WordPress wants to use as a parameter. If that is not the file you want – replace it with your plugin’s file: add_filter( ‘template_include’, ‘wpse_57232_render_cpt’, 100 ); /** * Provide fall … Read more

A special single page templates for posts under a category and all its child category

You can do that with single_template filter. First you will need to check if a post belongs to a top level category. So here is the function. // custom single template for specific category function wpse_custom_category_single_template( $single_template ) { global $post; // get all categories of current post $categories = get_the_category( $post->ID ); $top_categories = … Read more

Custom Taxonomy in plugin and template

First of all – plugins are for generating content, themes are for displaying it. So really, a plugin shouldn’t do this. But there are grey areas – for example in an ‘events’ related plugin, it would be desirable to display dates, venue etc – things that a WordPress theme wouldn’t normally display. I would suggest … Read more

Make all subcategories use the template of its category parent?

Here is a code I used to do it: // make category use parent category template function load_cat_parent_template($template) { $cat_ID = absint( get_query_var(‘cat’) ); $category = get_category( $cat_ID ); $templates = array(); if ( !is_wp_error($category) ) $templates[] = “category-{$category->slug}.php”; $templates[] = “category-$cat_ID.php”; // trace back the parent hierarchy and locate a template if ( !is_wp_error($category) … Read more

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