我有一个自定义的帖子类型的文件,我正试图使用一个新的WP\\u查询列出。
当我在主要帖子内容中添加短代码时,效果很好。然而,当我向自定义字段添加快捷码时(我已将其设置为与主要内容一起显示在页面上作为第二“列”),主要内容将消失!
如果我注释掉“while…have\\u posts()”和“endwhile”行,将显示主要内容;然而,即使在每隔一行注释完之后,主要内容也会消失,除非我也删除了“while”。
我很确定这与使用WP\\u查询有关(它以某种方式劫持了循环),尽管它不应该这样做。
我有什么遗漏吗?
以下是短代码:
function ia_news_display_test($atts){ // [ia_news cat=\'category\' num=\'numbertodisplay\']
extract(shortcode_atts(array(
\'cat\' => \'any\',
\'num\' => \'2\',
), $atts));
$dirloop = new wp_query( array(
\'post_type\' => \'ia_news\',
\'category_name\' => $cat,
\'posts_per_page\' => $num,
\'orderby\' => \'menu_order\',
\'order\' => \'ASC\'
));
if ($dirloop->have_posts()){
$content = "<ul class=\'ia_news_list\'>\\n";
while ( $dirloop->have_posts() ) : $dirloop->the_post();
$custom = get_post_custom($post->ID);
$file_id = $custom["upload_file"][0];
$file_begin = $custom["begin_date"][0];
$file_end = $custom["end_date"][0];
if (\'\' != $file_end){$file_end = " to ".$file_end;}
$file_url = wp_get_attachment_url($file_id);
if (\'\' != $file_url) { //CHECK FOR EXISTENCE OF FILE URL
$content .= "<li class=\'ia_nl\'><a href=\'".$file_url."\'>".$cat." ".$file_begin.$file_end."</a></li>\\n";
}
endwhile;
$content .= "</ul>\\n";
} else { $content = "nothing"; }
return $content;
}