Jump to content

search and replace the result of a function??? Help


krisnrg

Recommended Posts

Hey guys I'm new to PHP and I have little experience programing. Back in the day I was learning Action Script for Flash so I'm not completely lost since I kinda understand Functions and Variables and stuff.

 

Ok here is the question... I have a Function in wordpress:

 

wp_get_archives();

 

that basically returns this:

 

<a title="February 2008" href="http://www.casavidanueva.com/wp/2008/02/">February 2008</a>
<a title="January 2008" href="http://www.casavidanueva.com/wp/2008/01/">January 2008</a>

 

My blog/site needs to be bilingual Spanish and English. I have most everything worked out.

 

I want to keep the functionality of the months and links to them being generated dynamically. So I thought, "Can't I just search and replace something in that string?"

 

So I tried this:

 

<?php $mes = wp_get_archives();
$new = str_replace("January","Enero",$mes);
echo $new;
?> 

 

But nothing happens. I guess the result of the function Im wanting to search in is not a string.

 

If you guys can help that would be great... Thanks

That should work. I recently made a plugin to add rel="noindex" to the archive links. Here's what my plugin file looks like . . .

add_filter( 'get_archives_link', 'filter_category_list' );

function filter_category_list( $text ) {
$text = preg_replace( '/<a([^>]+)>/', '<a$1 rel="noindex">', $text );
return $text;
}

 

This could be changed to the following to translate months . . .

add_filter( 'get_archives_link', 'filter_category_list' );

function filter_category_list( $text ) {
$text = str_replace( 'January', 'Enero', $text );
return $text;
}

 

You've probably read this, but you can use arrays for the search and replace values to replace more than one string at a time.

Ok thanks for the help.

 

Um would you be able to explain the add_filter? Is it a function?

 

Also I tried you second script and nothing happened. This is what I have in the sidebar (basically nothing cause I was testing this). I have a variable at the top that determines which searchform to use. One for spanish and one for english.

 

<?php $lang = $_GET["lang"];?>
<div id="sidebar">
<ul class="rsidebar">

	<li>
		<?php			
		if (is_category(3)) { 
		include (TEMPLATEPATH . '/searchform-3.php');
		} elseif  (is_category(4)) {
		include (TEMPLATEPATH . '/searchform.php');
		} elseif  ($lang == "spanish") {
		include (TEMPLATEPATH . '/searchform-3.php');
		} elseif  ($lang == "english") {
		include (TEMPLATEPATH . '/searchform.php');}
		 ?>
	</li> 

<?php wp_get_archives(); ?>

<?php 		add_filter( 'get_archives_link', 'filter_category_list' );

	function filter_category_list( $text ) {
		$text = str_replace( 'January', 'Enero', $text );
		return $text;
	}
	echo $text;
?>


	<li>
			<?php	if (is_category(3)) { ?>
				<p>spanish</p> 
		<?php } else if  (is_category(4)) { ?>
				<h2>Archives</h2>
				<ul>

				</ul>
		<?php }?>


	</li> 

</ul>
</div>

 

If you can help me further It would be greatly appreciated.. Thanks

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.