• Resolved babsiee33

    (@babsiee33)


    Hi All!

    I have a wordpress theme where the menu links to specific categories.

    However, two categories have only one post. So I would like to see the post opened immediatly when I click on the specific links in the menu.

    How do I make the category link directly to the post?

    Hope you guys can help 🙂

    THanks!
    – B

Viewing 1 replies (of 1 total)
  • Thread Starter babsiee33

    (@babsiee33)

    Oh i should have looked inside the forum… the solution was already there! I quote:

    here is my solution: “an automatic condition script that could be attached to the main category.php and checks if there’s just one post in the category and redirects.”
    <?php
    if(have_posts()) :
    $category = get_the_category();
    if ($category[0]->category_count == 1) :
    while (have_posts()) : the_post();
    wp_redirect(get_permalink($post->ID));
    endwhile;
    else :
    include(TEMPLATEPATH . ‘/index.php’);
    endif;
    endif;
    ?>

    Worked great!

Viewing 1 replies (of 1 total)
  • The topic ‘Link category to specific post’ is closed to new replies.