Showing posts with label pull in video URL for custom slide markup. Show all posts
Showing posts with label pull in video URL for custom slide markup. Show all posts

Thursday, June 6, 2013

[Help Wordpress] pull in video URL for custom slide markup


pull in video URL for custom slide markup



Look at that. I'm learning php (sorta). I figured it out. For anyone else trying to solve something similar:


/* this code will work if you just add it to your functions.php */


// Create PHP class that will hold methods
class MyRoyalSliderRendererHelper {
    private $post;
    private $options;


    function __construct( $data, $options ) {
        // $data variable holds WordPress post object only for Posts Slider
        // for other types sliders it holds just data associated with slide, print it to see what's inside
        $this->post = $data;


        // slider options (that you choose in right sidebar)
        $this->options = $options;
    }
    
    function hello_world() {
        return "Hello World!";
    }
    function post_id() {
        return $this->post->ID;
    }
    function my_video_url() {
     $videonum = $this->post->ID;
     return get_the_post_video_url( $videonum );
    }
}


/**
 * @param [object] $m Mustache_Engine object
 * @param [object] $data Object with slide data (for example for posts slider it's WordPress Post Object)
 * @param [object] $options Array of RoyalSlider options
 */
function newrs_add_custom_variables($m, $data, $options) {


    // initialize helper class
    $helper = new MyRoyalSliderRendererHelper($data, $options);


    // add {{hello_world}} variable that gets data from hello_world function of MyRoyalSliderRendererHelper class
    $m->addHelper('hello_world', array($helper, 'hello_world') );


    // same, but for post_id
    $m->addHelper('post_id', array($helper, 'post_id') );


    // my_video_url
    $m->addHelper('my_video_url', array($helper, 'my_video_url') );
}
add_filter('new_rs_slides_renderer_helper', 'newrs_add_custom_variables', 10, 4);



.

help.dimsemenov.com

Search

Other post