• My project uses Simple Tags plugin to generate a tag cloud for frontend with urls like ‘mysite.com/tag/<tag-name>’. I have a custom object type called ‘tours’ in the project. On clicking a particular tag cloud link , i want tours tagged with that particular tag to be displayed and paginated using wp_pagenavi plugin. Right now, i am only able to see the first page of tours filtered by tags. On going to page 2 i get a 404 error. The tours for a tag are displayed using a file called tag.php in the root of my custom theme folder.

    I know very little about taxonomies .I want to know if the ‘post_tag’ taxonomy is relevant here. Please help me solve this problem. The site is https://abgtours.ru . Any help will be appreciated.

    The code of tag.php is

    <?php
    /**
     * The template used to display Tag Archive pages
     *
     * @package WordPress
     * @subpackage Twenty_Eleven
     * @since Twenty Eleven 1.0
    
    Template Name: Tag Page*/
    get_header(); ?>
    <?php //print_r($_REQUEST); echo single_tag_title('',false);
    $url=urldecode($_SERVER['REQUEST_URI']);
    //$matches=array();
    $url_array=explode('/', $url);
    
    $idx=0;
    $v1=0;
    
    foreach($url_array as $w)
    {
    	if($w==='tag')
    	{
    		break;
    	}
    	$idx++;
    }
    
    foreach($url_array as $w)
    {
    	if($w==='page')
    	{
    		break;
    	}
    	$v1++;
    }
    
    //echo "<b>".$url_array[$idx+1]."</b>";
    
    $term=$url_array[$idx+1];
    
    $page=$url_array[$v1+1];
    
    //$mp = query_posts("taxonomy=post_tag&post_type=tours&post_tag='".$term."'&order=DESC&showposts=10");
    //$mp = query_posts("taxonomy=post_tag&post_type=tours&order=DESC&showposts=10");
    
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args=array(
       'post_type'=>'tours',
       'taxonomy' => 'post_tag',
       'post_tag'=>$term,
       'posts_per_page' =>10,
       'paged'=>$paged
    );
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query($args);
    
    //die;
    ?>
    
    <div class="content">
      <div class="main">
        <div class="leftpart">
        <div class="navigation">
       <?php if(function_exists('bcn_display'))
        {
            bcn_display();
        }?>
    
          </div>
          <div class="tourslist">
          	<div>
    
            <ul>
            <li class="tourslist_li" style="list-style:none">
                <div class="tourheadding" style="background:none">
                  <div class="headdingleft">
                    <h3>
                      <?php echo "Архив Тегов: ". $term; ?>
                       </h3>
                   </div>
                  <div class="tourprice helvetica-neue-light">
                    &nbsp;
                  </div>
                </div>
                </li>
              </ul>
    
            </div>
            <?php if ( $wp_query->have_posts() ) : ?>
            <ul>
              <?php
    		 while ( $wp_query->have_posts() ) :  $wp_query->the_post(); 
    
    		 //global $post;
    		 //$pst_id = $post->ID;
    
    		 ?>
              <?php $meta = get_post_meta($post->ID, 'abg_tours_download_brochure', true); ?>
              <?php $tourimg = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ) ,'list-thumb'); ?>
              <li class="tourslist_li" style="list-style:none">
                <div class="tourheadding">
                  <div class="headdingleft">
                    <h3><a href="<?php the_permalink(); ?>">
                      <?php the_title();  ?>
                      </a> </h3>
                    <p><?php echo get_post_meta($post->ID,'abg_tours_days_nights',true); ?></p>
                  </div>
                  <div class="tourprice helvetica-neue-light">
                    <?php if(get_post_meta($post->ID,'abg_tours_price',true)) { ?>
                    <img src="<?php bloginfo('template_url'); ?>/images/from_ru.png" /> $<?php echo get_post_meta($post->ID,'abg_tours_price',true);?>
                    <?php } ?>
                  </div>
                </div>
                <div class="toursdetail">
                   <?php if($tourimg[0]) {?><div class="placeimage"><a href="<?php the_permalink(); ?>"> <span class="newimg"></span>
                    <img src="<?php echo $tourimg[0]; ?>" width="241" height="139" alt="" /> </a> </div><?php } ?>
                  <div class="<?php if($tourimg[0]) {?>toursright<?php }else{ ?>toursright2<?php } ?>">
                    <div class="citylist">
                      <p><strong>Тип Тура:</strong></p>
                      <p>
                        <?php $terms = get_the_terms($post->ID, 'tourstype');
    				  		$types = '';
    					  foreach($terms as $tourtype ){
    						  if($tourtype->taxonomy == 'tourstype' ){
    							 $types[] = $tourtype->name;
    						  }
    					  }
    
    					 echo implode(", ",$types);
    
    				     ?>
                      </p>
                    </div>
                    <div class="citylist">
                      <p><strong>Города:</strong></p>
                      <p>
                        <?php $terms1 = get_the_terms($post->ID, 'tourscat');
    				  $cities = '';
    				  foreach($terms1 as $tourcity ){
    					 $cities[] = $tourcity->name;
      				  }
    					 echo implode(", ",$cities);
    				     ?>
                      </p>
                    </div>
                    <div class="description">
                      <h5>Описание:</h5>
                      <p><?php echo substr(get_the_content(),0,145); ?></p>
                    </div>
                    <div class="tourshare"> <span class='st_email_large' st_title='<?php the_title(); ?>' st_url='<?php the_permalink(); ?>' displayText='Отправить имайл' style="float:left; padding-top:6px !important;">Отправить имайл</span> <span class="float-left" style="padding-top:5px !important;">|</span> <span class='st_sharethis' st_title='<?php the_title(); ?>' st_url='<?php the_permalink(); ?>' style="padding-left:-10px;" displayText='Поделиться'></span> <span class="float-left" style="padding-top:5px !important;">|</span> <a href="<?php the_permalink(); ?>" class="moredetail">Детали Тура</a> </div>
                  </div>
                </div>
              </li>
              <!-- #post-<?php the_ID(); ?> -->
    
              <?php endwhile; // end of the loop. ?>
            </ul>
            <?php else : ?>
            <ul>
              <li class="tourslist_li" style="list-style:none; min-height:200px;">
                <article id="post-0" class="post no-results not-found">
                  <header class="entry-header">
                    <h1 class="entry-title">
                      <?php _e( 'Nothing Found', 'twentyeleven' ); ?>
                    </h1>
                  </header>
                  <!-- .entry-header -->
    
                  <div class="entry-content">
                    <p>
                      <?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?>
                    </p>
                    <?php get_search_form(); ?>
                  </div>
                  <!-- .entry-content -->
                </article>
                <!-- #post-0 -->
              </li>
            </ul>
            <?php endif;
    
     ?>
          </div>
          <div class="pagi" style="position:relative">
            <?php  //kriesi_pagination(); ?>
            <?php wp_pagenavi(array( 'query' => $wp_query ));
    		$wp_query = null;
    $wp_query = $temp;
    wp_reset_query();
    		?>
          </div>
        </div>
        <?php get_sidebar(); ?>
      </div>
    </div>
    
    <?php get_footer(); ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    On tag pages you want only show posts of the “tours” post type?

    Thread Starter pdeb

    (@pdeb)

    Yes, that is correct

    Moderator keesiemeijer

    (@keesiemeijer)

    Try it without a new WP_Query($args) and a normal main loop: https://pastebin.com/fRWYT6E1

    And with this in your theme’s functions.php:

    function my_post_queries( $query ) {
    	// do not alter the query on wp-admin pages and only alter it if it's the main query
    	if (!is_admin() && $query->is_main_query()){
    
    		// alter the query for tag archive pages
    		if(is_tag()){
    			$query->set('posts_per_page', 10);
    			$query->set('post_type', array('tours'));
    		}
    	}
    }
    
    add_action( 'pre_get_posts', 'my_post_queries' );

    Thread Starter pdeb

    (@pdeb)

    It seems to be working.. thank you..

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘custom tag cloud and pagination problem’ is closed to new replies.