Problems, need help? Have a tip or advice? Post it here.
5 posts Page 1 of 1
Hi,

I am setting up a Json-LD for articles and was wondering if there's any way to have a word count number on a particular editable section? Especially for Mosaic, as I want to put the words number in the Json-LD accurately?

(I am building with AMP, so JS is not an option)

just in case, if someone has a solution, thanks.
Paul
Hi Paolo,

I assume you are generating the JSON LD server-side using Couch tags.
If so, at the point where you need the word count you may try using some PHP e.g. as follows -
Code: Select all
<cms:show_mosaic 'my_content'>
    <cms:if k_tile_name='my_text' >
        <cms:php>echo str_word_count('<cms:show my_text />');</cms:php>
    </cms:if>
    ...

Would this help?
Hi Kk,

That works, but it's a mosaic, so I might have few instance of the tile named 'content'.

For example I do:

Code: Select all
<cms:if k_tile_name='content' >
        <cms:php>global $wordcounter; $wordcounter = str_word_count('<cms:show content />'); echo $wordcounter;</cms:php>
    </cms:if>


Then in Json-LD

Code: Select all
"wordcount": "<cms:php>global $wordcounter; echo $wordcounter;</cms:php>",


So it shows the counter after each content, but how can I add them, as I may have more than one quite often?

I that case, in Json-LD, it shows the words count for one instance.

For example for this one :
https://www.pauloeuvreart.com/art-blog/biographies/biographie-de-claude-monet.html

the word count is 54

Thanks for your help,
Paolo
I think you should make a separate pass, iterating through the mosaic and adding together all the word counts to get a final figure. You can use that figure later while outputting the JSON-LD.

Please feel free to contact me directly with your code in case you need any help with the process.
Ok, I will do that.

Thanks
5 posts Page 1 of 1