Created
November 10, 2017 07:52
-
-
Save cagriuckan/7b01786f86c4f34947a3b5d1fe53f33e to your computer and use it in GitHub Desktop.
Wordpress - Yazının okunma süresini hesaplama
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# uckan.net | |
$uckicerik = $post->post_content; // yazı iceriğini çekiyor | |
$word = str_word_count(strip_tags($uckicerik)); // içerikteki kelime sayısını hesaplıyor | |
$m = floor($word / 200); // kelime sayısını 200'e bölerek dakika sayısını hesaplıyor | |
$s = floor($word % 200 / (200 / 60)); // kelime sayısının %200'ünü alıp 3.33'e bölerek saniyeyi hesaplıyor | |
echo 'Okuma süresi: '; | |
$uckokunma = $m . ' dk' . ($m == 1 ? '' : '') . ', ' . $s . ' sn' . ($s == 1 ? '' : ''); | |
echo $uckokunma; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment