CPT(自定义Post类型)提要短代码
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CPT(自定义Post类型)提要短代码相关的知识,希望对你有一定的参考价值。
/** * CPT (Custom Post Type) Feed Shortcode * http://codex.wordpress.org/Shortcode_API */ global $post, $wp_query; $cpt = 'project'; // Custom Post Type slug $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; // Save and overwrite wp_query so the navigation will work $saved_query = $wp_query; $wp_query = null; $saved_post = $post; $post = null; // http://codex.wordpress.org/Function_Reference/WP_Query // http://codex.wordpress.org/Template_Tags/get_posts $wp_query = new WP_Query(); 'orderby' => 'menu_order', // or 'date' 'order' => 'ASC', // or 'DSC' 'post_type' => $cpt, // $term->taxonomy => $term->slug, 'post_status' => 'publish', // 'posts_per_page' => get_option('posts_per_page', 10), // 'paged' => $paged, 'posts_per_page' => -1 ); $wp_query->query($defaults); // posts_per_page $output = ''; if (have_posts()) { $count = 0; while (have_posts()) { the_post(); if ($count % 4 == 3) { echo('<div class="end"></div>'); } $count++; } } // Pagination get_template_part('templates/nav', 'page'); // templates/nav-page.php // Restore previous wp_query $wp_query = null; $wp_query = $saved_query; $post = null; $post = $saved_post; return $output; } add_shortcode('cptfeed', 'fn_cpt');
以上是关于CPT(自定义Post类型)提要短代码的主要内容,如果未能解决你的问题,请参考以下文章