WordPress.org

Ready to get started?Download WordPress

Forums

Porting a Theme (6 posts)

  1. MaddTechWF
    Member
    Posted 4 years ago #

    I'm working on porting a theme a friend created for his site. I'm a little confused on how I would code this using the "menu" php.

    Here is the original HTML

    <ul class="main_menu">
       <li><a class="homepage" HREF="index.html"></a></li>
          <li class="selected_page">
             <div class="selected">
                <div class="selected_left"></div>
                <div class="selected_middle">
                   <a HREF="about-2520us.html">About us</a>
                </div>
                <div class="selected_right"></div>
             </div>
          </li>
          <li><a HREF="work.html">Work</a></li>
          <li><a HREF="services.html">Services</a></li>
          <li><a HREF="contact.html">Contact</a></li>
     </ul>

    I know that this code controls what is selected....

    <li class="selected_page">
             <div class="selected">
                <div class="selected_left"></div>
                <div class="selected_middle">
                   <a HREF="about-2520us.html">About us</a>
                </div>
                <div class="selected_right"></div>
             </div>
          </li>

    How can I use the standard WordPress php to reference the menu and have it use the above code.

  2. kz
    Member
    Posted 4 years ago #

    Add this in function.php:

    function the_selected(){
    echo '
    <li class="selected_page">
      <div class="selected">
        <div class="selected_left"></div>
        <div class="selected_middle">
          <a HREF="about-2520us.html">About us</a>
        </div>
        <div class="selected_right"></div>
      </div>
    </li>';
    }

    In your menu.php

    <ul class="main_menu">
       <li><a class="homepage" HREF="<?php bloginfo('url'); "></a></li>
       <?php if(is_home()) the_selected(); ?>
       <li><a HREF="<?php echo get_permalink(1) ?>">Work</a></li>
       <?php if(is_page('1')) the_selected(); ?>
       <li><a HREF="<?php echo get_permalink(2) ?>">Services</a></li>
       <?php if(is_page('2')) the_selected(); ?>
       <li><a HREF="<?php echo get_permalink(3) ?>">Contact</a></li>
       <?php if(is_page('3')) the_selected(); ?>
     </ul>

    Replace the numbers (1, 2, 3) with each page ID.

  3. MaddTechWF
    Member
    Posted 4 years ago #

    In the Function.php page do I need to put

    <a HREF="about-2520us.html">About us</a>

    or something else?

  4. kz
    Member
    Posted 4 years ago #

    Here is new code.

    functions.php

    <?
    function the_menu($link, $selected){
      if($selected) :
    ?>
    <li class="selected_page">
      <div class="selected">
        <div class="selected_left"></div>
        <div class="selected_middle">
    <?php
      endif;
      echo $link;
      if($selected) :
    ?>
        </div>
        <div class="selected_right"></div>
      </div>
    </li>
    <?php
      endif;
    }
    ?>

    menu.php

    <ul class="main_menu">
      <li><?php the_menu('<a class="homepage" href="' . get_bloginfo('url') . '">Home</a>', is_home()); ?></li>
      <li><?php the_menu('<a href="' . get_permalink(1) . '">About us</a>', is_page(1)); ?></li>
      <li><?php the_menu('<a href="' . get_permalink(2) . '">Work</a>'    , is_page(2)); ?></li>
      <li><?php the_menu('<a href="' . get_permalink(3) . '">Services</a>', is_page(3)); ?></li>
      <li><?php the_menu('<a href="' . get_permalink(4) . '">Contact</a>' , is_page(4)); ?></li>
    </ul>
  5. MaddTechWF
    Member
    Posted 4 years ago #

    What would I need to change if I wanted to apply this to a secondary menu also.

  6. MaddTechWF
    Member
    Posted 4 years ago #

    I was doing some searching and came across this little bit of code to list all of the children of a category.

    <?php
    if (is_category()) {
      $this_category = get_category($cat);
      if (get_category_children($this_category->cat_ID) != "") {
        echo "<h1>Subcategories</h1>";
        echo "<ul>";
        wp_list_categories('orderby=id&show_count=0&title_li=
    &use_desc_for_title=1&child_of='.$this_category->cat_ID);
        echo "</ul>";
      }
    }
    ?>

    I want to use it with the code you provided me before to create a second menu that has all of my subcategories for that page.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.