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.

[howto] Preferential category treatment? Fill 'x' containers with category a then fill remaining with b.

May 23, 2011 4:35pm

Subscribe [3]
  • #1 / May 23, 2011 4:35pm

    imjared

    23 posts

    The client has a channel with two categories, “current students” & “alumni.” They are asking for a gallery of current students and this gallery holds twelve items at a time.

    Ideally, there would be twelve “current students” channel entries and everything would be dandy. However, they would like that if for some reason the number of current students drops below 12 at any given time, the gallery would then pull in items tagged with “alumni.” As there is no way to use the “orderby” parameter to order by category, I’m a little stumped about how to do this. I was thinking an embedded template where I would pass a variable for how many items to display would be my solution but that seems a bit cumbersome. Anything I’m missing?

  • #2 / May 24, 2011 3:37am

    Mark Bowen

    12637 posts

    If I’m correct on my thinking as to what you want here then the only way I see this being done is to use an embedded template and some PHP magic (or create a plugin specifically for this purpose).

    I did do this once before on quite an old site now which is no longer live so don’t have access to the code any more but basically what I did was :

    1 - Main entries tag set to (in your case) output 12 entries.
    2 - Had a conditional in there which basically said if total_results is less than 12 then embed a template.
    3 - The embedded template gets the total_results amount sent along to it.
    4 - In the embedded template some PHP gets run first to figure out what 12 - total_results is and then this is used to limit a second entries tag in that template.

    Don’t know if that helps in this instance at all though?

    Best wishes,

    Mark

  • #3 / May 24, 2011 8:51am

    imjared

    23 posts

    This confirms exactly what I thought I might need to do. Thanks for chiming in here, Mark!

  • #4 / May 24, 2011 10:27am

    Mark Bowen

    12637 posts

    This confirms exactly what I thought I might need to do. Thanks for chiming in here, Mark!

    No problem at all. There might be other ways around it too so hopefully others will chime in here with ideas.

    If you do go this route though and have any problems just let me know and I’ll try to put some code together again to do this sort of thing.

    Best wishes,

    Mark

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

ExpressionEngine News!

#eecms, #events, #releases