Lon*_*fPR 1 wordpress shortcode
我正在为一个孩子主题编写一个自定义短代码,我已将其放入我的孩子主题函数.php.这是代码:
function get_featured_video(){
$video_query = new WP_Query('category_name=videos&order=ASC');
$videoPath = "/";
$videoText = "";
while ($video_query->have_posts()){
$video_query->the_post();
$featured = get_post_meta($post->ID, "vid_feature", $single = true);
if(strtolower($featured)=='yes'){
$videoPath = get_permalink($post->ID);
$content = strip_tags($post->post_content);
$contentArr = str_word_count($content,1);
if(count($contentArr>50)){
$videoText = join(" ",array_slice($contentArr,0,50));
$videoText .= " <a href='$link'><read more></a>";
} else {
$videoText = $content;
}
break;
}
}
$returnStr = "<h1><a href='$videoPath'>You've Got to See This!</a></h1>\n";
$returnStr .= $videoText;
return $returnStr;
}
add_shortcode('getfeaturedvideo','get_featured_video');
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是它返回一个空白查询.我知道视频类别中有一个帖子.我从未在functions.php中使用过WP_Query.我需要使用不同的方法吗?
归档时间: |
|
查看次数: |
4896 次 |
最近记录: |