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

No comments:

Post a Comment

Search

Other post

[Wordpress issuses] olaide07 on "Adding a calendar to a page and linking"
olaide07 on "Adding a calendar to a page and linking"
Hello!I want to add a calendar to my quote of the day page and be able to link each day to...
[Wordpress issuses] karenhanson75 on "Problem with xml file when importing from Posterous."
karenhanson75 on "Problem with xml file when importing from Posterous."
I'm trying to import from Posterous. I've downloaded the backup and am trying to import th...
[WP issuses] mgerney on "[Plugin: WP Forum Server] Extra return after post name"
mgerney on "[Plugin: WP Forum Server] Extra return after post name"
mgerneyMemberPosted 3 hours ago #There is an extra return after the forum poster name. I c...
[Wordpress issuses] peterleeson on "No option to follow a blog."
peterleeson on "No option to follow a blog."
I have been informed that some people are getting an e-mail asking them to confirm that th...
[Help Wordpress] Not working on page
Help Wordpress
Thanks for a great plugin!I can't make the slider work on a page in wordpress.It just show...