আপনি কি জানেন? আপনার ব্লগে মোট কত গুলো ওয়ার্ড পাবলিশ হয়েছে?

আশাকরি সকলে খুব ভালো আছেন। আমাদের ওয়ার্ডপ্রেস ব্লগে প্রতি দিন অনেক লোক বিভিন্ন বিষয় নিয়ে পোষ্ট করে থাকে। আর প্রতিটি পোষ্ট এ থাকে অনেক অনেক ওয়ার্ড তাই আপনাকে যদি জিজ্ঞাসা করা হয় যে, বলুন তো আপনার ব্লগে মোট কত গুলো ওয়ার্ড আজ পর্যন্ত পাবলিশ হয়েছে? আশাকরি বলতে পারবেন না। আর বলতে না পারাটাই হল স্বাভাবিক। কারন পোষ্টের সংখ্যা তাই ঠিক মত বলতে পারা যায় না, তার পর আবার ওয়ার্ড এর সংখ্যা তাই না? হ্যা তাই। আর এই সমস্যার সমাধান দিতে আমি এবার নিয়ে আসলাম একটা দারুন কোড যেটা আপনার functions.php তে ব্যবহার করলে আপনার ড্যাশবোর্ডের “Right Now” box এর শেষে ঠিক এই রকম ভাবে আপনার ব্লগের মোট প্রকাশিত ওয়ার্ডের সংখ্যা দেখাবে:

তাহলে আর দেরী না করে এক্ষুনি এখান থেকে এই কোড গুলো কপি করে ব্যবহার করা শুরু করুন।

function post_word_count() {
    $count = 0;
    $posts = get_posts( array(
        'numberposts' => -1,
        'post_type' => array( 'post', 'page' )
    ));
    foreach( $posts as $post ) {
        $count += str_word_count( strip_tags( get_post_field( 'post_content', $post->ID )));
    }
    $num =  number_format_i18n( $count );
    // This block will add your word count to the stats portion of the Right Now box
    $text = _n( 'Word', 'Words', $num );
    echo "<tr><td class='first b'>{$num}</td><td class='t'>{$text}</td></tr>";
    // This line will add your word count to the bottom of the Right Now box.
    echo '<p>This blog contains a total of <strong>' . $num . '</strong> published words!</p>';
}
// add to Content Stats table
add_action( 'right_now_content_table_end', 'post_word_count');
// add to bottom of Activity Box
add_action('activity_box_end', 'post_word_count');

সবাইকে অনেক অনেক ধন্যবাদ।

Leave a Comment