web/wp-content/plugins/Text_Cutter.php
branchwordpress
changeset 123 561aa6d282f6
child 132 4d4862461b8d
equal deleted inserted replaced
112:fb7cd02b9848 123:561aa6d282f6
       
     1 <?php
       
     2 /**
       
     3  * @package Title_Cutter
       
     4  * @author Samuel Huron
       
     5  * @version 0.1
       
     6  */
       
     7 /*
       
     8 Plugin Name: Text Cutter
       
     9 Plugin URI: http://www.iri.centrepompidou.fr
       
    10 Description: This is just a simple thing to cut the title visible in navigation and in the page of post.
       
    11 Author: Samuel Huron 
       
    12 Version: 0.1
       
    13 Author URI: http://www.cybunk.com/
       
    14 */
       
    15 
       
    16 function Expert_without_BR ($content){
       
    17 
       
    18 	$symbole= "<br/>";
       
    19 
       
    20 	return (str_replace($symbole, "", $content)." YO");
       
    21 }
       
    22 
       
    23 function Title_Cutter($content){
       
    24 	
       
    25 	$length = 200;
       
    26 	$symbole= "<!-- cut -->";
       
    27 
       
    28 	if(!is_single(get_the_ID())){
       
    29 		
       
    30 		$lastpos = strrpos($content,$symbole); 	
       
    31 		
       
    32 		if($lastpos!=FALSE){
       
    33 			return (substr($content, 0, $lastpos)."");
       
    34 			
       
    35 		} else {
       
    36 			if(strlen($content)>$length){
       
    37 				return (substr($content, 0, $length)."[...]");
       
    38 			} else {
       
    39 				return ($content);
       
    40 			}
       
    41 		}
       
    42 	}else{
       
    43 		return ("".str_replace($symbole, "", $content));
       
    44 	}
       
    45 	
       
    46 }
       
    47 
       
    48 // Cut 
       
    49 add_action ( 'the_title', 'Title_Cutter');
       
    50 //add_action ( 'the_excerpt', 'Expert_without_BR',1);
       
    51 
       
    52 ?>