0

I have a SQL query set-up to display a list of entries based on the category ID found in the third segment, but I'm having a hell of a time trying to display the category name that goes along with it. This is what I have that's currently working:

SELECT
    cd.field_id_19 AS song_number,
    cd.field_id_20 AS song_title,
    cd.field_id_21 AS song_artist
FROM exp_channel_data cd
LEFT JOIN exp_category_posts cp
ON cd.entry_id = cp.entry_id
WHERE cp.cat_id = {segment_3_category_id}

I know I have to add a JOIN with the exp_categories table in order for the exp_category_posts.cat_id to retrieve cat_name, but have not been successful in working it out.

Any help would be greatly appreciated.

  • Do you want to get the cat_name of the category on segment_3 or of all categories of every entry? – Robson Sobral Jul 1 '14 at 1:03
0

This plugin will give you all of that functionality that you can pass into a channel entries tag. http://gotolow.com/addons/low-seg2cat

Example:

{exp:channel:entries channel="channel_name" category="{segment_3_category_id}"}
      {count} of {total_results} of the entries associated with that cat.

      {segment_3_category_name}
{/exp:channel:entries}

Hope this helps!

| improve this answer | |
  • Wow I feel like an idiot. Thanks for pointing out the easiest of solutions there! – Roger Erik Tinch Jul 1 '14 at 14:42
  • No problem this is a standard in all my EE installs. It is a great plugin and makes life easy. – mattsidjohn Jul 1 '14 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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