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 want to display notification bar on header in my Wordpress theme when user submit certain number of post. I want to notify my author once they are submit amount of post. e.g.

if (authorpost === 50){

// congratulations! you have submitted total 50 posts bla bla.

} else if (authorpost === 100) {

// congratulations! you have submitted total 100 posts bla bla.

} else { // nothing will display }

I want this into header.php and will place my div right after tag. Also I want to display only when they submit certain number of post as I mention above as soon as they cross that number it won't display anything.

share|improve this question
    
Excuse me! I am trying to do in my wordpress template. –  pixelngrain Jun 5 '12 at 17:39
add comment

1 Answer

up vote 4 down vote accepted

A simple way to achieve this would be to do something like the following;

<?php
    $user_id = get_current_user_id();
    $post_count = count_user_posts($user_id);

    if ($post_count >= 50 && $post_count < 100) {
         // Congratulations you have submitted 50 posts!
    } elseif ($post_count >= 100) {
        // etc etc...
    } else {
        // do something else, or nothing.
    }
?>

You can place this within your header.php file, or for that matter in any template file should you choose to display this information elsewhere as this can run from out-side of your post loop.

WordPress API resources:

  • get_current_user_id LINK
  • count_user_posts LINK
share|improve this answer
add comment

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.