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.

How do I retrieve a thread count from forums based on a weblog entry?

June 18, 2009 1:35pm

Subscribe [2]
  • #16 / Jun 18, 2009 8:46pm

    lebisol

    2234 posts

    I was going to suggest an if statement but was worried about side effects 😊
    This would not be the best way to use as ‘access control’ since query is just for pulling data and presenting it. Sure it is a shortcut but by no means is it an access control. You would control access to forums (categories) though forum module…this would just be a convenient way of jumping to the thread.

  • #17 / Jun 18, 2009 9:06pm

    craiguffman

    100 posts

    How have you handled it in the past when your query returns 0 replies?  I expected that, if the query does not generate results, that the query would return a “0” forum replies, which means that my page would still have the helpful link.  But instead, it skips to the next object on the page and says nothing about Forum replies.  I have tried to prevent this in various ways with no luck.  Here’s my latest. I don’t understand why EE simply ignores the function altogether and does not display “0” Forum Replies…..

    {if thread_counter >="0" } <a href="http://{path=forums/viewthread/{topic_link_id}}">{site_url}files/comments_bubble.png Forum Replies [{thread_counter}]</a>{if:else}<a href="http://{path=forums/viewthread/{topic_link_id}}">{site_url}files/comments_bubble.png Be the First to Reply to This Post</a>{/if}
  • #18 / Jun 19, 2009 3:18am

    lebisol

    2234 posts

    What do you want to warn the visitor about?
    -The fact that there is no forum topic attached to entry or that there is no replies?

  • #19 / Jun 19, 2009 3:21am

    craiguffman

    100 posts

    In my case there are always forum topics because I use Robin Sewell’s autofill which automatically creates forum topics.  So my hope is to indicate that there are zero replies so far and to encourage them to be the first to respond.

  • #20 / Jun 19, 2009 4:28am

    lebisol

    2234 posts

    Ok makes sense, just making sure that the linking of entry to topic is happening.
    Here is the ‘ultimate’ solution:

    {exp:query sql="SELECT count(exp_forum_posts.topic_id) AS thread_counter, exp_weblog_titles.forum_topic_id as topic_link_id
        FROM exp_weblog_titles
        LEFT OUTER JOIN exp_forum_posts
        ON (exp_weblog_titles.forum_topic_id = exp_forum_posts.topic_id)
        WHERE exp_weblog_titles.entry_id='{entry_id}'
        GROUP BY exp_weblog_titles.entry_id;"}
       
    {if thread_counter =="0"}
    Be First to <a href="http://{path=forums/viewthread/{topic_link_id}}">Discuss</a>
    {if:else}
     Forum Replies: [<a href="http://{path=forums/viewthread/{topic_link_id}}">{thread_counter}</a>]
    {/if}
    {/exp:query}

    This could also be a nice way (for those running forums) to unload some of the ‘comment maintenance’ and perhaps show these links after the commenting on entry had expired. This way discussions can continue in forums while entry page stays free from load of possibly 100s of comments. In other words I would embed this query on entry view page as well. 😉

  • #21 / Jun 19, 2009 12:02pm

    craiguffman

    100 posts

    Are you saying you use both comments and forum replies on a weblog post?  That’s not something I have thought of.

    Thanks for this.  Looks great.

  • #22 / Jun 21, 2009 11:57am

    lebisol

    2234 posts

    Just an idea…maybe set your own threshold…commenting for duration of x days and after the comments expire use the above to direct people to forums thread. Whatever you like…another nice thing with EE, process is your choice.
    All the best!


    edit: use of title field was replaced with entry_id for a more accurate match.

  • #23 / Jun 23, 2009 12:35pm

    craiguffman

    100 posts

    Thanks, lebisol, for all of your help.  The change to entry_id also seems to be much faster than the one matching on title.  Thanks a ton!

  • #24 / Jun 23, 2009 12:41pm

    craiguffman

    100 posts

    lebisol,

    Do you have any idea how I can display the comments from posts within my EE template with proper formatting.  Right now I am using this query to do so.  But the body field has timestamps and urls in it that display on my EE template without formatting.  Do you have any idea how I can take this query to retrieve the data as it is, but then display the body field with proper formatting of date and urls.

    See the example below.

    Hi Michael,

    Once local Vestries have violated a trust, as they have with TEC, giving up control….

    I have asked about this in several places and I have never received an answer.

    Thanks,
    Craig

  • #25 / Jun 23, 2009 12:49pm

    lebisol

    2234 posts

    I thought you are just redirecting them to the forums….are you pulling the data from forum thread into standard EE templates?

  • #26 / Jun 23, 2009 12:56pm

    craiguffman

    100 posts

    Yes and yes. 

    Yes, I am redirecting them to the forums when they click on a specific post (“comment”), but I am displaying within the template a short string of the post in a list and also the complete body.  You can see it here.  Look at the “Recent Comments” box.  You can see a few of the posts with the data formatting problems in the list.  But click on the header “Recent Comments” and you will see that I am displaying the entire list in a FIFO order.  And that’s where the formatting problem is particularly problematic.

  • #27 / Jun 23, 2009 1:11pm

    lebisol

    2234 posts

    Try using a {exp:forum} tag….but I think this is where you would need to do some custom php to clean out bb tags etc.
    Forum themes live on their own and their tags are only processed in forum module…

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

ExpressionEngine News!

#eecms, #events, #releases