Sort Posts By Long Text With Script
A website would not be the same number of words in each post. Is it possible we could rank them based on the number of words or characters with JavaScript or jQuery? Eg create link
Solution 1:
It's hard to give a full answer as we can't see the pages where you'd get your word counts from, but...
<body>
<p>abc def</p>
<p>def ghi</p>
</body>
Really you would probably be using something like php to loop through a list of pages and then at the end you will have three arrays, each containing a list of pages with 0-200, 201-400, and 400+ words.
Then you can include a list of links to each.
<script>functionwordCount(){
var e = document.getElementsByTagName('p');
var totalWords = 0;
for (var i = 0; i < e.length; i++) {
var innerTx = e[i].innerHTML;
var wordArray = innerTx.split(' ');
var thisTotal = wordArray.length;
// alert(wordArray.length);
totalWords += thisTotal;
// totalWords += wordArray.length; //Do something
}//f// var a = 'abc def ghi';// document.write(b.length);// alert(totalWords);if (totalWords > 400 ) {
alert('400+');
} elseif(totalWords > 200){
alert('200+');
} else {
alert('< 200');
}
alert('Now you need to use this information to add the specific page to an array of pages with the different word counts');
}
wordCount();
</script>
Post a Comment for "Sort Posts By Long Text With Script"