0

I'm trying to run some PHP code once in a loop in bbpress (wordpress forums)

The code I'm trying to run is a sidebar:

<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(5) ) : else : ?>
    <p class="empty-content-area">
        <span>Oops! No sweet stuff in here</span><br />
        <a href="wp-admin/widgets.php">Add a widget</a>
    </p>
<?php endif; ?>

I would like this to display only once below the first reply and nothing else after the 2nd, 3rd reply etc.

How can I do this?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
Tigrrr
  • 3
  • 1

1 Answers1

0

You can do this kind of quick-and-dirty thing:

<? if ($c++ == 0 && function_exists('dynamic_sidebar') && dynamic_sidebar(5) ) { ?>
    <p class="empty-content-area">
        <span>Oops! No sweet stuff in here</span><br />
        <a href="wp-admin/widgets.php">Add a widget</a>
    </p>
<? } ?>
Jill-Jênn Vie
  • 1,849
  • 19
  • 22
  • this might sound stupid but i added the following with no luck its still displaying after each reply – Tigrrr Aug 10 '12 at 00:15
  • Yes, because your `if` had no effect. Check my edited answer. – Jill-Jênn Vie Aug 10 '12 at 00:19
  • What's the $c++ bit supposed to do? $c is undefined in your snippet – Major Productions Aug 10 '12 at 00:23
  • Undefined variables are set to 0. This is PHP's magic. First time, `$c` is 0. But `$c++` means it will be incremented next time you use it, so it will be 1, and the condition will not be verified. – Jill-Jênn Vie Aug 10 '12 at 00:27
  • im not sure if im allowed to post link here but the above still not working it must be something im doing [link](http://www.diablo247.com/topic/just-got-my-barb-to-lvl-60/) – Tigrrr Aug 10 '12 at 00:33
  • i used ` if ($c++ == 0 && function_exists('dynamic_sidebar') && dynamic_sidebar(5) ); ?>` and worked like a charm when i placed it in the right place lol im such a noob – Tigrrr Aug 10 '12 at 01:05