0

Is there any way to do this in ExpressionEngine (3.5.10)....

I have a channel of services offered by a company. The channel name is called services. I then have a list of news articles in a channel called news.

There will be around 50 services and hundreds (or potentially thousands) of news articles.

What I want to do is when a user is looking at a particular service, I want to show news articles that are relevant.

However, any workflow for the publisher (the person using the EE Admin panel) is tedious, or it seems impossible to write a query in the template to do the job.

For example, it could technically be done like this:

  1. Set up a Relationship on news such that I can say which services it applies to. I don't understand how I could then query this to get the actual news content when viewing a service on the front-end because the relationship exists on the news channel entry, not the services channel entry. ** see notes below for what the intended outcome is here and you'll understand what the issue with this is.

  2. Set up a Relationship on services and select the appropriate news. This is impractical because of the amount of work it would involve to maintain. For example every single time a news entry is published the publisher would have to go into potentially 50 services rather than being able to do it from 1 place.

  3. Use categories... not really sure where to begin with that as I could set up categories on my news articles (where the categories are the names of the services) but then unsure how to query this in the template. For example, I don't understand in terms of writing a query, how you could correlate a category name (or category slug) to specific channel entries.

** The relevant template is the one which shows details of an individual service. These are set up with a URL structure like so:

  • /services/service-one
  • /services/service-two
  • /services/another-service
  • ...

So when the user goes to /services/service-two it should list any news entries that are relevant to service-two.

What is the most efficient way of doing this in terms of:

  1. Workflow for the publisher, i.e. the least number of clicks and data entry.
  2. Something that scales well given there may be 50 services and >1000 news articles, with further news articles being added daily.
  3. How does the proposed solution work in the template - i.e. when I'm looking at services/service-two what code do I need to bring out the list of news entries such that I can read at least their title and URL?

My apologies if the answer to this is obvious but I've thought about it so long now I'm asking for help as I can't see a way around it.

1 Answer 1

2

Categories is the primary method I would choose given your outline. Each categories category url should match the URL name of the service whereas the category title can be whatever you want it to be. It will require some work upfront and on-going but so would any other approach.

Then, assign all your news articles at least one if not multiple categories. Hey, news articles might apply to more then one service so makes sense.

Grab your traditional services content through

{exp:channel:entries channel="services" url_title="{segment_2}....}

  your code here

{/exp:channel:entries}

Then wherever you need to insert your news articles (using lows seg2cat)... because EE uses the category ID not the URL in the channel call.

{exp:channel:entries channel="news" category="{segment_2_category_id}" dynamic="no" limit="10"}

  your code here

{/exp:channel:entries}

Thats about it, you can futz around with order, limits and asc/desc to suit... because no one wants 100's of links to other news.

1
  • Thanks, this looks like a really good solution. News articles do apply to more than one service so that also sounds great. Thank you.
    – Andy
    Oct 3, 2017 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.