Separating message and author in ‘Stray Random Quotes’ WordPress plugin

In: Feeling guru|Techie Daw|wordpress

30 Jan 2011
Advertisement

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.

Advertisement

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!

About the author

Richard Feraro is a PHP Developer living in Manila, Philippines. He has been programming for nine (9) years and working on different open source application mostly done in PHP and MySQL.

1 Response to Separating message and author in ‘Stray Random Quotes’ WordPress plugin

Avatar

Semidoppel PHILIPPINES

February 1st, 2011 at 4:52 pm

More more teach me more pls! Hehehe actually kht HTML di akomarunong

Comment Form

About my blog

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.

Share This Post

or bookmark to your mobile

Bookmark: http://mysillypointofview.richardferaro.com/2011/01/30/separate-message-author-in-stray-random-plugin/

Advertisement

WordPress + Magento

Proudly Pinoy!

Proudly Pinoy!

Recent Trackbacks

Archives

Disclaimer

All entries in this blog are my opinion and don't necessarily reflect the opinion of my employer or my mom.

Viewers by Country

in India 3401 (21 %) 3934 (20 %)
us United States 2700 (17 %) 3507 (18 %)
gb United Kingdom 929 (6 %) 1182 (6 %)
de Germany 808 (5 %) 1011 (5 %)
nl Netherlands 571 (4 %) 710 (4 %)
fr France 516 (3 %) 655 (3 %)
ph Philippines 442 (3 %) 669 (3 %)
br Brazil 427 (3 %) 502 (3 %)
it Italy 343 (2 %) 438 (2 %)
es Spain 334 (2 %) 446 (2 %)
ca Canada 324 (2 %) 404 (2 %)
au Australia 321 (2 %) 378 (2 %)
vn Vietnam 289 (2 %) 369 (2 %)
pk Pakistan 279 (2 %) 305 (2 %)
cn China 256 (2 %) 345 (2 %)
ro Romania 241 (2 %) 292 (1 %)
ua Ukraine 234 (1 %) 298 (2 %)
id Indonesia 140 (1 %) 167 (1 %)
pl Poland 131 (1 %) 161 (1 %)
sg Singapore 126 (1 %) 171 (1 %)
Total Countries: 139
Total Visits: 15858
Total Pageviews: 19789