Articles of get the category

Unable to differentiate between two categories under custom post type on single.php

I have created A custom post type as mentioned in my older question When I try to use get_the_category() function to retrieve the category of the post(if it is symphony or noir). It returns “Array”. How can I keep the posts under the two categories separate which do not interfere in the pagination of one […]

List recent posts with link to first category

I’m looking to get a list of the recent 4 posts and with it a link the the first (and only) category that the post is in. $args = array( ‘numberposts’ => ‘4’, ‘offset’ => ‘0’ ); $recent_posts = wp_get_recent_posts($args); foreach ($recent_posts as $recent) { echo ‘<li>’ ‘<a href=”‘ . get_permalink($recent[“ID”]) . ‘” class=”previous-post-thum”>’ get_the_post_thumbnail($recent[“ID”], […]

How to exclude a category name from showing?

So I’m trying this code: <?php global $post; $my_query = new WP_Query(‘showposts=8&category_name=featured’); while ($my_query->have_posts()): $my_query->the_post(); $do_not_duplicate = $post->ID; $category = get_the_category(); $content = get_the_content(); $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID) , ‘main-thumbs’); $tn_id = get_post_thumbnail_id($post->ID); $img = wp_get_attachment_image_src($tn_id, ‘main-thumbs’); $width = $img[1]; $height = $img[2]; ?> …. <div class=”cat-square <?php echo esc_html($category[0]->slug) ?>”> with this, I can style […]

Display data when category is empty

I have the following code which inserts data to the bottom of a product category. It works perfectly however it only displays when a product is actually in the category, id like it to display in empty categories too. What am I doing wrong ? add_action( ‘woocommerce_after_shop_loop’, ‘wpm_product_cat_archive_add_meta’ ); function wpm_product_cat_archive_add_meta() { $t_id = get_queried_object()->term_id; […]

Insert post's category name into thumbnail string

Hopefully a simple question. I’ve added several post thumbnail sizes to functions.php using add_image_size. They are each named exactly like a post category. I would like to find a way of making each post call the specific thumbnail size assigned to it’s category. The best way I can imagine doing it is by inserting the […]

How to get the current category with custom posts

If I go to: domain.example/category/skydancers-en-blikvangers/ I want to get all the posts in the current category for skydancers-en-blikvangers, I know I can hard code the category but this needs to be a dynamic template. So if I go to category/other-category that needs to work as well. Category.php: <div class=”container”> <div class=”row”> <div class=”col-md-12″> <div class=”jumbotron”> […]

Getting key value of WP_Term object in wordpress

How I can get from php on wordpress to a value of WP_Term object. I am using the next code to get the object: $queried_object = get_the_category( get_queried_object_id()); But this return an Array like this. Array ( [0] => WP_Term Object ( [term_id] => 12 [name] => Argentina … ) ) How I can get […]

get_the_category listing in hierarchial order

Hello at the moment I’m wondering how I would be able to make this work to post in Hierarchical order within the post loop. <?php foreach ((get_the_category()) as $childcat) { if (cat_is_ancestor_of(’42’, $childcat)) { echo ‘<li> <a href=”‘.get_category_link($childcat->cat_ID).'”>’; echo $childcat->cat_name . ‘</a> </li>’; } } ?> I would like it to output as such: Parent […]

How to exclude specific category from the get_the_category(); array

In my loop I’ve added: <?php $categories = get_the_category(); $separator = ‘ ‘; $output = ”; if($categories){ foreach($categories as $category) { $output .= ‘<span class=”post-category-info”><a href=”‘.get_category_link( $category->term_id ).'” title=”‘ . esc_attr( sprintf( __( “View all posts in %s” ), $category->name ) ) . ‘”>’.$category->cat_name.'</a></span>’.$separator; } echo trim($output, $separator); } ?> to display all the categories […]

Output the text before category

I need to output the text before the_category. In result, it should be something like Posted on September 20, 2014 IN MyCategory Here I use the_time(‘F j, Y’) and start from here I use the_category(). Word “in” should be inside the_category and before words “MyCategory”. For example, for the_date I can use $before to place […]