• I need a way of showing the categories but linking to the first post in that category.
    How can I go about that?

    At the moment I am showing the categories like:

    <?php wp_list_categories('sort_column=menu_order&title_li&depth=1&child_of=10&exclude=16'); ?>

    However these link to the archive for that page but I need it to go to the first page.

    Is there a way?

Viewing 1 replies (of 1 total)
  • <?php
    $taxonomy = 'category';
    $param_type = 'category__in';
    $term_args=array(
      'orderby' => 'name',
      'order' => 'ASC'
    );
    $terms = get_terms($taxonomy,$term_args);
    if ($terms) {
      foreach( $terms as $term ) {
        $args=array(
          "$param_type" => array($term->term_id),
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => 1,
          'caller_get_posts'=> 1
          );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php echo $term->name; ?></a></p>
           <?php
          endwhile;
        }
      }
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘List Categories and link to first/specific post’ is closed to new replies.