Link to home
Start Free TrialLog in
Avatar of Doug Foster
Doug FosterFlag for United States of America

asked on

wordpress -- add previous next links to archive

I want to add previous/next links to an archive template.

Here is the code I have for the function in the category.php page.  A sample archive on the site is http://southnyack.ny.gov/category/mayors-update/.



function custom_tax_group() {  
    $term = get_term_by('id', get_query_var('cat'), 'category');
    $count = 0;
    $cat_name = get_cat_name( $term->term_id );
    $the_query = new WP_Query('cat='.$term->term_id);
    $left = $the_query->post_count % 2 == 0 ? -1 : $the_query->post_count;

    if ($the_query->have_posts()) {
    		echo '<h2>' . $cat_name . '</h2>';

        ?>

        <table width="100%">

            <tbody>

            <?php

            while($the_query->have_posts()){

                $the_query->the_post();

                if($count == 0){

                    echo '<tr>';

                }

                $image =  wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()),'thumbnail');

                ?>

                <td>

                    <a href="<?=get_the_permalink();?>"><?=get_the_title();?></a>

                    <p><?=get_the_excerpt();?></p>

                </td>

                <?php

                $count++;

                if($count == 2 || ($left == 0)){

                    echo '</tr>';

                    $count = 0;

                }

                if($left > -1){

                    $left--;

                }

            }
            ?>
            </tbody>
        </table>
        <?php
        //echo '&nbsp;<a class="more-link" href="' . get_permalink() . '" rel="nofollow">Read More &hellip;</a>';
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial