WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How do I use nicer slugs for this? (3 posts)

  1. Emphacy
    Member
    Posted 3 years ago #

    I decided I wanted to redirect any page I made in the header file to a category. For instance I let the page 'How-To' in the navigation bar redirect to the category 'How-To'.

    I did this by editing the header file and adding the following code for each page I wanted to redirect.

    <?php wp_list_pages('title_li=&sort_column=menu_order&exclude='.get_option('tbf1_exclude_pages')); ?>
    <li><a href="<?php bloginfo('url'); ?>/?cat=4">How-To</a></li>

    As you can see however, the code redirects to ?cat=4 or a numeric slug. In my website I want my slugs to be text; 'how-to' for instance.

    However if I change this in the settings to use the word based slugs rather then the numeric slugs, the page still redirects to the category and shows ?cat=4 in the address bar, but I want it to show how-to instead of ?cat=4.

    If I click on category link however, it will go to the category and will display the how-to slug in the address.

    How do I fix this? I'm assuming I should edit my code somehow.
    I hope this makes sense. Thankyou.

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    instead:
    <li><a href="<?php bloginfo('url'); ?>/?cat=4">How-To</a></li>

    try to use:
    <li><a href="<?php echo get_category_link(4);">How-To</a></li>

    http://codex.wordpress.org/Function_Reference/get_category_link

  3. Emphacy
    Member
    Posted 3 years ago #

    Thanks very much for your help!
    Code works perfect with the addition of the missed ?>
    ;)

    <li><a href="<?php echo get_category_link(4); ?>">How-To</a></li>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.