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.

display only categories from a certain member and no empty

December 06, 2011 5:41am

Subscribe [2]
  • #1 / Dec 06, 2011 5:41am

    amra01

    45 posts

    Hi I am trying to display some categories from a certain member and display them only if they have some data I can do them separate but I can’t do them both.

    this is what I am using to get the categories but where can I use the author_id ?

    {exp:channel:categories channel="products" show_empty="no" parent_only="yes"}
     <li>
    <a href="http://{site_url}index.php/dimitriadis/products/categories/C{category_id}">{category_name}</a>
     </li>
    {/exp:channel:categories}

    and this is the alternate way but using limit I only get as many categories as the entries double and triple the same category.

    {exp:channel:entries author_id="97" channel="products" dynamic="no" limit="1" disable="pagination"}
    {categories}
    <li>
    <a href="http://{site_url}index.php/dimitriadis/products/categories/C{category_id}">{category_name}</a>
    </li>
     {/categories}
    {/exp:channel:entries}

    what should I do? if there was author_id inside the exp:channel:categories or an if statement for the author?

     

  • #2 / Dec 07, 2011 11:08am

    Kevin Smith

    4784 posts

    Hi amra01,

    Unfortunately, it looks like you’re not going to be able to accomplish what you’re looking to do natively. The Channel Categories tag is meant to display categories for a given Channel. The categories loop inside the Channel Entries tag is meant to display categories for the entries that are returned by the Channel Entries loop. The results aren’t always going to be the same since it’s meant to display different things.

    To accomplish what you need, you would need an author_id parameter for the Channel Categories tag indeed, and I would suggest making a Feature Request for that very thing.

    Have you tried checking Devot://ee for category-related add-ons? I believe there might be a few there that allow more fine-grained control over which categories are displayed.

  • #3 / Dec 08, 2011 6:24am

    amra01

    45 posts

    thanks for the reply, add ons don’t seem to do what I want,
    maybe something like this could work? problem is I don’t know anything about sql but if a correct sql query is placed inside limiting to the author_id I want, can do the job.

    {exp:channel:categories channel="products" show_empty="no" parent_only="yes"}
           
    {exp:query sql="SELECT cat_id as category_id, cat_name AS category_name FROM exp_categories WHERE parent_id = '1' LIMIT 1"}
           
    <li>
     <a href="http://{site_url}index.php/dimitriadis/products/categories/C{category_id}">{category_name}</a>
    </li>
    without the sql query I get all the parent categories with a post inside.         
    {/exp:query}
           
    {/exp:channel:categories}
  • #4 / Dec 08, 2011 7:19am

    ahmad saad

    364 posts

    try this sql:

    SELECT distinct exp_cat.cat_id as category_id, exp_cat.cat_name AS category_name 
    FROM exp_categories exp_cat,exp_category_posts exp_cat_p,exp_channel_titles exp_ch_t  
    WHERE  exp_cat.parent_id = '0' 
    and exp_cat.cat_id=exp_cat_p.cat_id 
    and exp_cat_p.entry_id=exp_ch_t.entry_id 
    and exp_ch_t.author_id="2"

     

    or u can use embed like this (I don’t test it)

    main temp:

    {exp:channel:categories channel="products" show_empty="no" parent_only="yes"}
     {embed="include/.cat_link" cat_id="{category_id}"}
    {/exp:channel:categories}

    then in .cat_link temp:

    {exp:channel:entries author_id="97" category="{embed:cat_id}" channel="products" dynamic="no" limit="1" disable="pagination"}
    {categories show="{embed:cat_id}"}
    <li>
    <a href="http://{site_url}index.php/dimitriadis/products/categories/C{category_id}">{category_name}</a>
    </li>
     {/categories}
    {/exp:channel:entries}

     

     

  • #5 / Dec 08, 2011 7:50am

    amra01

    45 posts

    your magic !! worked just fine with embed code thanks a lot my friend!!!:-)

  • #6 / Dec 08, 2011 7:55am

    ahmad saad

    364 posts

    can u tell me how u use the sql

    post your testing code please

    i tested the sql and it gives me only the categories the author has posted inside

  • #7 / Dec 08, 2011 8:54am

    amra01

    45 posts

    this is how I used it

    {exp:channel:categories channel="products" show_empty="no" parent_only="yes"}
                  
    {exp:query sql="SELECT distinct exp_cat.cat_id as category_id, exp_cat.cat_name AS category_name 
         
    FROM exp_categories exp_cat,exp_category_posts exp_cat_p,exp_channel_titles exp_ch_t  
         
    WHERE  exp_cat.parent_id = '0' 
           
    and exp_cat.cat_id=exp_cat_p.cat_id 
           
    and exp_cat_p.entry_id=exp_ch_t.entry_id 
           
    and exp_ch_t.author_id='97' "}        
     <li>
      <a href="http://{site_url}index.php/dimitriadis/products/categories/C{category_id}">{category_name}</a>
     </li>
            
      {/exp:query}
           
    {/exp:channel:categories}
  • #8 / Dec 08, 2011 9:21am

    ahmad saad

    364 posts

    try to use it like this

    {exp:query sql="SELECT distinct exp_cat.cat_id as category_id, exp_cat.cat_name AS category_name FROM exp_categories exp_cat,exp_category_posts exp_cat_p,exp_channel_titles exp_ch_t  WHERE  exp_cat.parent_id = '0' and exp_cat.cat_id=exp_cat_p.cat_id and exp_cat_p.entry_id=exp_ch_t.entry_id and exp_ch_t.author_id='97' "}        
     <li>
      <a href="http://{site_url}index.php/dimitriadis/products/categories/C{category_id}">{category_name}</a>
     </li>
            
      {/exp:query}

    without {exp:channel:categories I think this will work

    of course if you dont want to use embed


    u welcome

  • #9 / Dec 08, 2011 10:24am

    amra01

    45 posts

    thanks a lot for your help, the sql query works fine also

  • #10 / Dec 08, 2011 5:17pm

    Kevin Smith

    4784 posts

    Thanks for tossing in all this help, ahmad!

    amra01, do you have the solution you need, or would you like me to move this thread to Community Help so that you can continue to work out the SQL?

  • #11 / Dec 09, 2011 2:54am

    amra01

    45 posts

    it’s working fine using either of the 2 methods the topic should be closed.

  • #12 / Dec 09, 2011 6:44am

    ahmad saad

    364 posts

    welcome

    feel free to ask any thing

  • #13 / Dec 12, 2011 3:19pm

    Kevin Smith

    4784 posts

    Sounds good, fellas. Let us know if we can help again in the future!

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

ExpressionEngine News!

#eecms, #events, #releases