Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a website and i need to be able to edit the dashboard widgets so it shows relevant information to the website.

At the moment all that is showing is the right now widget. Inside this widget, i don't need the discussion section nor do i need posts and tags. What i do need is custom post types, for example products and news. So it would say products then how many products there are, like it does with pages.

It would also be great if you could show information from other plugins. For example i'm using a plugin called Support Ticket Center, it would be great if you could show how many open support tickets there are and how many have been closed and things.

Are there any plugins that can do this kind of customization? Or is it more complicated?

Thanks

EDIT: I've tried adding the following code to my functions.php file. It sort of works but the output is adding a lot of other divs and things. I don't understand where they are coming from.

    // wp_dashboard_setup is the action hook
add_action('wp_dashboard_setup', 'mycustom_dashboard_stats');

// add dashboard widget
function mycustom_dashboard_stats() {
    wp_add_dashboard_widget('site_stat_widget', 'Site Stats','wp_dashboard_custom_post_types');
}

function wp_dashboard_custom_post_types() {
    global $wp_registered_sidebars;

    $num_posts = wp_count_posts( 'Product' );


    echo "\n\t".'<div class="table table_content">';
    echo "\n\t".'<p class="sub">' . __('Content') . '</p>'."\n\t".'<table>';
    echo "\n\t".'<tr class="first">';

    // Posts
    $num = number_format_i18n( $num_posts->publish );
    $text = _n( 'Product', 'Products', intval($num_posts->publish) );
    if ( current_user_can( 'edit_posts' ) ) {
        $num = "<a href='edit.php'>$num</a>";
        $text = "<a href='edit.php'>$text</a>";
    }
    echo '<td class="first b b-products">' . $num . '</td>';
    echo '<td class="t products">' . $text . '</td>';

    echo '</tr>';
}

This is the html code it is outputting.

<div class="table table_content">
<p class="sub">Content</p>
<div class="postbox-container" style="width:49%;">
<div class="postbox-container" style="display:none;width:49%;">
<div class="postbox-container" style="display:none;width:49%;">
<p>
<div class="clear"></div>
<div class="clear"></div>
<div class="clear"></div>
<div class="clear"></div>
<div class="clear"></div>
<table>
</div>

This will output 'Content' then a huge gap then the number of products. I don't know why it's inserting all of the clear divs and things.

How do i get it to output the html the same as the 'Right Now' widget, so it display properly and would also use the same css.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You can get a little more fancy, but this should get you started.

add_action( 'right_now_content_table_end', 'wpse_3809');
function wpse_3809() {
    $types = get_post_types( array( '_builtin' => false ) );
    foreach( $types as $type ) :
        $num_posts = wp_count_posts( $type );
        $num = number_format_i18n( $num_posts->publish );
        ?>
        <tr>
            <td class="first b b_<?php echo $type; ?>">
                <a href="edit.php?post_type=<?php echo $type; ?>"><?php echo $num; ?></a>
            </td>
            <td class="t <?php echo $type; ?>">
                <a href="edit.php?post_type=<?php echo $type; ?>"><?php echo $type; ?></a>
            </td>
        </tr>
        <?php
    endforeach;
}

Edit: The code for the "Right Now" dashboard widget can be found in /wp-admin/includes/dashboard.php the function is wp_dashboard_right_now. Unfortunately, there does not appear to be a filter that will allow you to remove post, page, categories, tags, or comments. If you want to remove them, you can use JavaScript to remove the elements from the DOM or you might be able to hide them with CSS (if there is a CSS parent selector?). Alternatively, you could copy the code and remove / add anything you want. If you don't want to list all your custom post types, remove the get_post_types and foreach loop, and replace $type with the custom post type name.

share|improve this answer
    
Thanks. Is it possible to make it so i can list which post types i want to display instead of listing all of them. So i can remove posts, but add products and any others i want to add. –  Corbula Jan 6 '12 at 15:42
    
Not possible to remove post, page, categories, tags, or comments. See edit for more information. –  v0idless Jan 6 '12 at 16:10
    
How about if i don't display the right now widget and make a new widget displaying only the custom post types i want (product, News). That way i'm not removing post, page, categories, tags or comments. –  Corbula Jan 6 '12 at 16:42
    
Yes, that is possible, use the wp_dashboard_right_now code as a starting point. –  v0idless Jan 6 '12 at 16:52
    
I've updated the question with some code that i have tried, however it's not quite working. –  Corbula Jan 7 '12 at 14:31

@v0idless code is work fine but please use it for best result

//$types = get_post_types( array( '_builtin' => false ) );

$types = get_post_types( array( '_builtin' => false,'public'   => true ) );
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.