Title: Pass php variable to dynamic slider
Last modified: August 20, 2016

---

# Pass php variable to dynamic slider

 *  Resolved [RobReg](https://wordpress.org/support/users/robreg/)
 * (@robreg)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/pass-php-variable-to-dynamic-slider/)
 * Hello,
 * Great plugin, really like it. I’ve created a dynamic slider for one of my categories
   and tags which is what I want to do but I’d like to add the php code to my template
   page and allow it to use a variable passed to it to display whichever tag or 
   category I pass to it, if that makes sense?
 * Is there a way that I can do this?
 * Thanks in advance,
    Rob
 * [http://wordpress.org/extend/plugins/easyrotator-for-wordpress/](http://wordpress.org/extend/plugins/easyrotator-for-wordpress/)

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

 *  Plugin Author [DWUser](https://wordpress.org/support/users/dwusercom/)
 * (@dwusercom)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/pass-php-variable-to-dynamic-slider/#post-3151424)
 * Hi Rob,
 * Thanks for using EasyRotator for WordPress. If you’re comfortable with PHP coding
   and modifying plugin code, you can add this functionality. To do this, you’ll
   need to modify the `easyrotator-for-wordpress/easyrotator.php` and `easyrotator-
   for-wordpress/engine/main.php` files:
 * **In `easyrotator.php`:**
 * Edit the `easyrotator_display_rotator` method (around line 2110), to add another
   parameter that’s passed on to the `renderRotator` method.
 * **In `main.php`:**
 * Edit the `renderRotator` method (around line 1170), adding the new parameter 
   to the method signature, then using it to run a replace on `$contentDiv` immediately
   before the `replaceDynamicRotatorHTML()` call on line 1258. The replace should
   look for code like this (the `erwpFeaturedPhotos` `li`):
 * `<li class="erwpFeaturedPhotos" data-filter="recent" data-filterDetail="" data-
   limit="10" data-order="desc" data-excludeCurrent="true" data-includeExcerpt="
   true" data-includeLinks="true" data-linkTarget="_self" data-fullSize="full" data-
   thumbSize="thumbnail"></li>`
 * Update the `filter` and `filterDetail` values as desired; you can learn more 
   about the appropriate values to use by looking at existing `content.html` files
   in subfolders in the `wp-content/uploads/EasyRotatorStorage/user-content/` folder.
 * Please let me know if you have any other questions.
 * Sincerely,
    Drew O’Neill
 *  Thread Starter [RobReg](https://wordpress.org/support/users/robreg/)
 * (@robreg)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/pass-php-variable-to-dynamic-slider/#post-3151438)
 * Thank you very much for a quick and detailed reply, Drew.
 * There is just one part I don’t understand:
 * > “then using it to run a replace on $contentDiv immediately before the replaceDynamicRotatorHTML()
   > call on line 1258”
 * At the moment that line looks like this:
 *     ```
       // Search for dynamic content and replace
         $contentDiv = self::replaceDynamicRotatorHTML($contentDiv);
       ```
   
 * I don’t quite understand what I am supposed to change on that part? Any guidance
   would be appreciated.
 * Cheers,
    Rob
 *  Plugin Author [DWUser](https://wordpress.org/support/users/dwusercom/)
 * (@dwusercom)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/pass-php-variable-to-dynamic-slider/#post-3151443)
 * Hi Rob,
 * Suppose you have passed a new parameter, `$filter`. This `$filter` might be of
   this format:
 * `array('filter'=>'tags', 'filterDetail'=>'any:12')`
 * The `filter` property could be `tags` or `cats` (categories), and the `filterDetail`
   starts with `any:` or `all:` and ends with a comma-separated list of numeric 
   category or tag IDs. So, suppose you have two tags with IDs 12 and 13 and want
   to display posts with *both* tags. You would pass a parameter like this:
 * `array('filter'=>'tags', 'filterDetail'=>'all:12,13')`
 * Then, add a line before 1258:
 * `$contentDiv = preg_replace('|<li class="erwpFeaturedPhotos".*?data-filterDetail
   ="[^"]*"|', '<li class="erwpFeaturedPhotos" data-filter="' . $filter['filter'].'"
   data-filterDetail="' . $filter['filterDetail'] . '"', $contentDiv);`
 * Here’s a gist with some of this code: [https://gist.github.com/8371ce267d480d2b6859](https://gist.github.com/8371ce267d480d2b6859).
 * Sincerely,
    Drew O’Neill
 *  Thread Starter [RobReg](https://wordpress.org/support/users/robreg/)
 * (@robreg)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/pass-php-variable-to-dynamic-slider/#post-3151448)
 * Hello Drew,
 * Great, thank you for the help. I feel like I’m almost there…Apologies for my 
   basic php knowledge, but I’m learning 🙂
 * Perhaps I could just outline exactly how the flow would work and then it might
   make more sense.
 * There is a map on my homepage and a user clicks on the Europe continent. The 
   url that page goes to has a variable passed through in the url, so something 
   like:
 * “www.mysite.com/continent.php?continent=europe”
 * When the continent.php page loads, I want it to take that continent=europe parameter
   and use it dynamically in the slider to show only posts from Europe.
 * _What I’ve done so far…_
 * I’m using this code below to get the category ID from the slug name of the continent(
   my categories are all of the continents). Not sure if I need to add this to one
   of the easyrotator files or just ensure that it is added to the page which is
   being called, continent.php in this EG?
 *     ```
       $idObj = get_category_by_slug($continent);
         $id = $idObj->term_id;
       ```
   
 * So I’m thinking that I need to build up an array in my page continent.php which
   is then used in the easyrotator function? Something like this:
 * `$temp_array=('filter'=>'tags', 'filterDetail'=>$id)`
 * I’m not sure how to build this array!?
 * I would then add the $temp_array to this function in easyrotator.php
 *     ```
       function easyrotator_display_rotator( $rotatorID, $echo=true )
       {
       	global $erwp;
       	$content = $erwp->renderRotator($rotatorID,$temp_array);
       	if ($echo)
       		echo($content);
       	return $content;
       }
       ```
   
 * Then, I would add the same parameter in main.php to line 1170:
 * `public function renderRotator($fullPath,$temp_array)`
 * Just before line 1258 in the same main.php file I would add:
 * `$contentDiv = preg_replace('|<li class="erwpFeaturedPhotos".*?data-filterDetail
   ="[^"]*"|', '<li class="erwpFeaturedPhotos" data-filter="' . $temp_array['filter'].'"
   data-filterDetail="' . $temp_array['filterDetail'] . '"', $contentDiv);`
 * I hope this makes sense and are able to help me over this last hurdle!
 * Thanks again for your excellent advice,
    Rob
 *  Plugin Author [DWUser](https://wordpress.org/support/users/dwusercom/)
 * (@dwusercom)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/pass-php-variable-to-dynamic-slider/#post-3151451)
 * Hi Rob,
 * It’s a little hacky, but the simplest solution is to only modify the `renderRotator`
   method, and conditionally take action on the `continents.php` file. That requires
   only one addition to the `main.php` file:
 * [https://gist.github.com/8371ce267d480d2b6859](https://gist.github.com/8371ce267d480d2b6859)
 * Sincerely,
    Drew O’Neill
 *  Thread Starter [RobReg](https://wordpress.org/support/users/robreg/)
 * (@robreg)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/pass-php-variable-to-dynamic-slider/#post-3151452)
 * That’s amazing! Thank you so much for helping me with this.
 * I might have to add some more ELSEIF hacks for the other pages that I’m working
   on…I will have a play around with that.
 * Hopefully this will help others out too, as I’m sure a lot of people must want
   to only have one page and display a different set of posts depending on a variable
   passed to it.
 * Thanks again, Drew.
 * Rob
 *  Plugin Author [DWUser](https://wordpress.org/support/users/dwusercom/)
 * (@dwusercom)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/pass-php-variable-to-dynamic-slider/#post-3151453)
 * Hi,
 * I’m happy to help! If you have a minute, we always appreciate plugin (and support)
   ratings: [http://wordpress.org/extend/plugins/easyrotator-for-wordpress/](http://wordpress.org/extend/plugins/easyrotator-for-wordpress/)
 * Be sure to post back if you run into any other issues.
 * Sincerely,
    Drew O’Neill
 *  Thread Starter [RobReg](https://wordpress.org/support/users/robreg/)
 * (@robreg)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/pass-php-variable-to-dynamic-slider/#post-3151494)
 * Hello again Drew,
 * I’ve been playing around with this and realised that it doesn’t quite work as
   intended. The code when using $_SERVER[‘SCRIPT_NAME’] only returns index.php 
   each time.
 * I changed it to use this instead:
 *     ```
       if (in_array(substr($_SERVER['REQUEST_URI'],1,strpos($_SERVER['REQUEST_URI'],"/",1)), array('continent/','country/')))
       {
          $catDataObj = get_category_by_slug( @$_GET['continent'] );
          if ($catDataObj !== false) // check that we have a valid continent value
          {
             $cid = $catDataObj->term_id;
             $filter = array('filter'=>'cats', 'filterDetail'=>'all:' . $cid);
             $contentDiv = preg_replace('|<li class="erwpFeaturedPhotos".*?data-filterDetail="[^"]*"|', '<li class="erwpFeaturedPhotos" data-filter="' . $filter['filter'] . '" data-filterDetail="' . $filter['filterDetail'] . '"', $contentDiv);
          }
       }
   
       		// Search for dynamic content and replace
       		$contentDiv = self::replaceDynamicRotatorHTML($contentDiv);
       ```
   
 * Just thought I’d share it because someone else might find it useful.
 * Thanks,
    Rob

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

The topic ‘Pass php variable to dynamic slider’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/easyrotator-for-wordpress_72a6c3.
   svg)
 * [EasyRotator for WordPress - Slider Plugin](https://wordpress.org/plugins/easyrotator-for-wordpress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/easyrotator-for-wordpress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/easyrotator-for-wordpress/)
 * [Active Topics](https://wordpress.org/support/plugin/easyrotator-for-wordpress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/easyrotator-for-wordpress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/easyrotator-for-wordpress/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [RobReg](https://wordpress.org/support/users/robreg/)
 * Last activity: [13 years, 6 months ago](https://wordpress.org/support/topic/pass-php-variable-to-dynamic-slider/#post-3151494)
 * Status: resolved