• Okay so here is the problem. I have this code to hide the list unless a child cat is present – works great thank you guys for that! But is it possible to hide even the containing div? Cuase as of right now it just has the “Sub-Menu” text with nothing under it and it looks out of place on pages without children – i.e. home page. Any help would rock!!!
    Thanks,
    Matt

    <div class="interior">
    			<ul class="tabs">
    					<li class="cat"><a href="#tab-cat">Sub-Menu</a></li>
    			</ul>
    			<div class="tabcontent" id="tab-blr">
    <ul>
      <?php
      global $id;
      wp_list_pages("title_li=&amp;child_of=$id&amp;show_date=modified
      &amp;date_format=$date_format"); ?>
    </ul>
    			</div>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter mbarrio

    (@mbarrio)

    I know there is a php master out there that can help me. I have basically solved all my problems from recent posts of other people but this one I couldn’t so I’m going to need your help! ??

    Thread Starter mbarrio

    (@mbarrio)

    … bump?

    Hi

    check this parameter of wp_list_pages — echo

    echo (boolean)
    Toggles the display of the generated list of links or return the list as an HTML text string to be used in PHP. The default value is 1 (display the generated list items). Valid values:

    * 1 (true) – default
    * 0 (false)

    move your wp_list_pages statement before the containing div like this

    <?php
    $list = wp_list_pages("title_li=&amp;child_of=$id&amp;show_date=modified&amp;date_format=$date_format&amp;echo=0"); ?>
    
    if ($list) { ?>
       <div class="interior">

    What this means is the output from wp_list_pages gets stored in the variable $list instead of being displayed on the screen.

    The if ($list) says, if there is a value in $list then display the following code, otherwise don’t.

    The code looks like this

    `<?php
    global $id;
    $list = wp_list_pages(“title_li=&child_of=$id&show_date=modified&date_format=$date_format&echo=0”); ?>
    if ($list) { ?>
    <div class=”interior”>
    <ul class=”tabs”>
    <li class=”cat”>Sub-Menu

    <div class=”tabcontent” id=”tab-blr”>

      <?php
      echo $list; ?>

    </div>
    <?php } ?>

    By the way, one of your div’s is not closed.

    I didn’t test this code but it should work or be very close to working.
    The “echo $list” displays the output that was stored at the top from the wp_list_pages statement.

    let me try again with code…

    <?php
    global $id;
    $list = wp_list_pages("title_li=&amp;child_of=$id&amp;show_date=modified&amp;date_format=$date_format&amp;echo=0"); ?>
    if ($list) { ?>
      <div class="interior">
        <ul class="tabs">
          <li class="cat"><a href="#tab-cat">Sub-Menu</a></li>
        </ul>
         <div class="tabcontent" id="tab-blr">
    
        <ul>
          <?php echo $list ?>
        </ul>
      </div>
    <?php } ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to hide a list unless on a certain page’ is closed to new replies.