Hello reader's, we discussed about "How to get a category in wordpress".
In the below code gallery is the custom post type. For this you can create a taxonomy-gallery-category.php file. You can put the below code into this file.
<?php
/**
* This page shows list of all tour-region related to particular catgeory
*/
get_header();
global $post;
global $wpdb;
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
?>
<ul class="clearfix">
<?php
$post_type = 'gallery';
$args = array(
'post_type' => $post_type, /*This is where you should put your Post Type */
'posts_per_page' => -1,
'post_status' => 'publish',
//'paged' => $page,
'tax_query' => array(
array(
'taxonomy' => $term->taxonomy,
'field' => $term->slug,
'terms' => $term->term_id,
'include_children' => false
)
)
);
$query = new WP_Query( $args );
$round = count($query->posts);
if ( $query->have_posts() )
{
while ( $query->have_posts() )
{
$query->the_post();
$thumb_img = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'gallery-img-all');
$post_img = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
if( $post_img != '' ) :
echo "<li>";
echo "<a class='fancybox' href='". $post_img[0] ."' data-fancybox-group='gallery' title='". get_the_title($post->ID) ."' >";
echo "<div class='share_outer'></div>";
echo "<img src='". $thumb_img[0] ."' />";
echo "</a>";
echo "</li>";
endif; // end if
}
}
else
{
echo "No posts fount !!!";
}
wp_reset_postdata(); ?>
</ul>
0 Comment(s)