我创建了一个快捷码,可以根据meta\\u键检索并显示推荐的热门帖子。有不同的属性,除了一次属性的内容是HTML之外,所有属性都可以工作。
完整代码为:
function dot_irt_top_posts ( $atts ) {
// get our variable from $atts
extract(shortcode_atts(array(
\'before\' => \'<li>\',
\'after\' => \'</li>\',
\'number\' => \'10\',
\'post_type\' => \'post\',
\'year\' => \'\',
\'monthnum\' => \'\',
\'show_count\' => \'1\',
), $atts));
global $wpdb;
$request = "SELECT * FROM $wpdb->posts, $wpdb->postmeta";
$request .= " WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id";
if ($year != \'\') {
$request .= " AND YEAR(post_date) = \'$year\'";
}
if ($monthnum != \'\') {
$request .= " AND MONTH(post_date) = \'$monthnum\'";
}
$request .= " AND post_status=\'publish\' AND post_type=\'$post_type\' AND meta_key=\'_recommended\'";
$request .= " ORDER BY $wpdb->postmeta.meta_value+0 DESC LIMIT $number";
$posts = $wpdb->get_results($request);
$return = \'\';
foreach ($posts as $item) {
$post_title = stripslashes($item->post_title);
$permalink = get_permalink($item->ID);
$post_count = $item->meta_value;
$return .= $before;
$return .= \'<a href="\' . $permalink . \'" title="\' . $post_title.\'" rel="nofollow">\' . $post_title . \'</a> \';
if ( $show_count == \'1\') {
$return .= \'<span class="votes">\' . $post_count . \'</span> \';
}
//$return .= get_the_post_thumbnail($item->ID, \'showcase-thumbnail\');
$return .= $after;
}
return \'<div class="top_10_posts">\' . $return . \'</div>\';
}
add_shortcode(\'irt_top_posts\',\'dot_irt_top_posts\');
现在,如果我使用下面的短代码,数据将以列表的形式正确返回:
<ul>
[irt_top_posts post_type=\'showcase\' number=\'10\']
</ul>
但如果我设置“before”(在之前)(&;)“属性”之后,它们将显示为内容,而不是作为html执行:
<div>
[irt_top_posts post_type=\'showcase\' before=\'<div>\' after=\'</div>\' number=\'10\']
</div>
我是否需要一些其他函数来禁用转义HTML?