Skip to content

Instantly share code, notes, and snippets.

@muhfaris
Created October 11, 2016 04:31
Show Gist options
  • Save muhfaris/696605919947d170dcda238fa7afbe48 to your computer and use it in GitHub Desktop.
Save muhfaris/696605919947d170dcda238fa7afbe48 to your computer and use it in GitHub Desktop.
Potong Panjang judul / title post
/**
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