Display category name on featured image in wordpress excerpt
use get_the_category() <?php foreach((get_the_category()) as $category) { echo $category->cat_name . ‘ ‘; } ?> Note: It will return a list of categories if there are more than one category
use get_the_category() <?php foreach((get_the_category()) as $category) { echo $category->cat_name . ‘ ‘; } ?> Note: It will return a list of categories if there are more than one category
WordPress already has an API you can extend, and a class for querying posts! For example: // when the rest_api_init action/event happens add_action( ‘rest_api_init’, function () { // register a new endpoint register_rest_route( ‘mohnish/v1’, ‘/posts/’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘mohnish_awesome_func’, // that calls this function ) ); } ); // this is whats … Read more
There are various ways to achieve what you are talking about within WordPress. 1) Multisite/Network. For each City (or whatever your top level is), you create a new site with a default theme. This allows for either www.website.com/paris/music or paris.website.com/music, depending on your requirements. Introductory info on Network sites Creating a WordPress Network 2) Write … Read more
Your category.php should have two loops — one for stickies, one for regular posts: <?php // get sticky posts array $sticky = get_option(‘sticky_posts’); // First WP_Query arguments $args = array( // include stickies ‘post__in’ => $sticky ); $query = new WP_Query( $args ); // First loop for stickies only if ( $query->have_posts() ) : while … Read more
Ok, I resolved it. In a variable product $_product->get_id() is not of ID the product else is the ID only of these variation at cart. Then, in these loop can found the id of product in the variable $cart_item[‘product_id’] We can use it: $the_product = wc_get_product( $cart_item[‘product_id’] ); $array_cat = $the_product->get_category_ids(); Regards
Normally the category url is www.homepage.com/category/slug-of-the-category/. You can find all categories and their url under Posts -> Categories in the backend of WordPress. So you don’t have to create a page, because the pages already exist.
By default it will add current-cat class to the current category item. If we need to change that, we can use: ‘current_category’ (int|array) ID of category, or array of IDs of categories, that should get the ‘current-cat’ class. Default 0. as mentioned in the dev docs for wp_list_categories() arguments: Then we can style it as … Read more
wp_dropdown_categories() will list by id by default. It utilizes get_terms() as well, and provides a hook to toward the end if you wish to filter the html of $output further than the parameters allow. (I’ve added the source below). It has the following parameters: ‘show_option_all’ (string) Text to display for showing all categories. ‘show_option_none’ (string) … Read more
What you are looking for is the_post_thumbnail();. You should do something like this: <?php if ( has_post_thumbnail() ) : ?> <?php the_post_thumbnail(); ?> <?php endif; ?> More information can be found here.
add_action( ‘save_post’, ‘add_tag_based_on_category’ ); function add_tag_based_on_category( $post_id ) { $args = array( ‘fields’ => ‘names’ ); $categories = wp_get_post_categories( $post_id, $args ); $cat_names = implode( ‘, ‘, $categories ); wp_set_post_tags( $post_id, $cat_names, true ); }