0
Iam新的wordpress技術。我想用模板顯示我的視頻文章使用摘錄。但默認摘錄()不允許tags.so我怎麼能顯示使用摘錄()。你能告訴我答案嗎?如何使用摘錄在我的模板中顯示視頻?
Iam新的wordpress技術。我想用模板顯示我的視頻文章使用摘錄。但默認摘錄()不允許tags.so我怎麼能顯示使用摘錄()。你能告訴我答案嗎?如何使用摘錄在我的模板中顯示視頻?
通常WordPress的並不是所有的視頻顯示使用摘錄功能,因爲你必須覆蓋已建成的代碼。
代碼:
function new_excerpt($text)
{
global $post;
$pattern = get_shortcode_regex();
preg_match_all('/'. $pattern .'/s', $post->post_content, $matches);
if(is_array($matches) && array_key_exists(2, $matches))
{
//I'm currently using only youtube and flv videos. If you use
//other videos then add those shortcodes in the following array
$arr=array('youtube','flv');
foreach($matches[2] as $v)
{
if(in_array($v, $matches[2]))
{
$vdo=apply_filters('the_content', $matches[0][0]);
$text=get_the_excerpt();
$text.="<div style='margin:20px 0 0 -115px;'>".$vdo."</div>";
}
}
}
return $text;
}
add_filter('the_excerpt', 'new_excerpt');
僅供參考,請訪問:http://heera.it/show-vipers-video-excerpt#.V78XOzUnjZU
確保,如果你沒有在你身邊可以做以下的事情視頻文件一個div。
替換線:18碼
$text.="<div style='margin:20px 0 0 -115px;'>".$vdo."</div>";
的隨着
$text.=$vdo;
這將這樣的伎倆。認爲這是你面臨的任何障礙。
你指的是什麼文件?如果它是一個wordpress的核心文件,永遠不要改變這些 – Lee
這不是WordPress的核心文件,你必須將代碼添加到主題的function.php文件,那將在那裏做魔術.. :) –
:S是否有代碼你給的鏈接?如果是這樣,請在您的答案中發佈代碼,而不是鏈接。 – Lee