Class active for Archive link – looped out

One way to do this is to get the current object ID with get_queried_object_id() and compare it against the category term ID inside the foreach loop. E.g. $current_object_id = get_queried_object_id(); foreach (get_categories() as $category) { $classes=””; if ( $category->term_id === $current_object_id ) { $classes .= ‘selected’; } printf( ‘<a class=”%s” href=”%s”>%s</a>’, $classes, get_category_link($category->term_id), $category->name ); … Read more

How to make 2 tag feeds show up on 1 page?

Your best bet is to create a page template with the following code. Also you will need to decide if you will use a tag or category. The code below assumes you are using a category. <div class=”news”> <?php //The Query wp_query(‘showposts=5&category_name=News’); //The Loop if ( have_posts() ) : while ( have_posts() ) : the_post(); … Read more

How can i insert term in a specific language of Polylang?

You can actually make it this way: $cat1 = wp_insert_term( ‘Cat1’, ‘category’, [‘slug’ => ‘slug-cat1’], ); $agenda = wp_insert_term( ‘Agenda’, ‘category’, [ ‘slug’ => ‘slug-agenda’, ‘parent’=> term_exists( ‘Cat1’, ‘category’ )[‘term_id’], ], ); pll_set_term_language($cat1[‘term_id’], ‘fr’); pll_set_term_language($agenda[‘term_id’], ‘de’); Here is link to Polylang Function reference: https://polylang.wordpress.com/documentation/documentation-for-developers/functions-reference/

Making the category & tag Description textarea bigger

Hook onto the edit-tags page and insert some additional styling to adjust the textarea, the ID remains the same for post tags, categories and i think other taxonomies to.. Adjust CSS for taxonomy management page Example only, tailor to suit you needs. add_action( ‘admin_print_styles-edit-tags.php’, ‘resize_description_field’ ); function resize_description_field() { ?> <style type=”text/css”> textarea#tag-description { height:300px!important; … Read more

query order by category

This should limit the posts pulled in the new WP_Query instance to the currently selected category or the first category of the current post. global $wp_query; $sidebar_query_vars = array(‘orderby’ => ‘rand’, ‘showposts’ => 12); if(is_category()) { $sidebar_query_vars[‘cat’] = $wp_query->get_queried_object()->term_id; } elseif (is_single()) { $categories = (get_the_terms($wp_query->get_queried_object_id(), ‘category’)); if(is_array($categories)) { $first_cat = array_shift($categories); $sidebar_query_vars[‘cat’] = $first_cat->term_id; … Read more

Modify WordPress SQL Query to pull from within a category

You need to make sure that the $currentcat variable is set before this query runs. This should be the id of the category you want to pull top posts from. $sql = “SELECT count(mr.post_ID) AS totHits, p.ID, p.post_title FROM $wpdb->posts p JOIN {$wpdb->prefix}kf_most_read mr ON mr.post_ID = p.ID JOIN {$wpdb->prefix}term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) WHERE … Read more

one category template for multiple categories

First paste this code in your theme’s functions.php function post_is_in_descendant_category( $cats, $_post = null ){ foreach ( (array) $cats as $cat ) { // get_term_children() accepts integer ID only $descendants = get_term_children( (int) $cat, ‘category’); if ( $descendants && in_category( $descendants, $_post ) ) return true; } return false; } then on your category.php or … Read more