murraytodd
Forum Replies Created
-
Forum: Plugins
In reply to: Wordcount plugin for each post?(As an update to what I just wrote an hour ago.)
I’ve found a few flaws in the code recommended above. First of all, the use of the get_the_content function was only returning the content before the
<!--more-->
tag if I used it in a multi-post (ie. index.php) file. I rewrote the function to look like this:function wordcount() { global $page, $pages; if (!function_exists('str_word_count')) { return str_word_count(strip_tags($pages[$page-1])); } else { return count(explode(" ",strip_tags($pages[$page-1]))); } }
and I called it from within “The Loop” by
<?php _e('with Word Count:' . wordcount()); ?>
instead of the simple “echo” statement that was mentioned. (‘_e’ runs string echoes through a nationalization process and is a bit more elegant.)
Forum: Plugins
In reply to: Wordcount plugin for each post?It may be worthwhile to consider two different PHP functions: str_word_count and strip_tags.
The exploding trick is not very smart about non-literal-space whitespace characters (although I don’t think tabs ever get into WordPress entries). I don’t know it well enough to know its weaknesses, but I’m going to guess that the actual PHP str-word-count command has been designed to be maximally elegant and efficient. The only disadvantage to using it is that the function requires PHP >= 4.3.0. Since WordPress itself requires version 4.2 or higher. If your host has the appropriate version of PHP, great. If you want a general solution, you might test the PHP version first and create a fall-back to the string exploding scenario.
The strip_tags option should be self-explanatory. I know that many of my posts are full of lists, the links have full title strings added, etc. If you only care for your word count to be ballpark, maybe you don’t care, but I would suggest using strip_tags for that last bit of cleanliness. Note that strip_tags is supported in all PHP 4+ versions.
Forum: Fixing WordPress
In reply to: dreamweaver as wysiwyg WP editor?meganano: (I know this thread is old, but maybe someone else banging his or her against the wall will appreciate the info.)
The problem with Dreamweaver/Mac “breaking” WordPress css files has to do with the newline encoding. If your server is a Linux server it’s going to want a \n end-of-line encoding as opposed to Mac’s \r or Windows’s \r\n.
In Dreamweaver 7 & 8, under Preferences on the Code Format tab, the “Line break type” should be set to “LF (Unix)”.