Spintax type function for WP template

blogspotter

WF Premium Member
Jun 29, 2007
2,879
104
0
Interwebz
Anybody using a spintax type functionality that can be used with wordpress templates.

I want to be able to use it in the Post or pages for the sidebar files.

I want to display random text on different pages based on a Spintax.

Is there a rand() type function that I can use with a string of synonyms?

I would like to be able to paste that price of code below a post or page.

Something on HTML preferred so that i can use it on my html sites as well.


Much Appreciated.
 


I helped someone with this in this forum a few weeks ago - in this section. Might have to go digging for it but it's there.
 
Yeah ignore that - it was through pm. Conversation started here: http://www.wickedfire.com/design-de...w-make-wordpress-publish-spintax-content.html

Here is the function to spin content that's seperated by {|}. You are going to need to add a plugin that will allow you to run php in the posts or sidebar - phpexec should work for example.


PHP:
<?php



function spin($s){
preg_match('#\{(.+?)\}#is',$s,$m);
if(empty($m)) return $s;

$t = $m[1];

if(strpos($t,'{')!==false){
$t = substr($t, strrpos($t,'{') + 1);
}

$parts = explode("|", $t);
$s = preg_replace("+\{".preg_quote($t)."\}+is", $parts[array_rand($parts)], $s, 1);

return spin($s);
}
// end of function.... you add content here

$content = '{blah|blah|blah}';

echo spin($content);


?>

Not tested - wordpress does stupid crap sometimes and might have a conflict with names you need to change - other than that it should work.
 
Yep - should work. If you want to place it in the widgets section you need to have that extra plugin. Otherwise you should be good.