"Display Category Name In Wordpress"
Bootstrap 4.1.1 Snippet by Arjunverma

<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <div class="row"> <h2>Create your snippet's HTML, CSS and Javascript in the editor tabs</h2> </div> </div>
/*Basic Syntax to get Categories name*/ /* <?php $cat = get_the_category(); echo $cat[0]->cat_name; ?> */
add_shortcode("post","post"); function post(){ $args = array( 'post_type' => 'slider', 'post_status' => 'publish', 'category_name' => '', 'posts_per_page' => 5, 'orderby' => 'date', 'order' => 'DEC', ); $arr_posts = new WP_Query( $args ); if ( $arr_posts->have_posts() ) : while ( $arr_posts->have_posts() ) : $arr_posts->the_post(); ?> <article class="thumb" id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <?php if ( has_post_thumbnail() ) : the_post_thumbnail(); endif; ?> <header class="entry-header"> <h1 class="entry-title"><?php the_title(); ?></h1> </header> <span><?php $cat = get_the_category(); echo $cat[0]->cat_name; ?></span> <div class="entry-content"> <?php the_excerpt(); ?> <a href="<?php the_permalink(); ?>">Read More</a> </div> <span><?php echo the_posts_pagination();?></span> </article> <?php endwhile; endif; }

Related: See More


Questions / Comments: