Add additional fields:
Field type: Text
Name: Videopost
Description: Youtube Video
HTML code template: (variant 1)
<div class="PostFullStoryVideo" data-videopost="{videopost}"></div>
Jquery script:
<script type="text/javascript">
$(document).ready(function() {
var getvideoidpost = $('.PostFullStoryVideo').attr('data-videopost');
$(this).html('<iframe width="540" height="304" src="//www.youtube.com/embed/' + getvideoidpost + '?rel=0&autoplay=1&showinfo=0&controls=1&HD=1" frameborder="0" allowfullscreen></iframe>');
});
</script>
If you're going to do that, the extra custom field isn't really necessary. Plus, you'd have to put <div> for the video in the template, which isn't optimal because you can't really chose where it goes in the news post (if you want to have text before/after the video).
Something better would be to have the following code in your news post (html enabled) where you want the video:
<div class="newsYoutube">ocW3fBqPQkU</div>
And include on the page (not in the news post/template; we only need it once):
<script type="text/javascript">
$(document).ready(function() {
$(".newsYoutube").each(function(){
$(this).html('<iframe width="560" height="315" src="//www.youtube.com/embed/'+ $(this).html() +'?rel=0" frameborder="0" allowfullscreen></iframe>');
});
});
</script>
You could still use the data-videopost="youtubeidhere", but I prefer putting it into the div so it gets replaced (also, less code). Having the attribute after we've embedded the video isn't needed. Also, we don't really need to create a javascript variable for the youtube id; we're only using it once.
This is fine and all, and it kind of fixes the problem, but the deeper problem is not being able to embed any kind of HTML into the news posts that you want. It's not like you're going to insert anything malicious, it's your own website. I use HTML in a lot of my news posts, especially because the bbcode doesn't really work for certain things. Like links, for example. If I had multiple links, the [/link] wouldn't end the link, and it would only end once it got to another [link=http://.....], etc.
Also worth noting that if you want to add new lines, you have to use
, which isn't valid html. You should be using <br/>, but it just gets replaced by a new line, but the new line won't show in the news post (on the site) because you have html enabled. I tried doing
</br>, but then it did two new lines, instead of just one.
The HTML and bbcode in Cutenews 2 need fixin'. Also, you should be able to set the specific width/height for your embedded videos. Something like:
[youtube=560,315]URL[/youtube]
Where the first number is the width, and the second is the height.
EDIT: I realized that the jQuery I had conflicted if you had multiple videos on the same page. The code should now work for multiple videos on the same page.