WordPress.org

Ready to get started?Download WordPress

Forums

EasyRotator for WordPress - Slider Plugin
[resolved] Pass php variable to dynamic slider (9 posts)

  1. RobReg
    Member
    Posted 1 year ago #

    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/

  2. DWUser.com
    Member
    Plugin Author

    Posted 1 year ago #

    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

  3. RobReg
    Member
    Posted 1 year ago #

    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

  4. DWUser.com
    Member
    Plugin Author

    Posted 1 year ago #

    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 .

    Sincerely,
    Drew O'Neill

  5. RobReg
    Member
    Posted 1 year ago #

    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

  6. DWUser.com
    Member
    Plugin Author

    Posted 1 year ago #

    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

    Sincerely,
    Drew O'Neill

  7. RobReg
    Member
    Posted 1 year ago #

    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

  8. DWUser.com
    Member
    Plugin Author

    Posted 1 year ago #

    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/

    Be sure to post back if you run into any other issues.

    Sincerely,
    Drew O'Neill

  9. RobReg
    Member
    Posted 1 year ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.