WordPress.org

Ready to get started?Download WordPress

Forums

Linking to a category (9 posts)

  1. Niclas
    Member
    Posted 9 years ago #

    hi!
    I want to link to a category in my navigation (a.k.a pages).
    How can this be done?

  2. skippy
    Member
    Posted 9 years ago #

    If you are writing a Page, and want to manually link to a specific category, simply insert the appropriate HTML in the body of your page:
    <a href="/category/foo">foo</a>

    If you want links to your categories to be automatically created as part of your templates, look into the wp_list_cats() template tag.

  3. moshu
    Member
    Posted 9 years ago #

    You have to be a bit more specific. Categories are listed in your sidebar (navigation) by using the template tag list_cats or the related wp_list_cats.
    What about Pages?

  4. Niclas
    Member
    Posted 9 years ago #

    Ok, I'll try to explain a little bit better:

    http://niclas.pigne.net/blog <- I want to link to the category "Tutorials" under "Navigation". Am I clear enough? :)

    If it's possible, I would like to hide Tutorials from the archives to. any tips on doing that?

  5. moshu
    Member
    Posted 9 years ago #

    Maybe I am wrong but my impression is under the Navigation you display your Pages (probably using the wp_list_pages tag + a manual link to homepage). And now you want to insert in this list a link to one of the categories. It would be the same way = manully, as you did with your homepage link.
    In the categories list you can choose to exclude one or more categories:
    http://codex.wordpress.org/Template_Tags/wp_list_cats#Categories_With_Excludes

  6. Niclas
    Member
    Posted 9 years ago #

    thanks! that solved the problem. I wonder why I never thought of including the link the same way I'm including the home link.

    Anyway, thanks!

  7. skippy
    Member
    Posted 9 years ago #

    Your list of links under "Navigation" is, I'm assuming, comprised solely of WordPress Pages, and is generated using the wp_list_pages() template tag.

    If you want to include a link to a category there, you have several choices:
    1) remove the wp_list_pages() template tag, and hard-code a list of navigation items to which you would like to link.
    2) create a new page, "Tutorials", using a Page Template that presents posts from your Tutorials category as you want.

  8. Niclas
    Member
    Posted 9 years ago #

    I've got a new problem.
    I tried creating a new page, like Skippy told me. And I've used the get_posts tags to include the posts from the Tutorial category into the Tutorials page.

    This is the code I've used
    <?php
    $posts = get_posts('numberposts=3');
    foreach($posts as $post) :
    setup_postdata($post);
    ?>
    <a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a>
    <?php endforeach; ?>

    But when I try to run it, wordpress gives me an error saying: "Warning: Invalid argument supplied for foreach() in /***/***/public_html/blog/wp-content/themes/ennbee2/tutorials.php on line 16"

    What am I doing wrong?

  9. Niclas
    Member
    Posted 9 years ago #

    got it all worked out now. Thanks for the help!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags