Давайте настроим вывод списка элементов портфолио на странице таксономии. Для этого модернизируем наш код.
Переопределим шаблон. И функция sp_set_page_template будет иметь следующий вид:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
function sp_set_page_template($template){ $currentId = get_the_ID(); $currentPostType = get_post_type($currentId); if(is_single() && $currentPostType == 'sp_portfolio'){ $template = locate_template('page-templates/single-portfolio-page-template.php'); } if(is_tax('sp_portfolio_tax')){ $template = locate_template('page-templates/list-portfolio-page-template.php'); } return $template; } add_filter('template_include', 'sp_set_page_template', 99); |
В шаблоне list-portfolio-page-template.php изменим способ вывода заголовка h1.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<?php /* Template Name: Portfolio list */ get_header(); if(is_tax()){ $title = single_term_title('', 0); } else { $title = get_the_title(); } ?> <!-- Page Title ============================================= --> <section id="page-title"> <div class="container clearfix"> <h1><?php echo $title;?></h1> <ol class="breadcrumb"> <li class="breadcrumb-item"><a href="#">Home</a></li> <li class="breadcrumb-item active" aria-current="page">Portfolio</li> </ol> </div> </section><!-- #page-title end --> |
И напоследок изменим функцию sp_get_portfolio_list()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
function sp_get_portfolio_list($result=null){ global $wp_query; if(isset($wp_query->queried_object->term_id)){ $termID = $wp_query->queried_object->term_id; } else { $termID = ''; } //args $postsPerPage = 4; if(isset($wp_query->query['paged'])){ $paged = $wp_query->query['paged']; } else { $paged = 1; } //get count of items $args = array( 'post_type' => 'sp_portfolio', 'order' => 'asc', 'numberposts' => -1, ); if(!empty($termID)){ $args['tax_query'][] = array( 'taxonomy' => 'sp_portfolio_tax', 'field' => 'id', 'terms' => $termID ); } $spPosts = SP_Framework_Post_Type_Utility::get_list($args); $countPosts = count($spPosts); //get items $args = array( 'post_type' => 'sp_portfolio', 'order' => 'asc', 'posts_per_page' => $postsPerPage, 'paged' => $paged, ); if(!empty($termID)){ $args['tax_query'][] = array( 'taxonomy' => 'sp_portfolio_tax', 'field' => 'id', 'terms' => $termID ); } $spPosts = SP_Framework_Post_Type_Utility::get_list($args); if(count($spPosts)>0){ $result .= '<div id="portfolio" class="portfolio grid-container clearfix">'; foreach ($spPosts as $spPost) { $postID = $spPost['id']; $title = $spPost['title']; $url = $spPost['url']; $image = SP_Framework_Post_Type_Utility::get_image($postID, 'full'); $result .= '<article class="portfolio-item pf-media pf-icons">'; $result .= '<div class="portfolio-image">'; $result .= '<a href="'.$url.'">'; $result .= '<img src="'.$image.'" alt="'.$title.'">'; $result .= '</a>'; $result .= '</div>'; $result .= '<div class="portfolio-desc">'; $result .= '<h3><a href="'.$url.'">'.$title.'</a></h3>'; $terms = get_the_terms($postID , 'sp_portfolio_tax'); if(is_array($terms)){ $result .= '<span>'; foreach($terms as $term){ $result .= '<a href="'. get_term_link($term->term_id, $term->taxonomy ) .'">'. $term->name .'</a> '; } $result .= '</span>'; } $result .= '</div>'; $result .= '</article>'; } $result .= '</div>'; //pagination $args = array( 'wrapper_start' => '<ul class="pagination nobottommargin">', 'wrapper_end' => '</ul>', 'posts_per_page' => $postsPerPage, 'range' => 4, 'count_posts' => $countPosts, 'page' => 'portfolio', ); $spPagination = SP_Framework_Post_Type_Utility::get_pagination($wp_query, $args); $result .= $spPagination; } return $result; } |