Post Loop Category first show parent then child

The following code will print out all the top-level categories first and then all the non-top-level categories, if that’s what u wanted. <?php $categories = get_the_category( get_the_ID() ); if( $categories ){ $output = “”; //display all the top-level categories first foreach ($categories as $category) { if( !$category->parent ){ $output .= ‘<a href=”‘ . esc_url( get_category_link( … Read more

add_settings_field (exclude categories->reading) wp_category_checklist

FWIW, to get this to work as intended, I went ahead with the wp_dropdown_categories function approach, settling for a js on-load hack to facilitate selection of currently excluded categories witin the dropdown. /* Add Settings Field –“Exclude Categories”– under options-reading.php page */ class Add_Settings_Field { public function __construct() { add_filter( ‘admin_init’ , array( &$this , … Read more

Get categories of queried posts

You need a: array of post id ( ok ) array of category id ( not yet ) array of category id/name with unique value ( not yet ) using wp_get_posts_categories( $post_id ); returns an array of category id, so you can loop your $ids calling this function to collect all categories id. with the … Read more

How to add icon over specific thumb

The implementation can be purely CSS, and depends on your specific HTML markup. However, the class you’ll need to target is supplied by the post_class() template tag. Let’s say you have something like the following, basic markup: <div id=”post-<?php the_ID(); ?>” <?php post_class(); ?>> <div class=”post-title”> <img … /> <h1><?php the_title(); ?></h1> </div> <!– Etc. … Read more

How could I write a get_categories_by_year() function?

I would do this with SQL query. Doing it in PHP will be a little bit slow, I guess. This function should do the job: function get_categories_from_year($year) { $sql = “select term.* from {$wpdb->terms} term inner join {$wpdb->term_taxonomy} tax on (term.term_id = tax.term_id) inner join {$wpdb->term_relationships} relation on (tax.term_taxonomy_id = relation.term_taxonomy_id) inner join {$wpdb->posts} post … Read more