Initialize Royal Slider on AJAX Pages

Peter Mandell's Avatar

Peter Mandell

18 Mar, 2013 06:54 PM

My WordPress theme loads pages via AJAX. I have successfully loaded the slider through "echo get_new_royalslider($sliderID)" but the slider is still not initializing. How can I get the correct jQuery code (including the specific options for the given slider) and run it after the AJAX is complete. Any help would be much appreciated! Thanks!

Showing the most recent page of comments. View the first page

  1. 32 Posted by shir on 23 Jan, 2014 07:27 AM

    shir's Avatar

    Hi Mike,

    Sorry for this late response ...
    although I coulnd't see the problem in your page, I retested it on another Ajax emplate I bought and you are rught, I missed one inportant line that registers the files for the while template:
    register_new_royalslider_files(any_slider_id_here);

    Where you should replace "any_slider_id_here" with a real existing slider ID.

    So the full code should be like this:

    function fire_royalslider_func($atts){
        $sliderid = $atts['id'];
        
        
        if (!$sliderid) return;
       /* Print slider HTML, skip this part if you already have it on page */
        echo get_new_royalslider($sliderid); 
        /* Print slider END */
        
        // Init code
        include_once(ABSPATH.'wp-content/plugins/new-royalslider/classes/NewRoyalSliderMain.php');
        $init_codes = NewRoyalSliderMain::$sliders_init_code;
        if(count($init_codes) > 0 ) {
          echo '<script>';
              echo "jQuery(document).ready(function($) {\n";
                foreach($init_codes  as $key => $value) {
                        echo $value;
                }
              echo "});\n";
          echo '</script>';
          }
    }
    
    
    add_shortcode('fire_royalslider', 'fire_royalslider_func');
    register_new_royalslider_files(1);
    

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac