私は最初のパブリック テーマで投稿フォーマットのサポートを提供したいと考えています (私は通常、クライアント用にカスタム ビルドを行います)。また、特にインデックスではなく、さまざまなコンテンツのビットを取得する方法を、うまくいけば決定的に知りたいと考えています。テンプレート階層に関してではなく、the_content() から特定のデータ (つまり、ビデオまたはオーディオの URL、ギャラリー、引用、著者など) を抽出します。
それを行う一般的または標準的な方法は何ですか-コンテンツをフィルタリングしてこれらで動作すると思いますか?リンク/チュートリアル、提案などは大歓迎です。
要約すると、私は2つのことを求めています
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の多くのように感じます....