• Can someone tell me why this isnt working?
    In short, its just a shorcode to get some data in a table using jqwidgets.
    it works fine standalone but i cant get it to work throu wordpress.

    function get_shortcode_ollo()
    {
    	
    	wp_register_style( 'stylesheet', plugins_url('jqwidgets/styles/jqx.base.css', __FILE__), false, '', 'all');
    	wp_enqueue_style('datatables_style');
    	
    	wp_register_style( 'stylesheet', plugins_url('jqwidgets/styles/jqx.metro.css', __FILE__), false, '', 'all');
    	wp_enqueue_style('datatables_style');
    	
    	wp_register_script('jquery', plugin_dir_url(__FILE__) . 'scripts/jquery-1.10.2.min.js', 'jquery', '1.10.2', false);
    	wp_enqueue_script('jquery');	
    	
    	wp_register_script('jquery1', plugin_dir_url(__FILE__) . 'jqwidgets/jqxcore.js', 'jqwidgets', '', false);
    	wp_enqueue_script('jquery1');
    	
    	wp_register_script('jquery2', plugin_dir_url(__FILE__) . 'jqwidgets/jqxbuttons.js', 'jqwidgets', '', false);
    	wp_enqueue_script('jquery2');
    		
    	wp_register_script('jquery3', plugin_dir_url(__FILE__) . 'jqwidgets/jqxscrollbar.js', 'jqwidgets', '', false);
    	wp_enqueue_script('jquery3');
    	
    	wp_register_script('jquery4', plugin_dir_url(__FILE__) . 'jqwidgets/jqxmenu.js', 'jqwidgets', '', false);
    	wp_enqueue_script('jquery4');	
    
    	wp_register_script('jquery5', plugin_dir_url(__FILE__) . 'jqwidgets/jqxgrid.js', 'jqwidgets', '', false);
    	wp_enqueue_script('jquery5');		
    	
    	wp_register_script('jquery6', plugin_dir_url(__FILE__) . 'jqwidgets/jqxgrid.selection.js', 'jqwidgets', '', false);
    	wp_enqueue_script('jquery6');	
    
    	wp_register_script('jquery7', plugin_dir_url(__FILE__) . 'jqwidgets/jqxgrid.filter.js', 'jqwidgets', '', false);
    	wp_enqueue_script('jquery7');	
    	
    	wp_register_script('jquery8', plugin_dir_url(__FILE__) . 'jqwidgets/jqxgrid.sort.js', 'jqwidgets', '', false);
    	wp_enqueue_script('jquery8');	
    
    	wp_register_script('jquery9', plugin_dir_url(__FILE__) . 'jqwidgets/jqxdata.js', 'jqwidgets', '', false);
    	wp_enqueue_script('jquery9');		
    
    	wp_register_script('jquerya', plugin_dir_url(__FILE__) . 'jqwidgets/jqxlistbox.js', 'jqwidgets', '', false);
    	wp_enqueue_script('jquerya');		
    	
    	wp_register_script('jqueryb', plugin_dir_url(__FILE__) . 'jqwidgets/jqxgrid.pager.js', 'jqwidgets', '', false);
    	wp_enqueue_script('jqueryb');	
    
    	wp_register_script('jqueryc', plugin_dir_url(__FILE__) . 'jqwidgets/jqxdropdownlist.js', 'jqwidgets', '', false);
    	wp_enqueue_script('jqueryc');
    /**	
    		wp_register_script('jqueryd', plugin_dir_url(__FILE__) . 'skript.js', 'jqwidgets', '', false);
    	wp_enqueue_script('jqueryd');
    */	
    	
    
    $skr = '<script type="text/javascript">
            $(document).ready(function () {
                // prepare the data
                var theme = \'metro\';
          
                var source =
                {
                     datatype: "json",
                     datafields: [
    					 { name: \'cTrackName\', type: \'string\'},
    					 { name: \'cLapNumber\', type: \'string\'},
    					 { name: \'cLapTime\', type: \'string\'},
    					 { name: \'cContender\', type: \'string\'},
    					 { name: \'cDate\', type: \'string\'}
                    ],
    			    url: \'data.php\',
    				cache: false,
    				filter: function()
    				{
    					// update the grid and send a request to the server.
    					$("#jqxgrid").jqxGrid(\'updatebounddata\', \'filter\');
    				},
    				sort: function()
    				{
    					// update the grid and send a request to the server.
    					$("#jqxgrid").jqxGrid(\'updatebounddata\', \'sort\');
    				},
    				root: \'Rows\',
    				beforeprocessing: function(data)
    				{		
    					if (data != null)
    					{
    						source.totalrecords = data[0].TotalRows;					
    					}
    				}
                };		
    		    var dataadapter = new $.jqx.dataAdapter(source, {
    					loadError: function(xhr, status, error)
    					{
    						alert(error);
    					}
    				}
    			);
    	
                // initialize jqxGrid
                $("#jqxgrid").jqxGrid(
                {		
                    source: dataadapter,
                    theme: theme,
    				filterable: true,
    				sortable: true,
    				autoheight: true,
    				pageable: true,
    				virtualmode: true,
    				rendergridrows: function(obj)
    				{
    					 return obj.data;    
    				},
    			    columns: [
                          { text: \'Track\', datafield: \'cTrackName\', cellsformat: \'yyyy-MM-dd\', width: 200 },
                          { text: \'Lap\', datafield: \'cLapNumber\', width: 200 },
                          { text: \'Time\', datafield: \'cLapTime\', width: 180 },
                          { text: \'Contender\', datafield: \'cContender\', width: 100 },
                          { text: \'Date\', datafield: \'cDate\', width: 140 }
                      ]
                });
            });
        </script>';
    	
    $sko	 = 	'
    	<div id="jqxWidget">
        <div id="jqxgrid"></div>
        </div>
    
    ';
    	
    	
    	
    	return $sko . $skr; 
    
    ;
    
    	
    
     }
    
    add_shortcode('ollo_code', 'get_shortcode_ollo');
    
    ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • First, you don’t need to call register and then enqueue. You can just call enqueue and it will register it if it hasn’t been.
    Second, using a handle that is already used will not overwrite it. ‘jquery’ is already registered. You should use the scripts that WordPress registers, instead of supplying your own version.
    Third, the dependency parameter should be an array.
    Fourth, passing false for the in_footer parameter doesn’t make sense, since you are doing this in a shortcode, so you know execution has already passed the normal enqueue action. The only choice left is in the footer.

    This is a LOT of scripts to load. Is it worth it? Plus more inline script? And that script doesn’t appear to have any variables, so why isn’t it in a file that you load?

    Edit: I forgot I was going to point to the Code Reference.

    • This reply was modified 6 years, 1 month ago by Joy. Reason: code reference link
    Thread Starter joha1234

    (@joha1234)

    Thanks!

    I tried all you mentioned but i cant get that to work either.
    In the code above all scripts are included in the source after i run it thru wordpress, and everything seams fine, but it is not working, the scripts dont seam to be executed.

    The amount of scripts will be reduced in the end, im just trying to figure this out.
    I tried with ajax before and that turned out to be very complexed to get that to work with worpress.

    the scripts dont seam to be executed.

    WordPress helps you load the scripts; it doesn’t execute them for you.

    Loading a different version of jquery might not show problems in your limited tests, but if you use any plugin or theme that loads the WordPress version of jquery, you will definitely have problems. Of course, like I said, trying to register the same handle will not overwrite it, so you would be getting the WordPress version of it, if you use the dependency parameter correctly.

    AJAX is no big deal, if you follow instructions.

    ritshidze

    (@ritshidze)

    hello @joha1234 did you come right? I am having the same problem

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Register styles’ is closed to new replies.