WordPress.org

Ready to get started?Download WordPress

Forums

Navigation Help (2 posts)

  1. NoahRodenbeek
    Member
    Posted 2 years ago #

    I need a way to make a navigation button that sends a reader to a categories first post depending on which category they're currently looking at. Pleeeeease help!

  2. vtxyzzy
    Member
    Posted 2 years ago #

    This seems to work for me:

    Create a template that displays a single post in a category which is passed in the GET variable 'mycat'. Code similar to this:

    $cat = $_GET['mycat'];
    query_posts("cat=$cat&posts_per_page=1&ignore_sticky_posts=1");
    if (have_posts()) {
       while (have_posts()) {
          the_post();
          the_title();
       }
    } else {
       // Code here for nothing found
    }

    Assuming that you want the button on a category page, create it like this:

    <?php $cat = get_query_var('cat');
     $action = get_bloginfo('url') . "/my-single-cat-page-slug/";
     ?>
    <form action="<?php echo $action; ?>" method="get">
       <input type="hidden" name="mycat" value="<?php echo $cat; ?>">
       <input type="submit" value="Run me now!">
    </form>

Topic Closed

This topic has been closed to new replies.

About this Topic