Adding a video widget to wordpress theme

2 replies
  • WEB DESIGN
  • |
I have added the widget-video.php to my themes files to display videos like that of theme-junkie but i cant find it in the list of widgets, can you help me? Is there a function.php code i can use? Here is the code

PHP Code:
<?php
/**
 * Theme Junkie Video Widget
 */
class TJ_Video extends WP_Widget{

    function 
TJ_Video(){
        
$widgetOps = array(
            
"classname"   => "tj-video",
            
"description" => "Add any type of Videos as a widget.",
        );
        
$controlOps = array(
            
"width"   => 190,
            
"height"  => 120,
            
"id_base" => "video-widget"
        
);
        
$this->WP_Widget("video-widget""ThemeJunkie - Videos"$widgetOps$controlOps);
    }

    function 
widget($args$instance){
        
extract($args);

        
$title apply_filters("widget_title"$instance["title"]);
        
$count $instance["count"];

        echo 
$before_widget;
        echo 
$before_title $title $after_title;

         for (
$i 1$i <= $count$i++) { ?>
        <?php
        
if ($i == 1) { $class "open"; } else { $class "hide"; } ?>
        <div class="<?php echo $class?>" id="tj-video-cat-<?php echo $i?>">

        <?php if ($instance["video" $i]) { // Do we embed a video from a website?
            
$videocode $instance["video" $i];
              
$videocode preg_replace("/(width\s*=\s*[\"\'])[0-9]+([\"\'])/i""$1 268 $2"$videocode);
            
$videocode preg_replace("/(height\s*=\s*[\"\'])[0-9]+([\"\'])/i""$1 160 $2"$videocode);
            
$videocode str_replace("<embed","<param name='wmode' value='transparent'></param><embed",$videocode);
            
$videocode str_replace("<embed","<embed wmode='transparent' ",$videocode); ?>
            <div class="cover"><?php echo "$videocode";  ?></div>
            <?php }
             else {
                echo 
"Could not generate embed. Please try it again.";
            }
            
?>
            <p class="description"><?php echo $instance["video" $i "-desc"?></p>
        </div>
        <?php ?>

        <ul class="items">
            <?php for ($i 1$i <= $count$i++) { ?>
            <?php if ($i == 1) { $class="active"; } ?>
            <li>
              <a class="<?php echo $class?>" href="#tj-video-cat-<?php echo $i?>"><?php echo $instance["video" $i "-title"]; ?></a>
            </li>

            <?php $class ""; } ?>
        </ul>
        <script type="text/javascript">
        jQuery(function($) {
            $("document").ready(function() {
                $(".tj-video li a").click(function() {
                    $(".tj-video .open").addClass("hide").removeClass("open");
                    $(".tj-video " + $(this).attr("href")).addClass("open").removeClass("hide");
                    $(".tj-video li a.active").removeClass("active");
                    $(this).addClass("active");
                    return false;
                })
            });
        });
        </script>
    <?php
        
echo $after_widget;
    }

    function 
form($instance)
    {
        
$defaults = array(
            
"title" => "Video Widget",
            
"count" => "3"
        
);
        
$instance wp_parse_args((array) $instance$defaults);
    
?>
        <p>
            <label for="<?php echo $this->get_field_id("title"); ?>">Title</label>
            <input id="<?php echo $this->get_field_id("title"); ?>" class="widefat" name="<?php echo $this->get_field_name("title"); ?>" value="<?php echo $instance["title"]; ?>" style="width: 96%;" />
        </p>

        <p>
            <label for="<?php echo $this->get_field_id("count"); ?>">Videos</label>
            <select id="<?php echo $this->get_field_id("count"); ?>" name="<?php echo $this->get_field_name("count"); ?>" value="<?php echo $instance["count"]; ?>" style="width: 100%;">
                <?php for ($i 2$i <= 10$i++) {
                    
$active "";
                    if (
$instance["count"] == $i) {
                        
$active "selected=\"selected\"";
                    } 
?>
                    <option <?php echo $active?> value="<?php echo $i?>"><?php echo $i?></option>
                <?php ?>
            </select>
            <span class="description" style="font-size:11px;">Make sure to specify exact number of videos, otherwise the widget won't work.</span>
        </p>

    <?php for ($i 1$i <= $instance["count"]; $i++) { ?>
        <p>
        <label for="<?php echo $this->get_field_id("video" $i); ?>"><strong>Video #<?php echo $i?> Embed Code</strong></label>

        <textarea id="<?php echo $this->get_field_id("video" $i); ?>" class="widefat" name="<?php echo $this->get_field_name("video" $i); ?>" rows="6"><?php echo htmlspecialchars($instance["video" $i]); ?></textarea>
        </p>

        <p>
        <label for="<?php echo $this->get_field_id("video" $i "-title"); ?>">Video #<?php echo $i?> title</label>
        <input id="<?php echo $this->get_field_id("video" $i "-title"); ?>" class="widefat" name="<?php echo $this->get_field_name("video" $i "-title"); ?>" value="<?php echo $instance["video" $i "-title"]; ?>" style="width:96%;" />
        </p>

        <p>
        <label for="<?php echo $this->get_field_id("video" $i "-desc"); ?>">Video #<?php echo $i?> description</label>
        <input id="<?php echo $this->get_field_id("video" $i "-desc"); ?>" class="widefat" name="<?php echo $this->get_field_name("video" $i "-desc"); ?>" value="<?php echo $instance["video" $i "-desc"]; ?>" style="width:96%;" />
        <br/><br/></p>
    <?php }
    }
}
register_widget('TJ_Video');
?>
#adding #video #widget #wordpress
  • Profile picture of the author David V
    If your using the themejunkie videoplus theme, it should include automatically if the file is dropped in the "/includes" directory.
    (see example).

    If not, it may need to be included.
    Might need more info to help you, like theme? where you got the widget-video.php, etc...
    {{ DiscussionBoard.errors[8364831].message }}
    • Profile picture of the author ibietela2
      Originally Posted by David V View Post

      If your using the themejunkie videoplus theme, it should include automatically if the file is dropped in the "/includes" directory.
      (see example).

      If not, it may need to be included.
      Might need more info to help you, like theme? where you got the widget-video.php, etc...
      I am not using themejunkie theme anymore, i use mythemeshop splash theme but i just want that Feature on my current theme.
      Signature

      Your Health and Fitness Guide http://healthable.org | Buy Health and Fitness ebooks at cheap price at http://shop.healthable.org | Join me on my personal blog http://kingsleyfelix.com where i share make money, seo, adsense, traffic tips and lots more.

      {{ DiscussionBoard.errors[8364861].message }}

Trending Topics