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.

Allowing user to choose number of entries displayed

August 27, 2008 5:18pm

Subscribe [3]
  • #1 / Aug 27, 2008 5:18pm

    Chad Clark

    20 posts

    Is it possible to have a user choose the number of entries displayed on a page?

    Currently, I have 6 entries displaying:

    {exp:weblog:entries weblog="{my_weblog}" status="open|new" limit="6" sort="ascending" paginate="both"}

    Ideally, I would like to have the user choose how many entries are displayed per page (20, 50 etc.) and maintain pagination depending on the selection.

    Any suggestions?

  • #2 / Sep 01, 2008 4:00am

    Marks

    100 posts

    Hi,

    I think you will need a small form with the dropdown containing numbers for selection by user. Then either use onChange() event or simply post the form to itself e.g. same page and get the posted value and use it in your query to display the number of entries based on the number selected. There might be a need to even customise the pagination. EE one might not work since you will be using php to display the entries. I don’t know if there is another way of doing this. But that is all I could think.

    $sql = “SELECT * FROM exp_weblog_data LIMIT “.$selectedByUser;

    This is just an example of a query you could make. Not sure if this helps.

    Regards,
    Marks

  • #3 / Sep 01, 2008 5:34am

    Ingmar

    29245 posts

    Chad, if I had to do this I’d use url segments:

    <a href="http://example.com/index.php/group/template/show99">http://example.com/index.php/group/template/show99</a>

    Then use {segment_3} with a bit of PHP (removing the leading ‘show’ in this case, as it were) parsed on Input to define the “limit” parameter. Makes sense?

  • #4 / Sep 01, 2008 5:42am

    Marks

    100 posts

    Hi Ingmar,

    Thanks. I think your approach is the easiet to apply and I’d suggest use of it.

  • #5 / Sep 01, 2008 8:39am

    Chad Clark

    20 posts

    Hi Marks and Ingmar,

    Thanks for the suggestions.

    Chad, if I had to do this I’d use url segments:

    <a href="http://example.com/index.php/group/template/show99">http://example.com/index.php/group/template/show99</a>

    Then use {segment_3} with a bit of PHP (removing the leading ‘show’ in this case, as it were) parsed on Input to define the “limit” parameter. Makes sense?

    If it’s not too much trouble, do you think you could post an example of how this may be written. I have somewhat of an idea, but I don’t think I am completely there.

    Thank you.

  • #6 / Sep 01, 2008 8:59am

    Ingmar

    29245 posts

    Well, let’s see:

    {exp:weblog:entries limit="<?=substr("{segment_3}", 4);?>"}
    {title}
    
    {/exp:weblog:entries}

    That should work, provided you have “showxx” in segment 3.

  • #7 / Sep 01, 2008 1:43pm

    Chad Clark

    20 posts

    I don’t think I grasping this quite yet.

    {exp:weblog:entries limit="<?=substr("{segment_3}", 4);?>"}
    {title}
    
    {/exp:weblog:entries}

    I guess I am not understanding how calling out {segment_3} will parse out the number of posts to show. Is it a matter of calling out a specific template? For example, instead of {segment_3}, would it be something like {show99}?

    In addition, would the template I’m referring to in the php be set up as simply as:

    show99

    ?

    Hopefully I’m making sense.

    Thanks!

  • #8 / Sep 01, 2008 1:54pm

    Ingmar

    29245 posts

    You will need to provide the required number in the URL itself:

    <a href="http://example.com/index.php/group/template/show10">http://example.com/index.php/group/template/show10</a>
    <a href="http://example.com/index.php/group/template/show25">http://example.com/index.php/group/template/show25</a>

    Adapting these excamples would show 10 or 25 entries, respectively. Now all that’d remain is a pull down menu or something like it to link to URLs like that.

  • #9 / Sep 01, 2008 1:56pm

    Chad Clark

    20 posts

    Ah, okay. That is making sense. I’ll see if I can make it all come together.

    Edit:
    I was able to get it functioning the way I wanted. I threw in some conditionals for the default view, also:

    {exp:weblog:entries weblog="{my_weblog}" status="open|new" limit={if segment_2 == ""}"6"{/if}{if segment_2 != ""}"<?=substr("{segment_2}", 4);?>"{/if} sort="ascending" paginate="both"}

    Thanks for your help!

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

ExpressionEngine News!

#eecms, #events, #releases