WordPress.org

Forums

change ?cat= to be able to pick up the permalink (6 posts)

  1. PaulRome
    Member
    Posted 2 years ago #

    Hi,

    I need to change this line of code so instead of it being example.com/?cat=1 its example.com/categoryname/postname . Permalinks was changed to %postname% and the category base was also changed. But this line is in the home-page.php of the theme

    <li><a class="arrow-aligned-left" href="<?php echo get_bloginfo('url') . '?cat=' . $category->term_id; ?>">&nbsp;&nbsp;&nbsp;<?php echo $category->name; ?></a></li>

    Thank You

  2. chrismichaels84
    Member
    Posted 2 years ago #

    So, I don't know if I understand exactly what you're asking. This line of code seems to display a full category, but you want it rewritten to include a post name as well? Can you show me the SQL query that populated $category please?

  3. PaulRome
    Member
    Posted 2 years ago #

    That was bad on my part. Sry. It displays example.com/?cat=1 I would like it to display example.com/category/categoryname/

    Thanks

  4. chrismichaels84
    Member
    Posted 2 years ago #

    Okay, try this:

    <li><a class="arrow-aligned-left" href="<?php echo get_bloginfo('url') . '/' . $category->name . '/' . $category->slug ?>">&nbsp;&nbsp;&nbsp;<?php echo $category->name; ?></a></li>

    That will show:
    /My Category/my-category/

    you can replace the variables after the -> with any of these term_id for the number, name for the full name as it appears on the page and slug for the wordpress site name with dashes and such.

    Does that answer your question?

  5. PaulRome
    Member
    Posted 2 years ago #

    Ty, Just about works.

    So instead of example.com/restaurants/italian/ - I renamed the category base.

    It displays example.com/Italian/italian/

    Thanks

  6. PaulRome
    Member
    Posted 2 years ago #

    I just ended up hard coding it, well actually a friend gave the code.

    <li><a class="arrow-aligned-left" href="<?php echo get_bloginfo('url') . '/restaurant/' . $category->slug ?>/">&nbsp;&nbsp;&nbsp;<?php echo $category->name; ?></a></li>

Topic Closed

This topic has been closed to new replies.

About this Topic