WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i do menu with this code but links redirect me too archive.php

<ul id="nav">
    $all_posts = get_posts(array(
      'posts_per_page' => -1 // to show all posts

    // this variable will contain all the posts in a associative array
    // with three levels, for every year, month and posts.

    $ordered_posts = array();

    foreach ($all_posts as $single) {
        $year  = mysql2date('Y', $single->post_date);
        $month = mysql2date('F', $single->post_date);
        // specifies the position of the current post
        $ordered_posts[$year][$month][] = $single;
    $classplus = 0;
        // iterates the years
        foreach ($ordered_posts as $year => $months) { ?>
            <a class="lever year<?php echo $classplus; ?>"><?php echo $year ?></a>

            <ul class="active">
            <?php foreach ($months as $month => $posts1 ) { // iterates the moths ?>
            <?php foreach ($posts1 as $single ) { // iterates the posts ?>
                    <a href="<?php echo get_permalink($single->ID); echo '#post-'.$single->ID;?>"><?php echo get_the_title($single->ID); ?></a></li>
            <?php } // ends foreach $posts ?>

            <?php } // ends foreach for $months ?>

        </li> <?php
        } // ends foreach for $ordered_posts

I want link too single.php not archive.php. Help me... :)

share|improve this question
What do you mean "redirected"? Do links have expected values but lead to unexpected place? Or are the links themselves wrong? – Rarst Sep 24 '13 at 20:18
Your code works, links are ok (they point to posts), the problem must be in your templates. – Dan Ștefancu Sep 24 '13 at 22:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.