WordPress公文包自定义Post类型筛选

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WordPress公文包自定义Post类型筛选相关的知识,希望对你有一定的参考价值。

Here is a quick example on how to generate your own portfolio with filtering based on a taxonomy (in this case 'Solutions').
  1. <?php
  2. // get portfolio
  3. $args = array( 'post_type' => 'portfolio', 'posts_per_page' => 100, 'orderby' => 'title', 'order' => 'asc' );
  4. $loop = new WP_Query( $args );
  5. $port = array();
  6. while ( $loop->have_posts() ) : $loop->the_post();
  7. $idx = get_the_ID();
  8. $year_completed = get_post_meta($idx, 'year_completed', true);
  9. $website_addr = get_post_meta($idx, 'website_address', true);
  10. $thumb = get_the_post_thumbnail($idx, 'thumbnail'); //250x200 - featured image
  11. $title = get_the_title();
  12. $excerpt = get_the_excerpt();
  13. $content = get_the_content();
  14.  
  15. //get 'Solutions' terms
  16. $terms = get_the_terms($idx, 'Solutions');
  17. $terms_string = '';
  18.  
  19. //build up comma delimited string
  20. foreach($terms as $t){
  21. $terms_string .= $t->slug . ' ';
  22. }
  23. $port[] = array(
  24. 'id' => $idx,
  25. 'year_completed' => $year_completed,
  26. 'website' => $website_addr,
  27. 'thumb' => $thumb,
  28. 'title' => $title,
  29. 'content' => $content,
  30. 'excerpt' => $excerpt,
  31. 'terms' => $terms,
  32. 'terms_string' =>$terms_string, //classifications (comma delimited slugs)
  33. 'permalink' => get_permalink(),
  34. );
  35. endwhile;
  36.  
  37. $terms = get_terms('Solutions');
  38.  
  39. $filters = '<section id="options" class="clearfix">
  40. <ul id="filters" class="option-set floated clearfix">
  41. <li><a href="#filter" data-filter="*" class="selected">show all</a></li>';
  42.  
  43. foreach($terms as $t){
  44. $filters .= '<li><a href="#filter" data-filter=".' . $t->slug . '">' . $t->name . '</a></li>';// $t->count
  45. }
  46. $filters .= '</ul></section>';
  47. ?>
  48.  
  49.  
  50. <!-- add this inside entry-content -->
  51. <?php echo $filters; ?>
  52. <div id="portfolio">
  53.  
  54. <!-- isotope -->
  55. <ul class="thumbnails isotope">
  56. <?php foreach($port as $p){ ?>
  57. <li class="span3 element <?php echo $p['terms_string']; ?>">
  58. <div class="thumbnail">
  59. <?php echo $p['thumb']; ?>
  60. <div class="caption">
  61. <h5><a href="<?php echo $p['permalink']; ?>"><?php echo $p['title']; ?></a></h5>
  62. </div><!-- end caption -->
  63. </div><!-- end thumbnail -->
  64. </li>
  65. <? } //end foreach ?>
  66. </ul>
  67.  
  68. </div><!-- end #portfolio -->

以上是关于WordPress公文包自定义Post类型筛选的主要内容,如果未能解决你的问题,请参考以下文章

将分数添加到 wordpress 自定义帖子类型 slug

Wordpress:使用 wp_insert_post() 填充自定义帖子类型字段

Wordpress自定义Post类型注册

检查当前post类型是否为自定义post类型€“WordPress

从 Wordpress 取消注册自定义帖子类型

Wordpress - 从自定义帖子类型查询第一个和名称