سؤال

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?

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى wordpress.stackexchange
scroll top