Forums

[resolved] I want to create a plugin .. I want it to change the ... (4 posts)

  1. abosami2000
    Member
    Posted 1 year ago #

    hi ,

    I want to create a plugin , I want it to replace some words and give it link like wikipidia .. or wiki site ..

    for example when I write :"Japan or United State" directly the plugins search in DB about the post it title is "Japan" if it exsist give it link like this ' Japan ' also I try to make it without database by array but I can't

    this is the code :

    <?php
    /*
    Plugin Name: ReplaceMent
    
    */
    $wiki_contry = array ("Japan"=>"<a href='?japan.php'> Japan <a/>","United State"=>"<a href='?usa.php'> United State <a/>");
    function replace($text){
    	foreach ($wiki_contry as $ky => $vl){
    	$text = str_replace(ِ"$ky","$vl", $text);
    	return $text;
    	}
    }
    add_filter('the_content','replace');
    
    ?>

    and the error is :

    Parse error: parse error in C:\wamp\www\wordpress\wp-content\plugins\replace_plugins\replace_plugins.php on line 9

    I wait you to help me , plz

  2. David Sader
    Member
    Posted 1 year ago #

    <?php
    /*
    Plugin Name: ReplaceMent
    
    */
    
    function replace( $text ){
    
    	$q = array(
    			'Japan' => 'japan.php',
    			'USA' => 'usa.php',
    			'France' => ''
    			);
    
    		foreach( $q as $country => $page ) {
    
    				if( $page ) {
    					$url = '<a href="' . get_bloginfo('url') . '/' . $page . '">' . $country . '</a>';
    				} else {
    					$url = '<a href="' . add_query_arg( 's', $country , get_bloginfo('url')) . '">' . $country . '</a>';
    				}
    
    			$text = str_replace( $country, $url, $text );
    
    		}
    
    	return $text;
    
    }
    add_filter( 'the_content', 'replace' );
    ?>
  3. abosami2000
    Member
    Posted 1 year ago #

    wow great .. thanks Mr.David Sader ..

    thank you very much ..

  4. benfranklin
    Member
    Posted 1 year ago #

    Sader:

    What about if instead of replacing text with something, every time there is an instance of some keyword in the post it adds another keyword you have associated with the chosen keyword in a specific custom field ... instead of replacing the text in the post?

    Any ideas here?

    Thanks a lot.

    Reess

Topic Closed

This topic has been closed to new replies.

About this Topic