WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] use "php bloginfo" to get link to category (4 posts)

  1. csleh
    Member
    Posted 5 years ago #

    I have a menu that links to category pages. Using list_categories works great, but on the home page each

    <li> has a different image. All this is working but now need to add the link on the home page to the category page.
    I'm hoping for something easy, like:
    <a>/category/category-name.php">category-name</a>

    I want to do this instead of hardcoding in the url, in case we make changes to the permalinks before the site goes live.

    SO -- How/where can I find the info for base url?

  2. csleh
    Member
    Posted 5 years ago #

    Never mind, I was being a bit of an idiot. since each

  3. gets its own class, I just need to add a different id to the home
      and style the links.

      So:

      <?php
      if (is_page(13)) {echo '<div id="mainnav"><ul id="homenav">';
      wp_list_categories('');
              echo '</ul></div>';
      }  else {
             echo '<div id="mainnav"><ul>';
      wp_list_categories('');
              echo '</ul></div>';
      }
      ?>
  • csleh
    Member
    Posted 5 years ago #

    oops, still not thinking clearly. While the above works, it isn't what I wanted. My code used a <div> after each opening
    <li>, with the image set as a background. Using the code above puts the image behind the li. This doesn't work because I'd have to add the background color to the image an adjust how the text lines up. Just messy.

    Any idea how I can add a div to each line item?

  • csleh
    Member
    Posted 5 years ago #

    sheesh. got it:

    <div id="mainnav"><ul id="homenav">
      <li class="cat-item-3"><a href="/category/cat-name1/">
              <div class="class1"></div>category 1</a></li>
      <li class="cat-item-4"><a href="/category/cat-name2/">
              <div class="class2"></div>category 2</a></li>
      <li class="cat-item-5"><a href="/category/cat-name3/">
               <div class="class3"></div>category 3</a></li></ul>
    </div>

    It would be nice there was a way to add a span or div automatically with wp_list_categories because then if a category changes I wouldn't have to edit the header file.

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags