自定义分类的相关文章
所谓“自定义分类”是指非默认的 category 这个分类法。以下是代码样例:
<?php /** * WordPress 获取自定义文章类型的相关文章(自定义分类) * https://www.wpdaxue.com/related-custom-post-type-taxonomy.html */ // 获取自定义文章类型的分类项目 $custom_taxterms = wp_get_object_terms( $post->ID,'your_taxonomy', array('fields' => 'ids') ); // 参数 $args = array( 'post_type' => 'YOUR_CUSTOM_POST_TYPE',// 文章类型 'post_status' => 'publish', 'posts_per_page' => 3, // 文章数量 'orderby' => 'rand', // 随机排序 'tax_query' => array( array( 'taxonomy' => 'your_taxonomy', // 分类法 'field' => 'id', 'terms' => $custom_taxterms ) ), 'post__not_in' => array ($post->ID), // 排除当前文章 ); $related_items = new WP_Query( $args ); // 查询循环 if ($related_items->have_posts()) : echo '<h3 class="related-posts-title">Related Posts</h3><ul>'; while ( $related_items->have_posts() ) : $related_items->the_post(); ?> <li><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li> <?php endwhile; echo '</ul>'; endif; // 重置文章数据 wp_reset_postdata();
你需要根据自己的实际,修改如下参数:
第 7 行和第 16 行:修改 your_taxonomy 为你的自定义分类法
11行:’YOUR_CUSTOM_POST_TYPE’ 你需要修改为你的自定义文章类型
12行: 修改文章数量
还可以修改 26、29、32行的代码来输出自己想要的内容,比如添加缩略图,以及更多文章meta信息等。
参考资料:
关注公众号『窗外天空』
获取更多建站运营运维新知!互联网创业、前沿技术......
最新评论
想要aarch64_generic架构的,用的是Rockchip RK3308 ARMv8 Cortex-A35
水淀粉vdfv
有其他下载方式么,网站上的点击下载后没有任何反应,或者直接发给我一下?[email protected]
你好,我的型号ELECOM WRC-X3200GST3,ARMv8 Processor rev 4构架,CPU mediatek/mt7622,找了很久没有找到
我的也是这样。一直无法确认ARCH架构,或是不支持。一直没办法用。不知道怎么办了