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.

Weirdness with category list

November 03, 2007 10:29pm

Subscribe [1]
  • #1 / Nov 03, 2007 10:29pm

    Deron Sizemore

    1033 posts

    I’m displaying a simple category list on my site. It has each category plus the number of entries in that particular category out to the right in parenthesis. I just made 10 new entries and set them to be published on Monday, but even though they don’t technically show up until Monday, the category list is still recording them in the number out to the right of the category. I went to the edit tab and even “closed” these entries and was just going to manually publish them on Monday, but even setting them to closed didn’t do the trick. The number stayed the same and counted the entires even though they were not published yet.

    Here is the code I’m using from the Wiki. Any way around this?
                   

    {exp:query sql="SELECT count(exp_category_posts.entry_id) AS post_count,
                        exp_category_posts.cat_id, exp_categories.cat_name
                            FROM exp_categories, exp_category_posts, exp_weblog_titles
                            WHERE exp_category_posts.cat_id = exp_categories.cat_id AND parent_id='0'
                            AND exp_weblog_titles.weblog_id = '2'
                            AND exp_weblog_titles.entry_id = exp_category_posts.entry_id
                            GROUP BY exp_categories.cat_order"}
                            <li><a href="http://{path=" title="View all posts filed under {cat_name}">{cat_name}</a> ({post_count})</li>
                            {/exp:query}
  • #2 / Nov 04, 2007 10:33am

    Robin Sowell

    13255 posts

    I’m going to shift this over to ‘How to’, as it’s not really a problem with the tag or with EE, but with the query.  Basically- you need to write the query in such a way that it’s either checking the date and/or the status- and you aren’t.  So- if you just wanted open status entries- you’d need to add that in:

    {exp:query sql="SELECT count(exp_category_posts.entry_id) AS post_count,
                        exp_category_posts.cat_id, exp_categories.cat_name
                            FROM exp_categories, exp_category_posts, exp_weblog_titles
                            WHERE exp_category_posts.cat_id = exp_categories.cat_id AND parent_id='0'
                            AND exp_weblog_titles.weblog_id = '2'
    AND exp_weblog_titles.status='open' 
                            AND exp_weblog_titles.entry_id = exp_category_posts.entry_id
                            GROUP BY exp_categories.cat_order"}
                            <li><a href="http://{path=" title="View all posts filed under {cat_name}">{cat_name}</a> ({post_count})</li>
                            {/exp:query}

    Make sense?  The dates a little trickier- you’d likely use php to set a ‘now’ time, then put in a check that entry_date < $now- which you might could do with the current time global and avoid the php- but I haven’t tested the parse order on doing it that way.

    Anyway- you just need to tweak your query so that it follows the rules you want.  Make sense?

  • #3 / Nov 04, 2007 10:41am

    Deron Sizemore

    1033 posts

    Thanks Robin! Makes sense and I figured as much, just didn’t know what to write (with my limited coding knowledge) 😊) All the “SELECTS,” “FROMS,” and “WHERES” really make no sense to me in that statement. I’m trying to learn a little php/mysql though so maybe they will be clear.

    That fix should be good enough for me. I can just mark them closed and open them manually when I’m ready to publish. That will allow me to avoid any php that I don’t know how to do. hehe

    Thanks a lot

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

ExpressionEngine News!

#eecms, #events, #releases