it's my blog anyway
I needed a plugin that can show random quotes with author options as well and I found Stray Random Quotes WordPress plugin could do the trick. The only problem is, the function to display the random quote directly outputs the text onscreen together with the author.
What I need to do is to suppress the display of the function output onscreen, pass it to a variable then do a split of the variable to separate the message and author in an array. See the code below on how I did it
<?php
if (function_exists('stray_random_quote'))
// turn on output buffer
ob_start();
// run the function of the plugin
stray_random_quote('feedback',false,'',true,1,0,'Category','ASC',false,'');
// get the content from the buffer
$string = ob_get_contents();
ob_end_clean();
// split the output and remove unnecessary HTML tags
$feedback = split('by',strip_tags($string));
// access the message
echo trim($feedback[0]);
// access the author
echo trim($feedback[1]);
Pretty easy!
This is a programmer's blog. Whenever I encounter a difficult coding task, I make sure that I'll be able to share it here in the hope that others may find it useful. It's my way of giving back to the open source community who have been a great help to me as well.
1 Response to Separating message and author in ‘Stray Random Quotes’ WordPress plugin
Semidoppel
February 1st, 2011 at 4:52 pm
More more teach me more pls! Hehehe actually kht HTML di akomarunong