Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Syntax help on function. WordPress

  • SOLVED

Hello,
Just having some trouble with syntax (I believe). I just need to pass the value $twittercount to where it says $numb=3. I tried $numb=$twittercount and several variations but it doesn't seem to be taking it the way it is. Any help is appreciated.



//Twitter
$twittercount = get_option('twitter_count');
function wp_echoTwitter($username, $numb=3){
include_once(ABSPATH.WPINC.'/rss.php');

$tweet = fetch_rss("http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=" . $numb );

for($i=0; $i<$numb; $i++){
echo "<p style='line-height: 15px; margin-bottom: 10px; margin-top: 4px;'>" . html_entity_decode( $tweet->items[$i]['atom_content'] ) . "</p>";
}
}



Answers (2)

2010-12-09

Buzu B answers:

function wp_echoTwitter($username, $twittercount=3){

EDIT:
---------------Never mind that. I didnt quite got what you needed the first time.
What exactly are you trying to do?


Mike McAlister comments:

$twittercount is a value being pulled from a widget, so I need it to be $numb=$twittercount. $twittercount=3 is not going to get my value from the widget.


Buzu B comments:

OK, I think I know what you are trying to do.

Try this:

function wp_echoTwitter($username){

$numb = get_option('twitter_count');


include_once(ABSPATH.WPINC.'/rss.php');



$tweet = fetch_rss("http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=" . $numb );



for($i=0; $i<$numb; $i++){

echo "<p style='line-height: 15px; margin-bottom: 10px; margin-top: 4px;'>" . html_entity_decode( $tweet->items[$i]['atom_content'] ) . "</p>";

}

}


Mike McAlister comments:

Perfect! Exactly what I needed.

Thanks!
Mike

2010-12-09

Maor Barazany answers:

Try this:


function wp_echoTwitter($username, $numb=3){

include_once(ABSPATH.WPINC.'/rss.php');

$twittercount = get_option('twitter_count');

$numb = (is_null($twittercount)) ? $numb : $twittercount;

$tweet = fetch_rss("http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=" . $numb );



for($i=0; $i<$numb; $i++){

echo "<p style='line-height: 15px; margin-bottom: 10px; margin-top: 4px;'>" . html_entity_decode( $tweet->items[$i]['atom_content'] ) . "</p>";

}

}


In this way, if no option set in the <strong>twitter_count</strong> option, it will still get the default value of 3.