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.

Formatting multiple category_id's - numbers run together

January 28, 2011 10:39pm

Subscribe [3]
  • #1 / Jan 28, 2011 10:39pm

    bthx79

    9 posts

    Hello,

    This may be a no-brainer, but I can’t seem to figure it out.

    I am working with some jquery to do client-side sorting based on category id’s.

    The category_id tag is placed inside a div class like this:

    <div class="sort all {categories limit="2"}{category_id}{/categories}">

    When the code is rendered, it looks like this:

    <div class="sort all 25">

    Note the number 25 being the category id of the selected category.

    I run into a problem when I have multiple categories. 

    For example, I have an entry that has 2 categories assigned with id’s of 25 and 28, it shows like this in the code:

    <div class="sort all 2528">

    The multiple categories butt up to each other.

    For my jquery sort to work, I need a space between each category_id like this:

    <div class="sort all 25 28">

    The categories are not nested.  They are all in the root.

    Let me know if you need any additional info.

    I am using EE version 2.1.3 20101220

    Thanks in advance for any insight.

    Best Regards

  • #2 / Jan 29, 2011 3:24pm

    bthx79

    9 posts

    Hello,

    I ended up getting this to work with the most excellent “Entry Categories”
    plugin from devot-ee.com
    Entry Categories Plug-in

    Here is the problem I was having when trying to obtain category id’s for
    my client-side jquery sort:

    Rendered page code:

    <div class="sort all 2130">

    Category ID’s 21 and 30 were stuck together, thus throwing off the sort.

    I used the following tag configuration from the Entry Categories plugin to obtain
    formatting for the separate category id’s.

    <div class="sort all {exp:entry_cats entry_id="{entry_id}" site="1"}{level0_category0_cat_id}{if level0_category1_cat_id} {level0_category1_cat_id}{/if}{/exp:entry_cats}">

    Now the category id’s appear with a space between them:

    <div class="sort all 21 30">

    If anyone else has trouble with this, check out the Entry Categories plug-in.

    http://devot-ee.com/add-ons/entry-categories/

    This is the reason I love EE so much!  With a little research, there is almost always
    a way to make things work!

    Best Regards

  • #3 / Jan 31, 2011 1:58am

    John Henry Donovan

    12339 posts

    bthx79,

    For my jquery sort to work, I need a space between each category_id

    Why not just add the space in your tag?

    <div class="sort all{categories limit="2"} {category_id}{/categories}">

    That will give you output like this

    <div class="sort all 25 28">
  • #4 / Jan 31, 2011 4:28pm

    bthx79

    9 posts

    Hello John,

    I knew it had to be something really simple!  Thanks for the tip!!

    I just had to add a space before the category_id tag.

    The Wrong Code:

    <div class="sort all {categories limit="2"}{category_id}{/categories}">

    The Right Code:

    <div class="sort all{categories limit="2"} {category_id}{/categories}">

    A much cleaner solution indeed! I did find other uses for the Entry Categories Plug-in, so the purchase was definitely not a waste.

    Thanks again for the tip!!

    Best Regards

  • #5 / Feb 01, 2011 10:52am

    Sue Crocker

    26054 posts

    Glad John was able to help. Don’t hesitate to post again as needed.

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

ExpressionEngine News!

#eecms, #events, #releases