Counting the posts of a loop (WP_Query)?

Some additional information, no need to count the posts again, because WP_Query already did that for you. To clarify this, some information from the Class Reference of WP_Query as found in the »Properties« section: $post_count The number of posts being displayed. $found_posts The total number of posts found matching the current query parameters What this … Read more

Where does WordPress store version number?

If you need to get the wordpress version in your script, there is a global variable: $wp_version (right now it’s something like ‘3.1-RC3-17376′) It contains the wordpress version. If you need to acquire if from a file, you can read it from /wp-includes/version.php: function getWPVersion() { $path=”/path/to/wp-install”; include $path.’/wp-includes/version.php’; return $wp_version; } WordPress Version Variables … Read more

Settings API updated messages won’t show if custom admin page not hooked into add_options_page()

Thanks Chip (excellent Settings API tutorial) and t31os (great snippet of code for quick testing) for both your suggestions. I did some further digging and found that the default messages can indeed be displayed if I hook into any menu but only if the function settings_errors() is called. For example, modifying t31os code as follows: … Read more

Add class to before_widget from within a custom widget

Aha, so the $before_widget variable is a string representing div element: <div class=”widget my” id=”my-widget-1″> . So I checked the $before_widget for the “class” sub-string and added my $widget_width value to it. The code is from my custom widget file: function widget( $args, $instance ) { extract( $args ); … //other code $widget_width = !empty($instance[‘widget_width’]) … Read more