我为自定义帖子类型创建了一个快捷码,以便在页面中显示帖子。它可以工作,只是它只显示1个帖子。
这里是代码。。。有人知道怎么了吗?
// this is the shortcode function which includes the query
function ea_get_location($atts){
extract(shortcode_atts(array(
\'destination\' => null,
\'posts\' => \'10\'
), $atts));
$ea_params = array(
\'post_type\'=>\'itineraries\',
\'posts_per_page\' => $posts,
\'tax_query\' => array(
array(
\'taxonomy\' => \'location\',
\'field\' => \'slug\',
\'terms\' => $destination
))
);
query_posts( $ea_params );
while (have_posts()) : the_post();
$ea_var = \'<article id="post-\';
$ea_var .= get_the_ID();
$ea_var .= \'" class="post-\';
$ea_var .= get_the_ID();
$ea_var .= \' itineraries type-itineraries hentry">\';
$ea_var .= \'<header class="entry-header">\';
$ea_var .= \'<a href="\';
$ea_var .= get_permalink();
$ea_var .= \'#access" >\';
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), \'itinerary-thumb\' );
$thumb_url = $thumb[\'0\'];
$ea_var .= \'<img src="\'.$thumb_url.\'" class="attachment-itinerary-thumb wp-post-image" />\';
$ea_var .= \'</a><h2 class="entry-title">\';
$ea_var .= \'<a href="\';
$ea_var .= get_permalink();
$ea_var .= \'#access">\';
$ea_var .= get_the_title();
$ea_var .= \'</a></h2></header><div class="entry-summary">\';
$ea_var .= get_the_excerpt();
$ea_var .= \'</div></article>\';
endwhile;
// Reset Query
wp_reset_query();
// return the variable for use in the shortcode
return \'<div id="location-list" class="tax-location">\'.$ea_var.\'</div>\';
}
// register the function as a shortcode
function register_shortcodes(){
add_shortcode(\'location\', \'ea_get_location\');
}
?>
这是新的更新代码
// this is the shortcode function which includes the query
function ea_get_location($atts){
extract(shortcode_atts(array(
\'destination\' => \'\',
\'posts\' => -1
), $atts));
$ea_params = array(
\'post_type\'=>\'itineraries\',
\'posts_per_page\' => $posts,
\'tax_query\' => array(
array(
\'taxonomy\' => \'location\',
\'field\' => \'slug\',
\'terms\' => $destination
))
);
// The Query
$ea_itin_query = new WP_Query( $ea_params );
$ea_var = \'\';
while ($ea_itin_query->have_posts()) : $ea_itin_query->the_post();
global $post;
$ea_var .= \'<article id="post-\';
$ea_var .= get_the_ID();
$ea_var .= \'" class="post-\';
$ea_var .= get_the_ID();
$ea_var .= \' itineraries type-itineraries hentry">\';
$ea_var .= \'<header class="entry-header">\';
$ea_var .= \'<a href="\';
$ea_var .= get_permalink();
$ea_var .= \'#access" >\';
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), \'itinerary-thumb\' );
$thumb_url = $thumb[\'0\'];
$ea_var .= \'<img src="\'.$thumb_url.\'" class="attachment-itinerary-thumb wp-post-image" />\';
$ea_var .= \'</a><h2 class="entry-title">\';
$ea_var .= \'<a href="\';
$ea_var .= get_permalink();
$ea_var .= \'#access">\';
$ea_var .= get_the_title();
$ea_var .= \'</a></h2></header><div class="entry-summary">\';
$ea_var .= get_the_excerpt();
$ea_var .= \'</div></article>\';
endwhile;
// Reset Post Data
wp_reset_postdata();
// return the variable for use in the shortcode
return \'<div id="location-list" class="tax-location">\'.$ea_var.\'</div>\';
}
// register the function as a shortcode
function register_shortcodes(){
add_shortcode(\'location\', \'ea_get_location\');
}
?>