AshleyQuick Posted October 11, 2010 Share Posted October 11, 2010 I believe it's called increment. Either way, I cannot figure out how to simply count up beginning at 1 (in red in the div below) ... function wp_rss( $url, $num_items = -1 ) { if ( $rss = fetch_rss( $url ) ) { echo '<div id="charts">'; if ( $num_items !== -1 ) { $rss->items = array_slice( $rss->items, 0, $num_items ); } foreach ( (array) $rss->items as $item ) { printf( '<div id="chart_lt">1</div><div id="chart_rt">%3$s</div>', esc_url( $item['link'] ), esc_attr( strip_tags( $item['description'] ) ), htmlentities( $item['title'] ) ); } echo '</div>'; } else { _e( 'An error has occurred, which probably means the feed is down. Try again later.' ); } } Link to comment https://forums.phpfreaks.com/topic/215595-need-help-with-php-increment/ Share on other sites More sharing options...
joel24 Posted October 11, 2010 Share Posted October 11, 2010 increment is done with ++ in a loop, $count++; would increment $count + 1 for each loop. function wp_rss( $url, $num_items = -1 ) { if ( $rss = fetch_rss( $url ) ) { echo '<div id="charts">'; if ( $num_items !== -1 ) { $rss->items = array_slice( $rss->items, 0, $num_items ); } //start count $i = 1; foreach ( (array) $rss->items as $item ) { printf( '<div id="chart_lt">'.$i.'</div><div id="chart_rt">%3$s</div>', esc_url( $item['link'] ), esc_attr( strip_tags( $item['description'] ) ), htmlentities( $item['title'] ) ); //increment $i++; } echo '</div>'; } else { _e( 'An error has occurred, which probably means the feed is down. Try again later.' ); } } Link to comment https://forums.phpfreaks.com/topic/215595-need-help-with-php-increment/#findComment-1120995 Share on other sites More sharing options...
AshleyQuick Posted October 11, 2010 Author Share Posted October 11, 2010 Awesome, thank you so much! Have a blessed week!! Link to comment https://forums.phpfreaks.com/topic/215595-need-help-with-php-increment/#findComment-1121066 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.