How to show video from specific category on sidebar?

I need to get video and content from recent posts in specific category called “Video” and show it on my sidebar.

The problem is when I need to have limited text content. so, when I use the_content(); I can see video within sidebar, but when I use the_excerpt(); to limit text, video is gone.

The code I have is doing what I need with posts and categories but I’m stuck here:

<?php query_posts('cat=6&showposts=2'); ?>
<?php while (have_posts()) : the_post(); ?>

<?php endwhile; ?>

Tho, I have one more content limit function that I can use in my function.php but as I am new at WordPress and PHP, I don’t know what to do next and could use any help that you can offer.

function content($num, $more_link_text="(more...)") { 
    $theContent = get_the_content($more_link_text); 
    $output = preg_replace('/<img[^>]+./','', $theContent); 
    $output = strip_shortcodes($output);
    $output = strip_tags($output);
    $output = preg_replace("/\[caption.*\[\/caption\]/", '', $output);
    $limit = $num+1; 
    $content = explode(' ', $output, $limit); 
    array_pop($content); 
    $content = implode(" ",$content); 
    echo ($content) . "...";
}

with <?php content(8); ?> that I’m calling in my Loop. This do what I need with content limitation, but still doesn’t show video.

3 Answers
3

If you’re video embeds are always the same, I like the solution proposed by 5wpthemes, but if you want to avoid having to use a custom field ( and more specifically, remembering to do it), you could also try the code below ( which also requires the code to be very similar in every post ).

<?php $my_query = new WP query(array('cat'=>6, 'showposts'=> '2')); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    $theContent = get_the_content();
    $parts = explode("iframe",$theContent);
    ?><iframe<? echo $parts[1]; ?>iframe><?php
<?php endwhile; ?>

Leave a Comment