Forums

[resolved] wired links, changes dynamicaly (5 posts)

  1. devric
    Member
    Posted 1 year ago #

    Hi, i come up to a weird issue, look at the code below, the get_home_url and the_category('7'), both these changes the link dynamically,
    eg:
    if im in a category, cat=4, get_home_url returns the link to cat=4, and the_category('7') returns the title of category4, and this behavior changes to the page according to whatever pages im in

    <li>
     <a href="<?php get_home_url(); ?>"><div class="menu">Home</div></a>
     <ul><?php wp_list_cats("exclude=7"); ?></ul>
    </li>
    <li>
     <div class="menu"><?php the_category('7'); ?></div>
    </li>

    Anyone have any ideas how to fix it??
    thank you

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    wp_list_cats is a deprecated function and the_category can only be used in the loop.
    try it with this:

    <li>
     <a href="/"><div class="menu">Home</div></a>
     <ul><?php wp_list_categories("exclude=7"); ?></ul>
    </li>
    <li>
     <div class="menu">
    <?php
    $category_id =7;
    $category_link = get_category_link( $category_id ); ?>
    <!-- Print a link to this category -->
    <a href="<?php echo $category_link; ?>" title="Category Name">Category Name</a>
    </div>
    </li>
  3. devric
    Member
    Posted 1 year ago #

    Thanks kee!! solved the issue of category links

    however, the home link '/' gets to the root directory, not the installation folder. how do i get to the installation folder?

    Thanks

  4. keesiemeijer
    moderator
    Posted 1 year ago #

    change this:

    <a href="/"><div class="menu">Home</div></a>

    to this:

    <a href="<?php echo home_url(); ?>"><div class="menu">Home</div></a>
  5. devric
    Member
    Posted 1 year ago #

    nice thanks again Kee!

    the echo home_url works!!, i guess the get_home_url is deprecated too huh

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags