我想在我的第一个公共主题中提供对帖子格式的支持(我通常为客户进行自定义构建),并且希望明确地知道如何获取各种不同的内容,特别是对于索引,而不是关于模板层次结构,而是从 the_content() 中提取特定数据(即:视频或音频 URL、图库、引用和作者等)。
这样做的常见或标准方式是什么 - 我假设过滤内容以使用这些?欢迎任何链接/教程、建议等。
总结一下,我追求两件事
a)我是否应该完全支持帖子格式 b)有标准的方法吗?
我现在使用的视频(例如)是(使用自定义元框):
<?php
// Display Videos
// Utility function - allow us to strpos an array
if ( ! function_exists( 'video_strpos_arr' )) {
function video_strpos_arr($haystack, $needle) {
if( !is_array($needle) ) $needle = array($needle);
foreach( $needle as $what ) {
if( ($pos = strpos($haystack, $what) ) !==false ) return $pos;
}
return false;
}
}
// Get Ready Display the Video
$embedCheck = array("<embed", "<video", "<ifram");// only checking against the first 6
$mykey_values = get_post_custom_values('_format_video_embed');
$media_to_display = '';
// check if the audio metabox is used
if ( isset($mykey_values) && !empty($mykey_values) ) {
// iterate over values passed
foreach ( $mykey_values as $key => $value ) {
if ( !empty($value) ) {
$firstCar = substr($value, 0, 6); // get the first 6 char.
// if its a http(s).
if ( strpos($firstCar, "http:/" ) !== false || strpos($firstCar, "https:" ) !== false ) {
// send it to wp_oembed to see if the link is oembed enabled.
(wp_oembed_get($value) !==false ?
$media_to_display = '<div class="video" style="width:100%; overflow:hidden;">' .
wp_oembed_get($value) . '</div>' :
// if not output a link.
$media_to_display = '<a class="button videolink" href="' .
$value . '" target="_blank">Video link: ' . the_title() . '</a>'
);
}
// if its the embed code that matches our array defined above.
else if ( video_strpos_arr($firstCar, $embedCheck ) !== false ) {
$media_to_display = '<div class="video" style="width:100%; overflow:hidden;">' .$value. '</div>';
}
}
}; // end foreach
} // end conditional
if ( is_singular() ) {
// output a filtered excerpt displaying the result of the conditionals above.
echo apply_filters('the_content', $media_to_display );
the_content();
} else {
// output a filtered excerpt displaying the result of the conditionals above.
get_template_part( 'loop/loop', 'indextitle' );
echo apply_filters('the_excerpt', $media_to_display );
?><p><?php the_excerpt(); ?></p>
<a href="<?php the_permalink(); ?>" class="button">Read More</a> <?php
}
哪个适用于元框,我可以使用这样的函数来获取 URL 并传递它而不是元框值,然后将其从 the_content() 中过滤掉
function nona_url_grabber() {
if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) )
return false;
return esc_url_raw( $matches[1] );
}
但我觉得对于应该有一些支持的东西来说,这就是很多 PT....