I have this script that gives you this ability. You need to put it in the “plugins” folder and activate it. You will also have to edit it to match how you want it to display. Should be easy to understand, it just uses the standard WP code for creating a widget. If you want to translate it, you have to replace the English with your language.
<?php
/*
* Plugin Name: Participants Database: Show Total
* Version: 0.1
* Description: widget and shortcode for displaying the total number of participant records
* Author: xn*au webdesign
* Author URI: https://xnau.com/participants-database/
* License: GPL2
*/
add_action('widgets_init', create_function('', 'return register_widget("Total_Participants");'));
class Total_Participants extends WP_Widget {
public function Total_Participants()
{
$widget_ops = array(
'classname' => 'Total_Particpants',
'description' => 'Widget for displaying the number of participant records',
);
parent::WP_Widget(false, $name = 'Display Total Participants', $widget_ops);
// define the shortcode
add_shortcode('total_records', array(__CLASS__, 'get_total'));
}
public function form($instance)
{
$defaults = array(
'title' => 'Total Participants',
'string' => 'There are %s registered participants.',
);
$instance = wp_parse_args((array) $instance, $defaults);
$title = esc_attr($instance['title']);
$string = esc_attr($instance['string']);
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>">Widget Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('string'); ?>">Display String: <input class="widefat" id="<?php echo $this->get_field_id('string'); ?>" name="<?php echo $this->get_field_name('string'); ?>" type="text" value="<?php echo $string ?>" /></label><br />The string to display the total in. The "%s" will be replaced by the number of participants.</p>
<?php
}
public function update($new_instance, $old_instance)
{
$instance = $old_instance;
$instance['title'] = $new_instance['title'];
$instance['string'] = $new_instance['string'];
return $instance;
}
public function widget($args, $instance)
{
extract($args, EXTR_SKIP);
$count = $this->get_total();
$title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
echo $before_widget;
if (!empty($title))
echo $before_title . $title . $after_title;
printf($instance['string'], $count);
echo $after_widget;
}
public static function get_total()
{
$count = '';
if (class_exists('Participants_Db')) {
global $wpdb;
$sql = 'SELECT COUNT(*) FROM ' . Participants_Db::$participants_table . ' p';
$count = $wpdb->get_var($sql);
}
return $count;
}
}
?>