Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This code for category
- ------------------------
- <?php the_category(', '); ?>
- <?php wp_dropdown_categories('class=cat_select'); ?>
- <?php the_taxonomies(array('template' => '% %l')); ?>
- <?php echo get_the_term_list( $post->ID, 'project_cat', '', '', '' );?>
- //get parent taxonomy id from taxonomy id child
- ------------------------------------
- $subCategory = get_term_by( 'id', $search_region, 'houseboats_cat' );
- $mainCategory = get_term_by( 'id', $subCategory->parent, 'houseboats_cat' );
- $parent_cat = $mainCategory->term_id;
- // get taxonomy terms for parent and child separately
- -------------------------------
- foreach( get_terms( 'products-category', array( 'hide_empty' => false, 'parent' => 0 ) ) as $parent_term ) {
- // display top level term name
- echo $parent_term->name . '<br>';
- foreach( get_terms( 'products-category', array( 'hide_empty' => false, 'parent' => $parent_term->term_id ) ) as $child_term ) {
- // display name of all childs of the parent term
- echo $child_term->name . '<br>';
- }
- }
- // category feature image ACF
- ---------------------------
- <?php
- $term = get_queried_object();
- $image = get_field('category_featured_image', $term);
- if( $image ): ?>
- <div class="single_blog_thumb fix">
- <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['title']; ?>" />
- <div class="page_title_area fix">
- <h1><?php single_cat_title(); ?></h1>
- </div>
- </div>
- <?php else : ?>
- <div class="defaltpage_title_area fix">
- <h1><?php single_cat_title(); ?></h1>
- </div>
- <?php endif; ?>
- //This code for category without link
- --------------------------------------
- <?php $terms_as_text = get_the_term_list( $post->ID, 'product_specialties', '', ', ', '' ) ; echo strip_tags($terms_as_text); ?>
- //This code for getting taxonomy with ul>li>a
- ----------------------------------
- <?php
- $taxonomy = 'project_cat';
- $terms = get_terms('project_cat');
- ?>
- <ul id="home_links" class="fix">
- <?php
- foreach ($terms as $term) {
- $term_link = get_term_link( $term, 'project_cat' );
- if( is_wp_error( $term_link ) )
- continue;
- echo '<li><a href="' . $term_link . '">' . $term->name . '</a></li>';
- }
- ?>
- </ul>
- //This code for Taxonomy query
- ----------------------------------
- <?php $terms = get_terms( array(
- 'taxonomy' => 'representante_cat',
- 'hide_empty' => true,
- ) );
- if ( !empty( $terms ) && !is_wp_error( $terms ) ){
- foreach ( $terms as $term ) { ?>
- <option value="<?php echo $term->term_id; ?>" ><?php echo $term->slug; ?></option>
- <?php }
- } ?>
- //This code for Child Taxonomy query without parent name with alphabetic title order
- ------------------------------------------------------------------------------
- $taxonomy_name = 'houseboats_cat';
- $parent_terms = get_terms( $taxonomy_name, array( 'parent' => 0, 'orderby' => 'slug', 'hide_empty' => false ) );
- echo '<ul>';
- foreach ( $parent_terms as $pterm ) {
- //Get the Child terms
- $terms = get_terms( $taxonomy_name, array( 'parent' => $pterm->term_id, 'orderby' => 'slug', 'hide_empty' => false ) );
- foreach ( $terms as $term ) {
- echo '<li><a href="' . get_term_link( $term ) . '">' . $term->name . '</a></li>';
- }
- }
- echo '</ul>';
- How to order get_term_children output by alphabetic order
- --------------------------------------------------------
- <div class="get_term_child by_alphabetic_order">
- <?php
- $term_id = 20;
- $taxonomy_name = 'meeting_type';
- $termchildren = get_term_children( $term_id, $taxonomy_name );
- $children = array();
- foreach ($termchildren as $child) {
- $term = get_term_by( 'id', $child, $taxonomy_name );
- $children[$term->name] = $term;
- }
- ksort($children);?>
- <!-- now $children is alphabetized -->
- <select name='eventcats' id='eventcats' onchange='taclinkch(this.id)'>
- <option value=''>Select a Topic</option>
- <?php
- foreach ( $children as $child ) {
- $term = get_term_by( 'id', $child->term_id, $taxonomy_name );
- echo ' <option value="' . $term->term_id . '">' . $term->name . '</option>';
- } ?>
- </select>
- </div>
- // taxonomy query with pagination
- ------------------------------------------
- <div class="produtos_filter_result fix">
- <?php
- $taxonomy = 'produtos_cat';
- $number = 6; // number of terms to display per page
- // Setup:
- $page = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
- $offset = ( $page > 0 ) ? $number * ( $page - 1 ) : 1;
- $totalterms = wp_count_terms( $taxonomy, array( 'hide_empty' => TRUE ) );
- $totalpages = ceil( $totalterms / $number );
- $args = array(
- 'orderby' => 'name',
- 'order' => 'ASC',
- 'hide_empty' => true,
- 'number' => $number,
- 'offset' => $offset,
- );
- $terms = get_terms( $taxonomy, $args );
- foreach ( $terms as $term ){
- $term_link = get_term_link( $term );
- ?>
- <div class="cat_filter_result_item fix text-center">
- <div class="cat_filter_result_thumb fix">
- <img src="<?php the_field('catefory_photo_thumb', $term); ?>" alt="">
- </div>
- <div class="cat_filter_result_iconcat fix">
- <a href="<?php echo esc_url( $term_link ) ?>"><img src="<?php the_field('category_icon', $term); ?>" alt=""></a>
- <div class="filter_cat_title fix">
- <a href="<?php echo esc_url( $term_link ) ?>"><h5><?php echo $term->name; ?></h5></a>
- </div>
- </div>
- <div class="cat_filter_result_title fix">
- <a href="<?php echo esc_url( $term_link ) ?>"><h4>ConheƧa Mais</h4></a>
- </div>
- </div>
- <?php }
- ?>
- </div>
- <div class="produtos_paginationresult fix">
- <div class="mypagination_area text-center">
- <?php
- printf( '<nav class="pagination">%s</nav>',
- custom_page_navi( $totalpages, $page, 6, 0 )
- );
- ?>
- </div>
- </div>
- // this code for function.php
- function custom_page_navi( $totalpages, $page, $end_size, $mid_size )
- {
- $bignum = 999999999;
- if ( $totalpages <= 1 || $page > $totalpages ) return;
- return paginate_links( array(
- 'base' => str_replace( $bignum, '%#%', esc_url( get_pagenum_link( $bignum ) ) ),
- 'format' => '',
- 'current' => max( 1, $page ),
- 'total' => $totalpages,
- 'prev_text' => '<',
- 'next_text' => '>',
- 'type' => 'list',
- 'show_all' => false,
- 'end_size' => $end_size,
- 'mid_size' => $mid_size
- ) );
- }
- // select filter area caegory and jquery for get url and redirect to taxonomy page for query select option
- -----------------------------------------------------------------------------
- <form action="" id="cat_dorar_form" method="get">
- <div class="filter_choose_cat_area fix">
- <select name="cat_select" id="category-select" class="filter_catgory">
- <option value="">Selecione uma categoria</option>
- <?php
- $product_cats = get_terms( array(
- 'taxonomy' => 'produtos_cat',
- 'hide_empty' => true,
- ) );
- if ( ! empty( $product_cats ) && ! is_wp_error( $product_cats ) ){
- foreach ( $product_cats as $product_cat ) {
- if(!empty($_GET['cat_select'])){
- $product_id = $_GET['cat_select'];
- if($product_id == $product_cat->slug){
- $product_return = " selected='selected'";
- } else{
- $product_return = "";
- }
- }
- echo '<option value="'.$product_cat->slug.'" '.$product_return.' data-id="'.$product_cat->term_id.'">'.$product_cat->name.'</option>';
- }
- }
- ?>
- </select>
- </div>
- <div class="filter_submit fix">
- <input type="submit" value="Filtrar" name="pro-filt" class="filter_submitbtn" />
- </div>
- </form>
- // use this js
- --------
- jQuery(document).ready(function(){
- var linkase = '<?php echo site_url();?>/produtos-category/';
- var linslug;
- jQuery('select#category-select').change(function() {
- linslug = jQuery(this).val();
- });
- jQuery("#cat_dorar_form").submit(function(e) {
- e.preventDefault();
- var jakhusi = linkase+linslug;
- window.location.replace(jakhusi);
- });
- });
- // or use this js its take cat id and name to url
- ---------------------------------------
- jQuery(document).ready(function(){
- var linkase = '<?php echo site_url();?>/produtos-category/';
- var linslug, linkID;
- jQuery('select#category-select').change(function() {
- linslug = jQuery(this).val();
- linkID = jQuery('option:selected',this).attr('data-id');
- });
- jQuery("#cat_dorar_form").submit(function(e) {
- e.preventDefault();
- var jakhusi = linkase+linslug+'/?cat_select='+linkID+'&pro-filt=Filtrar';
- //console.log(jakhusi);
- window.location.replace(jakhusi);
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment