• On the frontpage of my blog, I have – in a lateral bar – an embedded ‘Video of the day’, manually inserted, which appears by default on all other pages when you view a post. However, what I am trying to figure out how to do is have that clip swapped for another one when moving to specific posts.

    For example, if I go to the post reviewing movie X, I would like to display the clip of movie X rather than the default clip.

    The sequence I’m trying to achieve is:

    1. Check if you’re on the frontpage or not,
    2. If on frontpage, display the clip I hardcoded in the lateral bar,
    3. If not on frontpage, identify the post displayed and see if there’s an associated video clip,
    4. If there is an associated clip, display it. If not, display the default clip.

    For a bit, I thought I could manage that with the personalized fields you can create for a post, inserting the required embedded clip code in there, which makes it unique for each relevant post. Then I was hoping that by calling the meta tag it creates, I could display the appropriate clip. Unfortunately (yeah, I should have read further first!), that works only within the loop, so I’m out of luck there.

    Any idea if it’s doable and suggestions on how to go about it?

Viewing 1 replies (of 1 total)
  • Perhaps you can use the $post variable. Something like:

    <?php
    
    if( !is_index() && $video = get_post_meta($post->ID, 'video_id', true ) ) {
      display_video( $video );
    }
    else {
      display_video ( $default );
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Swapping embedded video based on post’ is closed to new replies.