0

A similar question has been asked here which ended in the recommendation to create a custom plugin. That's not possible for me.

I want to know how many words my entries actually have; in the frontend I want to add to the meta-data "this article has 132 words".

Is there a way to count the words and use this number?

Thanks in advance!

1 Answer 1

1

Certainly on the front end, one of the options would be to simply use jquery to do that work for you. A quick search revealed one method that would likely do the trick - you would surround the article body requiring a word count with a class of "to_count" and then use jquery with a bit of regex to detect and count the words within that class element. This assumes that you're OK loading jquery on the page in which you need the count.

Alternatively, you could instead use an EE add-on like MD Character Count to give you a word count within the control panel and then you could add a custom field in which to record that value (but this may incorrectly assume that the content requiring a total is contained within a single field).

3
  • Thanks for your answer, Jean. But none of this solutions will work: counting the number of words every time the article is shown would result in ultra-high serverload, I think. MD Character Count does only count words in the input-fields in the backend/control panel.
    – BNetz
    Dec 28, 2013 at 19:59
  • 1
    I'd really suggest the second approach that i mentioned anyway - using MD Character Count to do the math for you (there's a forum post that seems to suggest Masuga may have been working on implementing a configuration for word count as opposed to character count) and then transposing that count value into a separate field to use on the front end for display. It's not a perfect solution, but given that you don't need a "live" count when the article loads and you're really using it mainly for front end display, capturing the count in a dedicated field may be the most efficient option. Dec 29, 2013 at 19:05
  • jQuery is executed on the client-end, so you're not going to have any issues with server load there, and it should be fairly trivial for the client end, so, I'd heartily recommend that solution. Jan 6, 2014 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.