Created
October 11, 2016 04:31
-
-
Save muhfaris/696605919947d170dcda238fa7afbe48 to your computer and use it in GitHub Desktop.
Potong Panjang judul / title post
This file contains hidden or 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
/** | |
fungsi ini untuk memotong ukuran judul / title yang panjang lebih dari 55 karakter, | |
karakter itu meliputi space dan huruf. | |
fungsi : | |
<?php potong_kar(get_the_title(),55,'...');?> | |
judul di potong jika lebih dari 55 dan selanjutnya akan di replace menggunkan tanda "..." (tanpa petik " ") | |
*/ | |
function view_post(){ | |
$related = ci_get_related_posts( get_the_ID(), 5 ); | |
if( $related->have_posts() ):?> | |
<div id="top_artikel" class="horisontal"> | |
<ul> | |
<?php $no=1;while( $related->have_posts() ): $related->the_post(); ?> | |
<li><a href="<?php the_permalink();?>"><div class="top_nomer"><?php echo $no;?></div> | |
<span><?php potong_kar(get_the_title(),55,'...');?></span></a> | |
</li> | |
<?php | |
$no +=1; | |
endwhile; ?> | |
</ul> | |
</div> | |
<?php | |
endif; | |
wp_reset_postdata(); | |
} | |
function potong_kar ($str,$numb1,$append = '...') { | |
$length = strlen($str); | |
if($length > $numb1) { | |
$str = substr($str,0,$numb1).$append; | |
echo $str; | |
}else{ | |
echo $str; | |
} | |
return $str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment