php - Use the same page for multiple taxonomies -
php - Use the same page for multiple taxonomies -
i need utilize same page different taxonomies , terms. how can retrieve taxonomies , terms url , run same page i want?
the query should run through url since not using forms. when user clicks on link, new page should opened archive of posts having custom post type, taxonomy , taxonomy terms specified in url.
this code have right now:
<? /* * template name: activities template * description: template activties restaurants, pubs, etc. */ ?> <?php $options = get_option('mh_options'); ?> <?php get_header(); ?> <?php if ( get_query_var('paged') ) {$paged = get_query_var('paged');} if ( get_query_var('page') ) {$paged = get_query_var('page');} $args = array( 'post_type' => 'activties', 'tax_query' => array( array( 'taxonomy' => 'restaurants', 'field' => 'slug', 'terms' => 'italian' ), 'paged' => $paged ) ); query_posts( $args ); ?> <div class="wrapper clearfix"> <div class="main"> <div class="content <?php mh_content_class(); ?>"> <?php mh_before_page_content(); ?> <?php dynamic_sidebar('pages-1'); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <!-- <?php the_content(); ?> --> <article <?php post_class(); ?>> <div class="loop-wrap loop-layout2"> <div class="clearfix"> <div class="loop-thumb"> <a href="<?php the_permalink(); ?>"> <?php if( get_field('business_logo') ): ?> <?php $image = wp_get_attachment_image_src(get_field('business_logo'), 'loop'); ?> <img src="<?php echo $image[0]; ?>" alt="<?php the_field('business_logo');?>" data-thumb="<?php echo $thumb[0]; ?>" /> <?php else: echo '<img src="' . get_template_directory_uri() . '/images/noimage_300x225.png' . '" alt="no picture" />'; ?> <?php endif; ?> </a> </div> <div class="loop-content"> <header> <h3 class="loop-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h3> </header> <?php if (get_field('business_description')): ?> <?php $text_to_trim = get_field('business_description'); echo '<div class="mh-excerpt">'. davide_excerpt($text_to_trim) . '</div>' . "\n" ; ?> <?php endif; ?> <?php if (get_field('business_paying_desc')): ?> <?php $text_to_trim = get_field('business_paying_desc'); echo '<div class="mh-excerpt">'. davide_excerpt($text_to_trim) . '</div>' . "\n" ; ?> <?php endif; ?> </div> </div> </div> </article> <?php dynamic_sidebar('pages-2'); ?> <?php endwhile; ?> <!-- <?php wp_reset_postdata(); ?> --> <?php wp_reset_query(); ?> <?php if (isset($options['comments_pages']) ? $options['comments_pages'] : false) : ?> <section> <?php comments_template(); ?> </section> <?php endif; ?> <?php endif; ?> </div> <?php get_sidebar(); ?> </div> <?php mh_second_sb(); ?> </div> <?php get_footer(); ?>
edit
after few days, found solution going post, has got issue: cannot see list of posts if post has got multiple terms (more 1 term basically) selected checkboxes when created or edited.
this taxonomy.php file
<?php $post = $wp_query->post; /*$catmerc = array('restaurants','pubs', 'the-pizzerias', 'bars', 'cafes', 'nightlife-clubs', 'shopping', 'the-coffeeshops');*/ $catmerc = array('the-restaurants', 'the-coffeeshops', 'the-pizzerias', 'shopping', 'nightlife-clubs', 'cafes', 'bars', 'pubs'); $termsobjects = wp_get_object_terms($post->id, $catmerc); //assuming post has 1 category, if theres more homecoming multiple objects in it's homecoming array: $currentcustomcat = $termsobjects[0]->slug; $currentcatmerc = get_query_var('taxonomy'); //you can have 'name' instead of 'slug' if helps $customcatarray = array('american-pubs-exclusive5', 'american-pubs-in-town', 'beer-houses-exclusive5', 'beer-houses-in-town', 'free-joints-exclusive5', 'free-joints-in-town', 'local-atmosphere-exclusive5', 'local-atmosphere-in-town', 'spanish-atmosphere-exclusive5', 'spanish-atmosphere-in-town', 'take-away-exclusive5', 'take-away-in-town', 'traditional-dutch-exclusive5', 'traditional-dutch-in-town', 'african-exclusive-5', 'african-in-town', 'argentinian-restaurants-exclusive5', 'argentinian-restaurants-in-town',' asian-restaurants-exclusive5', 'asian-restaurants-in-town', 'dutch-restaurants-exclusive5', 'dutch-restaurants-in-town', 'french-restaurants-exclusive5', 'french-restaurants-in-town', 'italian-restaurants-exclusive5', 'italian-restaurants-in-town', 'seafood-restaurants-exclusive5', 'seafood-restaurants-in-town', 'spanish-restaurants-exclusive5', 'spanish-restaurants-in-town', 'cocktail-bars-exclusive5', 'cocktail-bars-in-town', 'disco-bars-exclusive5', 'disco-bars-in-town', 'dutch-bars-exclusive5', 'dutch-bars-in-town', 'internet-cafes-exclusive5', 'internet-cafes-in-town', 'lounge-bars-exclusive5', 'lounge-bars-in-town', 'art-cafes-exclusive5', 'art-cafes-in-town', 'breakfast-lunch-exclusive5','breakfast-lunch-in-town', 'famous-cafes-exclusive5', 'famous-cafes-in-town', 'fashion-cafes-exclusive5', 'fashion-cafes-in-town', 'timeout-exclusive5', 'timeout-in-town', 'best-boutiques-exclusive5','best-boutiques-in-town', 'famous-brands-exclusive5', 'famous-brands-in-town', 'sportswear-exclusive5', 'sportswear-in-town', 'the-pizzerias-with-table-service-in-town', 'the-pizzerias-with-table-service-exclusive5', 'the-pizzerias-takeway-in-town', 'the-pizzerias-takeaway-exclusive5', 'the-coffeeshops-in-town', 'the-coffeeshops-exclusive5'); if (in_array($currentcatmerc, $catmerc) && in_array($currentcustomcat, $customcatarray) ) {include(templatepath.'/page_activities.php'); } /*if( $currentcustomcat == "italian" || $currentcustomcat == "local-atmosphere"){ //it matched, stuff here {include(templatepath.'/single_activities.php'); } }*/ else { /*include(templatepath.'/page.php'); */ $pagelink=get_page_link (get_page_by_title( 'homepage' )); header("location: $pagelink",true,301); } ?>
and page_activities.php file
<?php if ( get_query_var('paged') ) {$paged = get_query_var('paged');} if ( get_query_var('page') ) {$paged = get_query_var('page');} $args = array( 'post_type' => 'activities', 'tax_query' => array( array( 'taxonomy' => $currentcatmerc, 'field' => 'slug', 'terms' => $currentcustomcat ), 'paged' => $paged, 'posts_per_page'=>'10', ) ); $args2 = array( 'post_type' => 'activities', 'paged' => $paged ); query_posts( $args ); ?> <div class="wrapper clearfix"> <div class="main"> <div class="content <?php mh_content_class(); ?>"> <?php mh_before_page_content(); ?> <?php dynamic_sidebar('pages-1'); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <!-- <?php the_content(); ?> --> <article <?php post_class(); ?>> <div class="loop-wrap loop-layout2"> <div class="clearfix"> <div class="loop-thumb"> <a href="<?php the_permalink(); ?>"> <?php if( get_field('business_logo') ): ?> <?php $image = wp_get_attachment_image_src(get_field('business_logo'), 'loop'); ?> <img src="<?php echo $image[0]; ?>" alt="<?php the_field('business_logo');?>" data-thumb="<?php echo $thumb[0]; ?>" /> <?php else: echo '<img src="' . get_template_directory_uri() . '/images/noimage_300x225.png' . '" alt="no picture" />'; ?> <?php endif; ?> </a> </div> <div class="loop-content"> <header> <h3 class="loop-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h3> </header> <?php if (get_field('business_description')): ?> <?php $text_to_trim = get_field('business_description'); echo '<div class="mh-excerpt">'. davide_excerpt($text_to_trim) . '</div>' . "\n" ; ?> <?php endif; ?> <?php if (get_field('business_paying_desc')): ?> <?php $text_to_trim = get_field('business_paying_desc'); echo '<div class="mh-excerpt">'. davide_excerpt($text_to_trim) . '</div>' . "\n" ; ?> <?php endif; ?> </div> </div> </div> </article> <?php dynamic_sidebar('pages-2'); ?> <?php endwhile; ?> <!-- <?php wp_reset_postdata(); ?> --> <?php wp_reset_query(); ?> <?php endif; ?> <div class="sb-widget home-2 home-wide"> <h4 class="widget-title">latest updates</h4> <ul class="cp-widget clearfix"> <?php query_posts( $args2 ); ?> <?php if (have_posts()) : $i=1; while (have_posts() && ($i<=10)) : the_post(); ?> <li class="cp-wrap cp-small clearfix"> <div class="cp-thumb"> <a href="<?php the_permalink(); ?>"> <?php if( get_field('business_logo') ): ?> <?php $image = wp_get_attachment_image_src(get_field('business_logo'), 'cp_small'); ?> <img width="70" height="53" src="<?php echo $image[0]; ?>" alt="<?php the_field('business_logo');?>" data-thumb="<?php echo $thumb[0]; ?>" class="attachment-cp_small wp-post-image" /> <?php endif; ?> </a></div> <div class="cp-data"> <p class="cp-widget-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></p> </div> </li> <?php $i++; ?> <?php endwhile; ?> <?php wp_reset_query(); ?> <?php endif;?> </ul> </div> <div class="sb-widget home-2 home-wide"> <?php echo do_shortcode('[rev_slider 620_100]'); ?> </div> <?php if (isset($options['comments_pages']) ? $options['comments_pages'] : false) : ?> <section> <?php comments_template(); ?> </section> <?php endif; ?> </div> <?php get_sidebar(); ?> </div> <?php mh_second_sb(); ?> </div> <?php get_footer(); ?>
pls help me because clueless. 1 news if check array print_r($termsobjects[0]); can see output.
i guess should utilize foreach somehow, don't know set hands on.
thank can help me this.
regards
..your question bit broad...but gist of need do:
to pull variables url
$query = explode('&', $_server['query_string']); $params = array(); foreach( $query $param ){ list($name, $value) = explode('=', $param); $params[urldecode($name)][] = urldecode($value); }
now have params array i've no thought urls like, ' postterm1 = italian, postterm2 = chinese, etc
$array['taxquery'] = array(); $array['taxquery'][relation]= 'or'; foreach ($param $key=>$value) { $array['taxquery'][]=array( 'taxonomy' => 'restaurants', 'field' => 'slug', 'terms' => $value ); }
this build query see below, delete 'tax_query' array , insert var $array instead. should work haven't tested play around format if needed.
your custom query (i think want multi taxonomies not all?) utilize wp_query:
$args= array( 'post_type' => 'activties', 'tax_query' => array( 'relation'=>'or', array( 'taxonomy' => 'restaurants', 'field' => 'slug', 'terms' => 'italian' ), array( 'taxonomy' => 'restaurants', 'field' => 'slug', 'terms' => 'chinese' ) ), );
ref: http://codex.wordpress.org/class_reference/wp_query
php wordpress custom-taxonomy
Comments
Post a Comment