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.

Advice on how to load channel articles

September 08, 2010 5:03am

Subscribe [3]
  • #1 / Sep 08, 2010 5:03am

    fourlincoln10

    18 posts

    I’m creating a site that includes a bunch of recipes for fish. When a visitor is looking at a certain kind of fish, the site owner would like a sidebar to display up to 3 recipes that are associated with that type of fish. If there aren’t 3 recipes for that type of fish in the system, they’d like the sidebar to display enough recipes from other kinds of fish to make a total of 3 recipes.

    I thought I’d create a channel called recipes and populate that separate from my standard content channel. I’d assign a fish category to each recipe. I’m trying to figure out how I would then:

    1) Load up to 3 recipes from a certain category.
    2) If there aren’t 3 recipes, load 1,2 or 3 from the rest of the categories (not the one I originally tried)
    3) Output summaries (pulled out of a summary custom field in the recipe) and links to the 3 recipes together as a group.

    I think I can do it using conditionals, but I’m not sure how to pull from categories other than the one I tried initially. Will someone tell me how to do that?

    Thanks,

    Troy

  • #2 / Sep 08, 2010 5:51am

    Cheif

    626 posts

    I’d look into using embeds, I’m only just discovering their power so bare with the crude code…

    on the actual article page in the recipe section:

    {embed="_sideitems/recipes" categories="fish"}

    then in _sideitems/recipes I’d put something like (dont quote me)

    {exp:channel:entries channel="yourrecipeschannel" limit="3" sortby="{embed:categories}"}
      {!-- That last bit sortby="{embed:categories}" ... pulls the variable we set in the 1st bit
    and uses the category to sort the results by --}
      {title}, {body} {URL} etc
    {/exp}
  • #3 / Sep 08, 2010 3:19pm

    Brandon Jones

    5500 posts

    Thanks, Cheif.

    Troy, this would be a better question for the CodeShare Corner as there are multiple approaches. Shifting this over there.

  • #4 / Sep 08, 2010 5:14pm

    fourlincoln10

    18 posts

    Okay…thanks to both of you.

    Troy

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

ExpressionEngine News!

#eecms, #events, #releases