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.

Getting {comment_total} without an extra query?

August 31, 2012 5:22am

Subscribe [2]
  • #1 / Aug 31, 2012 5:22am

    Hi all,

    I’m currently converting this WordPress theme to EE, trying to optimize everything as much as possible while doing so.

    If you look at this template from the demo-site, you’ll see the comments section at the bottom.

    At the top of this section, there is a count of the comments made - seven in this case. I’d love to save an {exp:channel:entries} query, just to get this count, but of course

    {comment_total}

    ...needs one, to count how many comments have been made.

    What I’m wondering is: Can I get that count using the {exp:channel:entries} query I already have pulling the article entry further up on the page, save it in a variable, and then use it later down in the comments section? Or some other way, that does not require me to “spend” a query, just to get this count?

    It may seem like I’m going too far in my optimization, but such a technique could be very handy in a million other situations, where the benefit may be greater.

    If EE does not have this functionality, perhaps a third-party add-on exists? I’ve tried looking for one on Devot:ee but had a little trouble figuring out what to search for, so if anyone knows of an add-on that does this, I’d love to hear about it 😊

    However, it preferably should be Open Source, or at least free with a kind developer. The reason for this is, that the theme will be released for free to the community when done (the first in a series of free themes, more about that here) and I’d like to include the add-on in the download, so the user won’t have to install anything separately.

    Anyways, hope you all have some ideas, thank you very much in advance!

    Cheers,
    Thomas

  • #2 / Aug 31, 2012 5:52am

    I tried using Yorick’s “Variables” plug-in, but it doesn’t seem to work when put inside {exp:channel:entries} tags.

    As I can read here, it doesn’t support being placed inside conditionals either, so this does not seem to be useable. Unfortunately, because it was exactly what I needed 😊

    Anyone got another idea, pretty-please? 😊

  • #3 / Sep 13, 2012 10:41am

    anonymous162744

    58 posts

    Yes, you can use Stash. What you can do is run one channel entry at the top of the page and save each field to a stash variable. The use that in other parts of the page:
    http://devot-ee.com/add-ons/stash

  • #4 / Sep 16, 2012 4:03am

    Hi Anthony, thank you for your reply!

    I tried Stash but had some trouble getting it to work, but I’ll revisit the issue and get back here if I need help, or if I succeed 😊

    Thank you again for your help!

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

ExpressionEngine News!

#eecms, #events, #releases