Exclude categories from homepage not longer working

I have no idea how this was ever working for you to begin with, but there’s really no need to use a custom page template for the blog posts index template. WordPress provides a template file to use: home.php. Easiest solution: Rename homepage.php as home.php and remove any custom template header comments Remove all query_posts() … Read more

Archive filtering

You need a tax_query argument to WP_Query, if I am reading your question correctly. $my_query = new WP_Query( array( ‘tax_query’ => array( array( ‘taxonomy’ => ‘category’, ‘field’ => ‘id’, ‘terms’ => array($featured_ID,$curr_cat->cat_ID), ‘operator’ => ‘AND’ ) ) ), ‘posts_per_page’ =>8 ) ); Untested, but I think that should be close. Also, where does global $cat; … Read more

Using in ‘category_name’ in ‘$query->set();’?

I am unable to duplicate the problem, but the Notice references this line: add_screen_option( ‘per_page’, array( ‘label’ => $title, ‘default’ => 20, ‘option’ => ‘edit_’ . $post_type . ‘_per_page’ ) ); And that makes me think that you should be passing a post type in your GET string. http://wp.dev/wp-admin/edit.php?post_type=post&category_name=intl Just a guess as I can’t … Read more

Include either name or slug in the include parameter using wp_list_categories?

I managed to figure this out with help from a friend. In case this helps anyone else, here’s my code. <?php $sector_terms = array(‘animal-health’, ‘sustainability-science’, ‘technical-publishing’); $sector_ids = array_map( function( $sector_term ) { $st = get_term_by(‘slug’, $sector_term , ‘post_tag’); return $st->term_id; }, $sector_terms); ?> <?php $sector_args = array( ‘taxonomy’ => ‘post_tag’, ‘show_count’ => 0, ‘pad_counts’ … Read more

Get the name of category in query

When you call $categories = get_the_category($post->ID); the $post variable is not defined yet (or is not the one that you expect), because you have to use it inside the loop. Where you have <span class=”cate”><?php echo $categories ?></span> replace with (this will output something like “Game, Arcade”) <span class=”cate”><?php the_category(‘, ‘); ?></span> or if you … Read more

Displaying year once in category.php [duplicate]

Create your query for the category, and order by date $q = new WP_Query(‘category_name=acategory&orderby=date&order=DESC’); After that, while looping posts, save the year in a helper variable, shoing it only when changed: $year = 0; if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post(); $post_year = (int) get_the_time(‘Y’); if ( $post_year !== (int) $year … Read more