ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

dynamic pagination list & query strings

April 04, 2008 2:19am

Subscribe [9]
  • #1 / Apr 04, 2008 2:19am

    Joobs

    362 posts

    I want to create a list of weblogs that can be dynamically sorted, but that can also be paginated. I notice that dynamic parameters dont work with pagination, and I really don’t want to use the search.

    I then thought that I could simply use a GET form to create a query string, and use some PHP to parse these values into the weblog:entries tag.  But it seems EE ignores anything after the question mark in the url.

    Do you have any suggestions how to achieve this?

    I’m a bit of a server noob, but I was wondering if I could do a .htaccess rewrite so it removes the question mark from the query string, allowing me to then use the url segment.

    I would imagine it creating something like http://www.example.com/templates/orderby=date&sort=desc&category=1/P0/

    Does this sound like it might work or are there any security concerns with this?

  • #2 / Apr 04, 2008 2:51am

    Matt Weinberg

    489 posts

    I can’t address the first part of the question because I’m not 100% sure what you’re asking, but regarding the second part: you can tag on “query strings” by just making new URL parameters (separated by slashes) and accessing them like this:

    http://expressionengine.com/docs/development/usage/input.html#segments

    I do it like this on one site:

    <?php 
       global $IN;
       if (isset($IN->SEGS[2])){
       $variable = $IN->SEGS[2];
       }
    ?>

    Does that help at all?

  • #3 / Apr 04, 2008 3:16am

    Joobs

    362 posts

    Thanks for your reply, but currently I am having an issue creating the URL parameters rather than reading them (that’s for later).

    I want to create a form with a few drop down options which can filter my weblog entries list (eg order by date), and when i submit this form this data is passed to the next page (and further paginated pages).  EE has a feature for dynamic parameters but the docs say this doesn’t work with pagination.

    The only solution for this I could think of is using a GET method on the form, which creates a query string like this “?orderby=date&sort=desc&category=1” in the URL, and then I get the variables from that segment using a bit of PHP in the template.  Unfortunatly ExpressionEngine doesn’t like URLs with question marks in them.

  • #4 / Apr 04, 2008 10:35am

    Sue Crocker

    26054 posts

    Joobs, I’ve asked the dev team from some help on this one..

  • #5 / Apr 04, 2008 12:02pm

    Derek Jones

    7561 posts

    ExpressionEngine works fine with query strings, but if you are not using the query delimiter immediately after index.php, you’ll find that your first variable needs to begin with ? to start the query string portion.  http://example.com/index.php/template_group/template/?foo=bar

    Then you can use $IN->GBL() to retrieve the items from the $_GET array.  But it seems tragically messy (from a URL standpoint) to me personally.  I would recommend backing up, and clearly defining your goals, not in terms of what you want the URLs to be or how you want to write your tags, but merely what you want your visitors to be able to do.  If you can define that with a bit greater detail than “I want to create a list of weblogs that can be dynamically sorted, but that can also be paginated.” then I’m sure that we or some members of the community can give you some solid suggestions, or give you a thumbs up on what you’re trying to do presently.

  • #6 / Apr 04, 2008 1:45pm

    Joobs

    362 posts

    I am creating a community based site using Solspace’s User module. On this site is a showcase section, where artists can upload content to 3 weblogs (music, images, videos).  Using Solspace’s User Module authors can also categorize themselves (Photographer, Artist, Poet etc).

    On the showcase section I want there to be options to browse the list of users, and browse lists of the different content types. This could be done using separate templates for each browse type (music, images, videos, users) using the normal weblog:entires tag.  For usability I would then like to be able to dynamically sort these entry lists (by altering the weblog:entires parameters somehow?), and remember these settings over several pages.  The only way I could think to do this was to pass the weblog parameters via the URL and insert them into the weblog:entries tag using php.

    The specific problem I am having with the query string is that it’s not being passed onto any future paginated pages from the pagination links it creates.

    So for a query string, it will work fine on the first page, but it will lose the string on future paginated pages:
    http://www.example.com/templates/?foo=bar&category=3
    http://www.example.com/templates/P4

    But if the variables are treated as a segment, the pagination links keep the segment in the url:
    http://www.example.com/templats/foo=bar&category=3/
    http://www.example.com/templats/foo=bar&category=3/P4

    I want this sorting to be done through drop down menus on a form, and i’m not sure how I can pass those variables into the URL.  Of course I am also interested in any other methods for doing a dynamic sort.

    Does this make things any clearer?

  • #7 / Apr 04, 2008 6:24pm

    Derek Jones

    7561 posts

    Just off the top of my head, you might be able to use jQuery to attach an event to the pagination links that would rePOST the information, using the pagination link as the action url for the form.  Or you could use GET as you are doing now and perhaps with an extension rewrite the pagination links, though that solution is less attractive to me.

  • #8 / Apr 04, 2008 7:04pm

    Joobs

    362 posts

    Thanks for the suggestion Derek.

    I was also thinking of using Cookie to save the POST information, this would have the advantage of having a clean URL.

  • #9 / Apr 06, 2008 1:12pm

    Robin Sowell

    13255 posts

    This jQuery based table sorter is sweet- and there’s a pagination plugin.  Not sure how lean it is- but the functionality is nice.  I flipped js off just to see how it degrades and seems like the full list shows- no pagination.  May/may not be viable in that regard.

  • #10 / Oct 03, 2008 4:04pm

    Paramore

    40 posts

    Joobs, we’re now in the same boat.  We have a table that has the exact requirements you’ve described, and even tried the jQuery Table Sorter with it’s accompanying pagination plugin (which I hacked to be filterable).

    But, that answer does not work when page load times become a problem.  We have a list of doctors, their related specialties (playa), and their related locations (playa), and if we were to request all 600 (or even half that), EE takes a while to render the page, which is not acceptable for such a large site.

    I’ve been toying with a URL structure like so:

    <a href="http://hospital.org/find_a_doctor/results/sortby/filter1/filter2/filter3/filter4/P0">http://hospital.org/find_a_doctor/results/sortby/filter1/filter2/filter3/filter4/P0</a>

    And the resulting page like so:

    {exp:weblog:entries 
        weblog="doctors" 
        status="Custom Status" 
        {if segment_5 == "orderby"}
            orderby="doc_first_name|doc_last_name" sort="asc" 
        {if:elseif segment_5 == "title_a"}
            orderby="title" sort="asc" 
        {if:elseif segment_5 == "title_d"}
            orderby="title" sort="desc" 
        {if:elseif segment_5 == "doc_services_a"}
            orderby="doc_services" sort="asc" 
        {if:elseif segment_5 == "doc_services_d"}
            orderby="doc_services" sort="desc" 
        {if:elseif segment_5 == "doc_locations_a"}
            orderby="doc_locations" sort="asc" 
        {if:elseif segment_5 == "doc_locations_d"}
            orderby="doc_locations" sort="desc" 
        {/if}
    
        {if segment_6 != "gender"} search:doc_gender="{segment_6}" {/if}
        {if segment_7 != "location"} search:doc_locations="{segment_7}" {/if}
        {if segment_8 != "language"} search:doc_language="{segment_8}" {/if}
        {if segment_9 != "service"} search:doc_services="{segment_9}" {/if}
    
        paginate="both"
        limit="10"}
    
        {!-- results go here --}
        {!-- pagination goes here --}
    {/exp:weblog:entries}

    This would seem to work, as I do get results, and I have pagination working fine, but the sort and filter options seem to never work.

    I could do a lot of this in PHP, but I’d rather keep a nice looking URL, and one that someone could give to their friend and it would populate results just as the original user saw it.

    Am I on the right track?  Should I be doing something else here?

    Thanks!
    Sean

  • #11 / Oct 03, 2008 4:05pm

    Sean Gates

    123 posts

    Nuts, I forgot to log out of our company login.  Sorry.

    —Sean

  • #12 / Oct 03, 2008 4:08pm

    Sean Gates

    123 posts

    Also here is a corrected url with orderby (instead of sortby):

    <a href="http://hospital.org/find_a_doctor/results/orderby/filter1/filter2/filter3/filter4/P0">http://hospital.org/find_a_doctor/results/orderby/filter1/filter2/filter3/filter4/P0</a>


    —Sean

  • #13 / Oct 05, 2008 12:21pm

    Robin Sowell

    13255 posts

    I think at this point I’m going to shift over to ‘How to’ as it’s more in the brainstorm realm.  I don’t see any particular reason the approach shouldn’t work.  But it’s complicated, so the best way to figure out why it’s not working is put just the weblog tag on a page all by itself- and then turn ‘Template debugging’ on in ‘Admin- System Prefs- Output and debug’.  See exactly what parameters end up going into your weblog tag.

    Odds are good something’s off in the logic, and the tag parameters aren’t what you want them to be.

    Of course- you’d want to make sure you’ve got the parameters nailed down as the first step.  Just hard code them, make sure the results are correct that way.  Then work on filtering until the filter logic returns the correct parameters.

    Make sense?

  • #14 / Oct 06, 2008 11:13am

    Sean Gates

    123 posts

    Thanks Robin.  I’ll give it a shot.

  • #15 / May 28, 2009 12:20pm

    Hoshman6000

    11 posts

    I know this is an older thread but I may have something that may be useful to others at some point. 

    I have built a few plug-ins to have custom advanced search capability, and ran into an issue with pagination not retaining the variables past displaying the first page. For example, if the results required 4 pages, the pagination links for the initial results page would correctly display links for 4 pages).  The problem came when you clicked on a pagination link to go to another page of results.  The variable placed from the results in the weblog tag (entry_id’{result_str}’ - result_str coming from my plug-in) would no longer hold its value. 

    The plug-in relies on POST variables to initially process the search, but once processed, simply finding a way to pass the result_str variable along would do the trick for pagination (though I wanted to hold the other variables to re-populate the sidebar advanced search form fields).

    Long story short (and not much code provided from the plug-ins - I can provide more if anyone desires) is I modified the mod.weblog.php file from:

    $PGR->suffix = '';

    to

    if(isset($_GET['suffix'])){
    $PGR->suffix = "?".$_GET['suffix'];
    } else {
    $PGR->suffix = '';
    }

    and use my plugin to set the GET suffix variable to a string carrying my results_str and any other desired variables.  When passed to the next page, these GET variables are processed by the plug-in that initially provided them as a pass-through to the output as well as back to the GET suffix variable.  Fairly simple and works amazingly well.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases