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.

Paginate entries on a single page

September 05, 2011 6:32am

Subscribe [2]
  • #1 / Sep 05, 2011 6:32am

    warrenkeith

    29 posts

    Hi there,

    I’m trying to separate my entries into blocks of three, but I can’t think of a way of doing it without setting up lots of code blocks with entry counts and offsets.

    Is there an easy way to output:

    <ul>
    <li>hello</li>
    <li>hello</li>
    <li>hello</li>
    </ul>
    
    <ul>
    <li>hello</li>
    <li>hello</li>
    <li>hello</li>
    </ul>
    
    <ul>
    <li>hello</li>
    <li>hello</li>
    <li>hello</li>
    </ul>

    from 9 individual entries?

    Any advice appreciated!

  • #2 / Sep 05, 2011 6:55am

    Mark Bowen

    12637 posts

    Hi becordial,

    As long as you know you will definitely only ever have 9 entries (or multiples of 3 entries at least) then this code should get you what you need here :

    {exp:channel:entries
        channel="test"
        limit="3"
        dynamic="no"
        url_title="one|two|three"
        disable="member_data|trackbacks|categories|category_fields|pagination"}
    
    {switch="<ul><li>|<li>|<li>"}{title}{switch="</li>|</li>|</li></ul>"}
    
    {/exp:channel:entries}

    Bare in mind though that as soon as you have any more or less than 9 entries that isn’t a multiple of 3 then this is going to break on your site and something like the 3rd party add-on called Splitter (Documentation Link) might be able to sort you out on this too.

    Let us know if that’s any good to you.

    Thanks.

    Mark

  • #3 / Sep 05, 2011 7:02am

    warrenkeith

    29 posts

    Thank-you very much for pointing me in the right direction!

    I know I’ll only ever want 3 entries per slot but it won’t necessarily be multiples of 3.

    I’m going to give you first idea a shot to see what happens but do you know in what way this would ‘break’ the output?

    Failing that I’ll definitely try splitter. I’ve skimmed the documentation but do you happen to know if rather than splitting entries into evenly sized ‘blocks’ I’ll be able to specify the size of the block?

    Thanks for the advice, much appreciated!

  • #4 / Sep 05, 2011 7:31am

    Mark Bowen

    12637 posts

    Thank-you very much for pointing me in the right direction!

    No problem at all.

    I’m going to give you first idea a shot to see what happens but do you know in what way this would ‘break’ the output?

    Break may have been slightly too strong a word for me to have used there but basically if you were to have any number of items that isn’t a multiple of 3 (based on the code shown above) then you could end up not having the end </ul> closing tag which would mean you wouldn’t get valid source code.

    Failing that I’ll definitely try splitter. I’ve skimmed the documentation but do you happen to know if rather than splitting entries into evenly sized ‘blocks’ I’ll be able to specify the size of the block?

    Sorry I’m not too sure what you mean by “rather than splitting entries into evenly ‘sized’ blocks” as opposed to “specify the size of the block”?

    I may need to move this post to the Community Help forum soon as this is really more of a how-to question than a Technical question however if you let me know what you meant by the above two statements then I’ll do my best to answer them wherever I can.

    Cheers,

    Mark

  • #5 / Sep 05, 2011 7:55am

    warrenkeith

    29 posts

    Sorry if some of what I’m asking is a bit vague! And apologies if this is in the wrong place - I haven’t used the forums for a while.

    I’ve got Splitter working well, but the only variable you can set seems to be the number of blocks, rather than the number of items per block.

    In my case I need three entries per block, regardless of how many entries there are.

    If I’m understanding the plugin correctly, you can only set the number of blocks, into which the entries would be evenly distributed.

    I’m now thinking that I would need to make a calculation to work out how many blocks I would need for any given number of entries. So something like

    {number of entries}/3={number of columns needed}

    I would also need to round the number up!

  • #6 / Sep 05, 2011 9:33am

    Mark Bowen

    12637 posts

    Hi,

    Sorry if some of what I’m asking is a bit vague! And apologies if this is in the wrong place - I haven’t used the forums for a while.

    No problem at all. We can always move the post to a more appropriate forum if needed.

    I’ve got Splitter working well, but the only variable you can set seems to be the number of blocks, rather than the number of items per block.

    In my case I need three entries per block, regardless of how many entries there are.

    Well using the switch example I showed above will split the entries into blocks of 3 however it expects there to be 3,6,9,12… entries as it basically just places the information required before and after each block.

    If I’m understanding the plugin correctly, you can only set the number of blocks, into which the entries would be evenly distributed.

    I’m afraid I haven’t used that plugin much and so don’t know enough about it to be able to answer to it. You would need to contact the developer of that plugin to find out more as it’s a 3rd party plugin and so not something that we can support I’m afraid. I just put that out there as an example as it’s close to the kind of thing you’re looking for here.

    I’m now thinking that I would need to make a calculation to work out how many blocks I would need for any given number of entries. So something like

    {number of entries}/3={number of columns needed}

    I would also need to round the number up!

    If you need to go down this route then it would definitely require some custom coding or a custom add-on as you would be needing to utilise something like a modulo calculation to get what you need. I believe there is a 2.x plugin here - http://ellislab.com/forums/viewthread/132133/#721476 although again this couldn’t be supported as it’s a 3rd party offering. Might be a place to start with this though.

    Other than that I can suggest that perhaps if you want me to we go ahead and move this thread over to the Community Help forums and perhaps someone in there can help out or has done this sort of thing before and can lend a hand.

    Would you like me to do that for you?

    Cheers,

    Mark

  • #7 / Sep 05, 2011 9:35am

    warrenkeith

    29 posts

    Great, thank you - yes please do move it over. Regardless of how I end up getting there I shall document it here!

    Many thanks!

    😊

  • #8 / Sep 05, 2011 9:37am

    Mark Bowen

    12637 posts

    Great, thank you - yes please do move it over.

    Will do, thanks.

    Regardless of how I end up getting there I shall document it here!

    Many thanks!

    😊

    That’s great thanks. If you find a solution then that will help out others so thank you for the offer.

    Mark

  • #9 / Sep 05, 2011 10:45am

    warrenkeith

    29 posts

    I ended up with some help from a PHP friend to achieve this, by setting up a simple counter and inserting a closing and new opening list element per the number set….

    <ul>
    
    <?php $counter = 0; ?>
    
    {exp:weblog:entries}
    
        <?php if($counter >= 3 ) {
            echo '</ul><ul>';
            $counter = 0;
            } else {
                $counter++;
            }
        ?>
    
    <li>
    
    {title}
    
    </li>
    
    {/exp:weblog:entries}
    
    </ul>

    Not an EE solution but works perfectly for me! Hope it helps someone else…

  • #10 / Sep 05, 2011 10:51am

    Mark Bowen

    12637 posts

    Glad your friend was able to help out here so quickly and thanks for sharing your solution with everyone else as I’m sure it may well come in handy for others needing to do this sort of thing in the future.

    Thanks.

    Mark

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

ExpressionEngine News!

#eecms, #events, #releases