About this topic

  • Posted by WindupHarlequin 1 year ago. There are 4 posts. The latest reply is from byron.
  • This topic is not resolved
  1. Hi there!

    First of all, fantastic plugin. I'm impressed not only by the scope of it all, but by your fantastic support. It's rare to find developers so quick to reply :)

    My question is this: is there a means to determine the order by which a gallery is sorted, within the shortcode itself? I'm aware of the option to set the default ordering within the admin panel, but I'm thinking something more akin to:
    [photosmash id=2 sort_type=rating sort_order=asc]

    The reason I ask is that I need functionality to allow users to switch between viewing a gallery by rank, date added, and title. I could use multiple galleries, but that;s rather messy and unnecessarily complicated.

    Even if you haven't implemented this yet, would you be able to suggest where I should add my own code to achieve this? I gather that the main shortcode parameters are in bwb-photosmash.php, and the main SQL is generated in bwbps-layout.php. If you could give me any hints about where to look to implement a system such as the one I've proposed, it would be fantastic, and I'd be more than happy to supply you with my code should I get it working (if you feel that it would be a valuable addition to the plugin).

    Many thanks,
    - WindupHarlequin

  2. Hi WindupHarlequin,

    Thanks for your kind comment!

    Sorting is not implemented in the shortcodes (though it has been requested several times). You're exactly right on the where the shortcodes are handled and where the SQL gets generated.

    The easiest thing to do might be to put code into your theme that checks a $_GET or $_POST parameter for a specified sort type, something like:

    $gallery_id = 23; // set your gallery id here if you know it
    
    switch ($_GET['bwbps_sort_order'] ){
    
    case 'ranked' :
      echo do_shortcode("[photosmash gallery_type='ranked' gallery_where=" . $gallery_id . "]");
      break;
    
    case 'recent' :
    echo do_shortcode("[photosmash gallery_type='ranked' gallery_where=" . $gallery_id . "]");
      break;
    
    case 'name' :
     // Well, I haven't implemented this (at least I don't remember doing it).
    
    default :
    echo do_shortcode("[photosmash id=" . $gallery_id . "]");
      break;
    
    }

    If you do choose to code it up in PhotoSmash instead of that cheesy theme workaround, I'll be glad to incorporate. If you can encapsulate your code into functions that I can call (do as I say, not as I do :P ) that will make it easier to add it to my development version. You'll want to code up a little form that can pass along the gallery ID and the sort or and be inserted somewhere in the Gallery. We'll want to have a tag for it so it can be inserted into custom galleries as well as standard galleries.

    Note that you can affect sort order/field with the:

    $galparms['sort_field']
    $galparms['sort_order']

    fields in the bwb-photosmash.php shortCodeGallery function. You'll want to look down in there to see where the last place I set it is, then perform your check on it after that. Also, note that it uses the sort field type ID and sort order ID as Ints, not the names, which would have made it easier. You should be able to figure them out from viewing source on the Gallery Settings page where you can set them for a gallery.

    The earlier method (the one with the different galleries...I know you weren't thrilled with the option) is probably a lot less work, though, as you say it is a bit messier. I haven't tested it, but it will probably work.

    Thanks for being willing to contribute!
    Byron

  3. Hey.

    Thanks for the speedy response. I've almost got a working shortcode implementation - I've added sort_order=ASC or sort_order=DESC to the shortcodes, and I'm just aliasing proper names to the sort_field IDs. Just digging through the code, I wonder if maybe you're unecessarily replicating functionality when you generate the $sortby variable based on gallery_type - it seems like there's some degree of code repetition and some logic that really would be better suited in the getSortbyField() function. For instance:

    case 20:	// Random
    	$sortby = 'RAND() ';
    	if(!(int)$g['limit_images']){
    		$limitimages = " LIMIT " . $limitpage . "8";
    	}
    
    	$sortby .= $limitimages;
    
    	break;
    
    case 30:	// Recent
    	$sortby = PSIMAGESTABLE.'.created_date DESC ';
    	if(!(int)$g['limit_images']){
    		$limitimages = " LIMIT " . $limitpage . "8";
    	}
    
    	$sortby .= $limitimages;
    
    	break;

    Could be simplified to

    switch ($g['gallery_type']){
    case 20:	// Random
    	$sortby = 'RAND() ';
    	break;
    case 30:	// Recent
    	$sortby = PSIMAGESTABLE.'.created_date DESC ';
    	break;
    }
    if(!(int)$g['limit_images']){
    	$limitimages = " LIMIT " . $limitpage . "8";
    }
    $sortby .= $limitimages;

    I gather that you're working on a new release, so you may already have addressed this. Will post again when I've got the full shortcode code working :)

  4. Thanks WUH!

    BB

RSS feed for this topic