Note that there are some explanatory texts on larger screens.

plurals
  1. PORendering Post formats from the_content() in WordPress - there must be a better way?
    primarykey
    data
    text
    <p>I would like to provide support for post formats in my first public theme (I usually do custom builds for clients) and would like to know, hopefully definitively, how to get the various different bits of content out, particularly for the index, and not with regards to the template hierarchy but rather extracting the specific data(ie: a video or audio URL, a gallery, a quote and author etc) from the_content().</p> <p>Whats the common or standard way of doing it - I assume filtering the content to work with these ? any links / tutorials, suggestion etc are welcome.</p> <p>To Summarize I'm after two things </p> <p>a) Should I be supporting post formats at all b) is there a standard way of doing it?</p> <p>What I'm using right now for video (for example) is (with a custom metabox):</p> <pre><code> &lt;?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("&lt;embed", "&lt;video", "&lt;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) &amp;&amp; !empty($mykey_values) ) { // iterate over values passed foreach ( $mykey_values as $key =&gt; $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 = '&lt;div class="video" style="width:100%; overflow:hidden;"&gt;' . wp_oembed_get($value) . '&lt;/div&gt;' : // if not output a link. $media_to_display = '&lt;a class="button videolink" href="' . $value . '" target="_blank"&gt;Video link: ' . the_title() . '&lt;/a&gt;' ); } // if its the embed code that matches our array defined above. else if ( video_strpos_arr($firstCar, $embedCheck ) !== false ) { $media_to_display = '&lt;div class="video" style="width:100%; overflow:hidden;"&gt;' .$value. '&lt;/div&gt;'; } } }; // 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 ); ?&gt;&lt;p&gt;&lt;?php the_excerpt(); ?&gt;&lt;/p&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;" class="button"&gt;Read More&lt;/a&gt; &lt;?php } </code></pre> <p>Which works with the meta box, and I could use a function like this to grab the URL and pass it instead of the metabox value and then filter it out of the_content()</p> <pre><code>function nona_url_grabber() { if ( ! preg_match( '/&lt;a\s[^&gt;]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) ) return false; return esc_url_raw( $matches[1] ); } </code></pre> <p>But I feel like thats a lot of PT for something that should have some support....</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload