Post Navigation

I have a widget area on my posts category pages and am wondering if there is a way to dynamically add a link to the first post as well as the current post of the category. I think the first post can be hardcoded since it will never change, but the current one will. I wonder what sort of php madness that can do this?

I know I know, you are asking why not just use the post navigation that already comes right… Well clients being what they are.

Any help is greatly appreciate and will very much aid in my not walking of a cliff.

1 Answer
1

you can use wp-pagenavi and set the “number of pages to show” to 3
so you will get

[first] [6] [7] [8] [last]

now if you just need the names of the post then you could do something like this:

global $wp_query;
    //curent post
    $thePostID = $wp_query->post->ID;
    $my_query = new WP_Query(array('cat' => get_query_var('cat')));
    $count = 0;
    $curent_count = 0;
    if ($my_query->have_posts()){
        while  ($my_query->have_posts()){
            $no_repeat = array();
            $my_query->the_post();
            $count = $count + 1;
            if ($count = 1 ){// the first post in the category
                if (!in_array($post->ID,$no_repeat){
                    echo '<a href="'.the_permalink().'">'.the_title().'</a> ';
                    $no_repeat[] = $post->ID;
                }
            }
            if ($count = ($thePostID -1) ){//previous post
                if (!in_array($post->ID,$no_repeat){
                    echo '<a href="'.the_permalink().'">'.the_title().'</a> ';
                    $no_repeat[] = $post->ID;
                }
            }
            if ($count = $thePostID){//Current post
                if (!in_array($post->ID,$no_repeat){
                    echo '<a href="'.the_permalink().'">'.the_title().'</a> ';
                    $no_repeat[] = $post->ID;
                }
            }
            if ($count = ($thePostID + 1)){//Current post
                if (!in_array($post->ID,$no_repeat){
                    echo '<a href="'.the_permalink().'">'.the_title().'</a> ';
                    $no_repeat[] = $post->ID;
                }
            }
        }
    }

Hope this helps.

Leave a Comment