ebow

Taxonomy template

Oct 29th, 2018
44
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  * The main template file.
  4.  *
  5.  * This is the most generic template file in a WordPress theme
  6.  * and one of the two required files for a theme (the other being style.css).
  7.  * It is used to display a page when nothing more specific matches a query.
  8.  * E.g., it puts together the home page when no home.php file exists.
  9.  * Learn more: http://codex.wordpress.org/Template_Hierarchy
  10.  *
  11.  * @package bs4boiler-platform
  12.  */
  13. ?>
  14.  
  15.  
  16.  
  17. <?php
  18.  
  19.  
  20.  
  21.  
  22. $update_taxonomy = 'type';
  23. $get_terms_args = array(
  24.     'taxonomy' => $update_taxonomy,
  25.     'fields' => 'ids',
  26.     'hide_empty' => false,
  27.     );
  28. $update_terms = get_terms($get_terms_args);
  29. wp_update_term_count_now($update_terms, $update_taxonomy);
  30.  
  31.  
  32.  
  33.  
  34. // Let's make this flexible for any custom taxonomy...
  35.  
  36. // Term:
  37. // Get taxonomy term from page (eg. source 'beet-tv')
  38. $term = get_queried_object();
  39. $this_terms_name = $term->name;
  40.  
  41. // Taxonomy:
  42. // Get taxonomy slug of this taxonomy term (eg. 'source')
  43. $this_terms_tax_slug = $term->taxonomy;
  44. // Standard Class Object - Source is in here.
  45. $this_terms_tax_obj = get_taxonomy($this_terms_tax_slug);
  46. // Get name of taxonomy using the slug (eg. 'Source')
  47. $this_terms_tax_name = $this_terms_tax_obj->labels->singular_name;
  48.  
  49. ?>
  50.  
  51.  
  52.  
  53. <?php get_header(); ?>
  54.  
  55. <?php
  56. // If header colour is set, wrap a container around Navbar and Jumbotron
  57. /* if(!empty(get_theme_mod('theme_setting_header_bgcolor'))) { ?>
  58.     </div>
  59. <?php }*/
  60. ?>
  61.  
  62. <nav aria-label="breadcrumb">
  63.   <ol class="breadcrumb m-0 rounded-0">
  64.     <li class="breadcrumb-item"><a href="#">Home</a></li>
  65.     <li class="breadcrumb-item"><a href="#">Library</a></li>
  66.     <li class="breadcrumb-item active" aria-current="page">Data</li>
  67.   </ol>
  68. </nav>
  69.  
  70.  
  71. <div class="container-fluid py-3 bg-white">
  72.  
  73.    <div class="row">
  74.       <div class="col-12">
  75.          <h5 class="mb-1"><?php echo $this_terms_tax_name . ': ' . $term->name; ?></h5>
  76.          <!--<p class="mb-0">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer sagittis eros non augue interdum tincidunt. Phasellus justo ipsum, elementum ut cursus sed, fermentum vel odio. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec finibus volutpat rhoncus. Interdum et malesuada fames ac ante ipsum primis in faucibus. Phasellus mi metus, tempus in maximus at, suscipit eu lacus.</p>-->
  77.       </div>
  78.    </div>
  79.  
  80. </div>
  81.  
  82.  
  83. <div class="container-fluid p-0 m-0 bg-white">
  84.  
  85.   <ul class="nav nav-tabs m-0 p-0">
  86.     <li class="nav-item ml-3">
  87.       <a class="nav-link active bg-light" href="#">Active</a>
  88.     </li>
  89.     <li class="nav-item">
  90.       <a class="nav-link" href="#">Link</a>
  91.     </li>
  92.     <li class="nav-item">
  93.       <a class="nav-link" href="#">Link</a>
  94.     </li>
  95.     <li class="nav-item">
  96.       <a class="nav-link disabled" href="#">Disabled</a>
  97.     </li>
  98.   </ul>
  99.  
  100. </div>
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114. <div class="container-fluid py-3 bg-light" style="min-height:70vh">
  115.  
  116.  
  117.  
  118.       <?php
  119.  
  120.       // Get posts matching for this taxonomy term
  121.       $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
  122.       $args = array(
  123.         'nopaging' => false,
  124.         'posts_per_page' => 40,
  125.         'paged' => $paged,
  126.         'tax_query' => array(
  127.           array(
  128.             'taxonomy' => $this_terms_tax_slug, // from above, whatever this taxonomy is, eg. 'source'
  129.             'field'    => 'slug',
  130.             'terms'    => $term->slug,
  131.           ),
  132.         ),
  133.       );
  134.       $the_query = new WP_Query($args);
  135.  
  136.  
  137.  
  138.  
  139.       if ( $the_query->have_posts() ) : ?>
  140.  
  141.         <div class="row">
  142.           <div class="col-sm-12 col-md-9">
  143.             <div class="row">
  144.  
  145.               <?php
  146.                 // Post Loop!!
  147.                 while ( $the_query->have_posts() ) {
  148.                   $the_query->the_post();
  149.                   // Tell loop template which taxonomy to loop through (set above ^)
  150.                   // set_query_var( 'tax_slug_to_do', $this_terms_tax_slug );
  151.                   // Get Loop template
  152.                   get_template_part('templates/loop');
  153.                 }
  154.                 wp_reset_postdata();
  155.               ?>
  156.  
  157.             </div>
  158.  
  159.             <?php
  160.              // Pagination, if allowed above
  161.              if ( false === $the_query->query_vars['nopaging'] ) {
  162.                fellowtuts_wpbs_pagination();
  163.              }
  164.              // function uses Bootstrap mark-up, cf. https://fellowtuts.com/bootstrap/wordpress-pagination-bootstrap-4-style/
  165.              // This needs to be disabled if nopaging is true!
  166.             ?>
  167.  
  168.           </div>
  169.           <div class="col-xs-12 col-sm-12 col-md-3">
  170.             <?php
  171.             // Terms from the post IDs of the above post query
  172.             $article_terms = get_terms( [
  173.                 'taxonomy'   => 'post_tag',
  174.                 'object_ids' => wp_list_pluck( $the_query->posts, 'ID' ),
  175.                 'orderby' => 'count',
  176.                 'order' => 'DESC',
  177.                 'hide_empty'=>0,
  178.             ] );
  179.             foreach ( $article_terms as $article_term ) {
  180.                 echo '<a href="' . esc_url( get_term_link( $article_term ) ) . '">' .$article_term->name .' ('.$article_term->count .')</a><br />';
  181.             }
  182.            ?>
  183.           </div>
  184.         </div>
  185.  
  186.  
  187.       <?php else : ?>
  188.           Nothing here.
  189.       <?php endif; ?>
  190.  
  191.     </div>
  192.  
  193.  
  194.  
  195.  
  196.  
  197. <?php get_footer(); ?>
RAW Paste Data