有关帖子格式,请参考此链接https://codex.wordpress.org/Post_Formats
要在帖子页面上显示视频,只需修改摘录过滤器并显示摘录即可。
Add following code in functions.php
function custom_wp_trim_excerpt($text) {
$raw_excerpt = $text;
if ( \'\' == $text ) {
$text = get_the_content(\'\'); // Original Content
$text = strip_shortcodes($text); // Minus Shortcodes
$text = apply_filters(\'the_content\', $text); // Filters
$text = str_replace(\']]>\', \']]>\', $text); // Replace
$excerpt_length = apply_filters(\'excerpt_length\', 50); // Length
$excerpt_more = apply_filters(\'excerpt_more\', \' \' . \'<a class="readmore" href="\'. get_permalink() .\'">»</a>\');
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
// Use First Video as Excerpt
$postcustom = get_post_custom_keys();
global $post;
$postid = $post->ID;
if ($postcustom){
$i = 1;
foreach ($postcustom as $key){
if (strpos($key,\'oembed\')){
foreach (get_post_custom_values($key) as $video){
if ($i == 1){
$text = $video."<br/>".$text;
}
$i++;
}
}
}
}
}
return apply_filters(\'wp_trim_excerpt\', $text, $raw_excerpt);
}
remove_filter(\'get_the_excerpt\', \'wp_trim_excerpt\');
add_filter(\'get_the_excerpt\', \'custom_wp_trim_excerpt\');
Put the excerpt tag where you want to display the video.
echo get_the_excerpt();
Add video URL in post content (visual editor) and it will display video in excerpt also.
例如:
https://vimeo.com/VIMEO_ID