0

I have a 'media' category page that pumps in videos / image galleries. I'm looking to have a smaller size video display (vimeo / youtube) on the category page, and the full size video on the single page.

How do I change the size of the video embed on the fly for the both scenarios?

Here's the loop for selecting anything in the "videos" category.

    <?php $videos = new WP_Query('category_name=video'); ?>
    <?php while ( $videos->have_posts() ) : $videos->the_post(); ?>
    <?php the_content(); ?>
    <?php endwhile; ?>

Videos are entered into the post's main tinymce content editor. Am I being to vague?

  • BTW, I know how to build category, single pages - just need to know how to alter the sizing of the video. – Devise Mar 12 '11 at 21:45
  • I've discovered that I can "hack" the sizing with css but am wondering if there's a more elegant / built in way of doing this through wordpress' native ability. – Devise Mar 12 '11 at 22:27
  • How are you 'pumping' in videos? We need some code before we can advise! – TheDeadMedic Mar 13 '11 at 2:15
  • Sure - edited original message to show my query. I'm sure I could create a custom function to resize the videos depending on the category / single views but am wondering if there's a simpler method. If resizing with css is the simplest - I guess it will have to do. I'm hoping to learn a little 'best practice' for wordpress / theme building / programming here as well. – Devise Mar 13 '11 at 14:53
  • When you say videos are entered into the editor, are you copying HTML embed code from a provider, or using WordPress Embeds - codex.wordpress.org/Embeds? – TheDeadMedic Mar 13 '11 at 16:36
2

The best solution here is to use the built-in filter for embed parameters:

<?php
function mytheme_embed_defaults( $defaults ) {  
return array( 
    'width'  => 100,
    'height' => 100
    );
}
add_filter( 'embed_defaults', 'mytheme_embed_defaults' );
?>

This code can be added to your theme's functions.php file and you can change the numbers to reflect the sizes that you desire. You can add conditionals as needed. Maybe something like:

<?php
function mytheme_embed_defaults( $defaults ) {  
    if ( is_category() ) {
        $defaults = array( 'width'  => 100, 'height' => 100 );
    }
    return $defaults;
}
add_filter( 'embed_defaults', 'mytheme_embed_defaults' );
?>

Would work best for you.

-1

If you use the embed shortcode, you can specify parameters

[­embed width="200"]http://www.flickr.com/photos/xdjio/226228060/sizes/t/[/embed]

Then you can capture that shortcode using the method described here:

How to display a shortcode caption somewhere other than the_content

  • I am using the native wordpress embed - just pasting the video url into the editor. I'll check out the shortcode suggestion. Would this be considered the best practice possible? Are there any other options that make sense? Thank you! – Devise Mar 13 '11 at 20:34

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.