0

function dtwd_special_show_sports($atts){
 $atts = shortcode_atts(
  array(
   'post_type' => 'post',
   'tax_name' => '',
   'posts_per_page' => '-1',
  ),
  $atts,
  'show_post'
 );
   ob_start(); 
 if(is_front_page()) {
  $paged = (get_query_var('page')) ? get_query_var('page') : 1;
 }else {
  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
 }
   //$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $query = new WP_Query( array(
        'post_type' => $atts['post_type'],
        //'category_name' => $atts['tax_name'],
        'posts_per_page' => $atts['posts_per_page'],
        'paged' => $paged,
    ) );
    if ( $query->have_posts() ) {
  ?>
  <div class="row">
  <?php
$taxonomy = $atts['tax_name'];
$terms = get_terms($taxonomy, array(
'orderby' => 'count',
'hide_empty' => true
)
);
$hierarchy = _get_term_hierarchy($taxonomy);
foreach($terms as $term) {
if($term->parent) {
continue;
}
echo $term->name.'<br>';
if($hierarchy[$term->term_id]) {
foreach($hierarchy[$term->term_id] as $child) {
$child = get_term($child, $atts['tax_name']);
echo ' — '.$child->name.'('.$child->count.')<br>';
}
}
}
?>
  <?php
     while ( $query->have_posts() ) : $query->the_post();
  $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID));?>
  <div class="col-6">    		
   <a href='javascript:void(0)' class='post-popup popmake-1522'>
    <div class="box-image" style="background-image: url('<?php echo $image; ?>');"></div>	
   <div class="title-box">
    <h5><?php the_title() ?></h5>
    <div class="col-6">
     <?php if(get_field('north')!=''){ ?>
      <h6>North</h6>
     <p><strong><?php the_field('north'); ?></strong></p>
     <?php } ?>
    </div>
    <div class="col-6" style="text-align: right;">
     <?php if(get_field('south')!=''){ ?>
      <h6>South</h6>
     <p><strong><?php the_field('south'); ?></strong></p>
     <?php } ?>
    </div>
    </div>
    </a>
   <div class="content-div">
   <h2><?php the_title() ?></h2>
   <hr/>
   <?php the_content();?>
   </div>
  </div>
     <?php endwhile;
     ?>
  </div>
     <nav class="custom_nav">
      <?php wp_pagenavi( array( 'query' => $query ) ); ?>
  </nav>
 <?php }?>
   <?php $specialsearch = ob_get_clean();
return $specialsearch;
}
add_shortcode('show_sports', 'dtwd_special_show_sports');

Jagdish Sarma Asked question October 16, 2020
Add a Comment