I am relatively new to developing in WordPress. The way my posts are structured is the post title with a video underneath followed by text. The videos supplied by my client are in JavaScript tags. What I am looking to accomplish with the archive page is to display the video from the first post under the category header.
I have noticed that the JavaScript is wrapped in p tags when the post is published so I had tried to break the_content by p but did not get the results that I am looking for.
This is the code that I have in functions.php.
function the_post_video($post_id=NULL) {
global $post;
$target_post = $post;
if($post_id !== NULL)
$target_post = get_post($post_id);
$matches = null;
if(preg_match('/<script(.*?)\\/?>(<\\/script>)?/s', $post->content, $matches)) {
return $matches[0];
}
return ''; // return empty if no iframe found.
}
Note: Currently the site is not live.
Any assistance is very much appreciated.