Plug in help please

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nightbreed
    Member
    • Mar 2004
    • 91
    • 3.0.0 'Gold'

    Plug in help please

    I've got a plug in set to hook at global_start.

    The included php contains a couple additional includes to non-vb code and db functions.

    After these includes there's a simply foreach loop that should display list items for the results.

    Inside the plugin include I've tried echoing the loop items a la:

    PHP Code:
    <?
    foreach blah {
    echo 
    '<li>'.$d_row['item'].'</li>';
    } else { 
    blah }
    ?>
    I've also tried escaping php and putting html inside the include a la:

    PHP Code:
    <?
    foreach blah {
    ?>
    <li><? echo $d_row['item']; ?></li>
    <?
    } else { blah }
    ?>
    Neither of these will display the list items. However, if I call the include directly from a browser the list items do display. It's only when attempting to use the plug in that the list wont' work.

    The code for the plug in is here:
    PHP Code:
    ob_start();
       include(
    '/path/navigator.php');
       
    $includedphp ob_get_contents();
    ob_end_clean(); 
    I've reviewed the online manual and read all I could. From everything I've read it should be working.

    Can someone help me out with what I may be missing?

    I'm really trying to avoid calling a new template, but if that is indeed the problem then I'll live with the fact that I have to add a template.

    Thanks.
  • Jake Bunce
    Senior Member
    • Dec 2000
    • 46598
    • 3.6.x

    #2
    No PHP tags are needed. And you should capture the output in a variable, not echo it. Use a structure like this:

    Code:
    foreach ($array as $value)
    {
    	$bits .= '<li>' . $value . '</li>';
    }
    Now you can use code like this in most templates:

    Code:
    <ul>
    $bits
    </ul>

    Comment

    • Nightbreed
      Member
      • Mar 2004
      • 91
      • 3.0.0 'Gold'

      #3
      ahh. Thanks Jake!

      Still can't seem to get it to work.

      I removed the php tags and set the items in a variable.

      Here's the block of code for the loop present in the include:
      PHP Code:
      foreach( $maincat as $d_row ) {    
                  if (
      $d_row["maincategory"] == "Free Samples") { 
                      
      $cats .= '';  
                  } else { 
                      
      $cats .= '<li><a title="'.$d_row['maincategory'].'" href="http://www.domain.com/index1.php?maincat_id='.$d_row['recid'].'">'.$d_row['maincategory'].'</a></li>';
                  } 
              } 
      In the template (header) I'm adding $includephp and $cats but nothing shows.

      yet called by itself, this does work:
      PHP Code:
      <?php
      include('path/navigator.php');
      echo 
      $cats;
      ?>
      Last edited by Nightbreed; Sat 5 Aug '06, 12:23pm.

      Comment

      • Nightbreed
        Member
        • Mar 2004
        • 91
        • 3.0.0 'Gold'

        #4
        Okay I got it working.
        I simply included the php code in the plug in manager rather than directing to an include and using ob_start. I guess I don't fully understand how the ob_start works.

        Comment

        widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
        Working...