Filter front page posts by category

Try adding this code to functions.php file: add_action(‘pre_get_posts’, ‘ad_filter_categories’); function ad_filter_categories($query) { if ($query->is_main_query() && is_home()) { $query->set(‘category_name’,’news, uncategorized’); } } category_name is the slug or the nicename of the category. Add a comma separated list of the categories you wish to include.

Exclude certain category from latest updates

In addition to the answer by Tim, one can always use a proper tax_query. All the build in tag and category parameters gets converted to a proper tax_query before being passed to the WP_Tax_Query class to build the JOIN clause for the SQL query. I use a tax_query in almost all applications as it gives … Read more

How to remove the parentheses from the category widget

Add this code to your functions.php file and it will remove the parentheses and surround the post count with a span with a class to easily style it. function categories_postcount_filter ($variable) { $variable = str_replace(‘(‘, ‘<span class=”post_count”> ‘, $variable); $variable = str_replace(‘)’, ‘ </span>’, $variable); return $variable; } add_filter(‘wp_list_categories’,’categories_postcount_filter’); ++Bonus In the archive widget, if … 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

Preventing index.php?category_name=something from redirecting

This should work: add_action( ‘init’, ‘wpa12742_init’ ); function wpa12742_init(){ add_rewrite_rule( ‘category/(.+?)/(\d{4})/?$’, ‘index.php?category_name=$matches[1]&year=$matches[2]’, ‘top’ ); add_rewrite_rule( ‘category/(.+?)/(\d{4})/page/(\d+)/?$’, ‘index.php?category_name=$matches[1]&year=$matches[2]&paged=$matches[3]’, ‘top’ ); } EDIT On second thought, that’s not enough, since you’ll get caught by redirect_canonical(). Add this too: add_filter( ‘term_link’, ‘wpa12743_term_link’, 10, 3 ); function wpa12743_term_link( $link, $term, $taxonomy ){ if(‘category’ != $taxonomy && !preg_match( ‘@^\d{4}$@’, get_query_var(‘year’) … Read more

wp_nav_menu not appearing for a couple pages

I had the same problem, but with a newer version of WordPress (3.7.1). On pages with custom taxonomies of custom posts, the wp_nav_menu was not shown. The solution below worked for me. in functions.php of the theme: add_action( ‘pre_get_posts’, ‘my_pre_get_posts’ ); function my_pre_get_posts($query) { if ($query->get(‘post_type’) === ‘nav_menu_item’) { $query->set(‘tax_query’,”); } }

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