Support » Fixing WordPress » dynamic link to category

  • Resolved onirisweb



    Like the title says, I am trying to get a dynamic link of a category.

    Actually I am building a custom archive template, which displays the 5 last posts in each category.

    Here is my code :

                // get all the categories from the database
                $cats = get_categories();
                    // loop through the categries
                    foreach ($cats as $cat) {
                    <div class="<?php my_post_class(); ?>">
                        // setup the cateogory ID
                        $cat_id= $cat->term_id;
                        // Make a header for the cateogry
                        echo "<span class='position-band'><span class='band-side'></span><span class='band-small-title'>".$cat->name."</span><span class='band-right'></span></span>";
                        <div class="clear"></div>
                        // create a custom wordpress query
                        // start the wordpress loop!
                        if (have_posts()) : while (have_posts()) : the_post(); ?>
                            <?php // create our link now that the post is setup ?>
                            <div class="title-cat"><a href="<?php the_permalink();?>"><?php the_title(); ?></a></div>
                            <?php echo '<br/>'; ?>
                        <?php endwhile; ?>
    	<a href="?cat=<?php $cat=$cat_id ?>">(View more...)</a>
    				<?php	endif; // done our wordpress loop. Will start again for each category ?>
                                    <?php } // done the foreach statement ?>

    If this code works well, I would like to make a View More link going to the specific category page.

    Actually my view more link doesn’t work. It goes to index page 🙁

    <a href="?cat=<?php $cat=$cat_id ?>">(View more...)</a>

    What’s wrong with it ?

    Thanks for your help.

Viewing 1 replies (of 1 total)
  • Ok I found how to make it :

    $category = get_the_category();
    echo '<a href="'.get_category_link($category[0]->term_id ).'">View More</a>';

    If it can help somebody…

Viewing 1 replies (of 1 total)
  • The topic ‘dynamic link to category’ is closed to new replies.