0

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.

0

I have created a working solution to this. I wrapped the JavaScript in a DIV. All other content is automatically wrapped in paragraph tags. In archive.php, I have it pull the most recent post in the section where I want the video. In the CSS, I have set display:none to the paragraph tags. Thanks everyone!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.