Create Anchor Points in Category Titles of Loop
-
Hi, I hope someone will be kind enough to help with this, I don’t have a good enough understanding of PHP just yet to figure this out.
I have this piece of code (see below) that is used to show all my post titles, grouped by categories. The page will be quite long so what I want to do is have a list in the sidebar of all the categories and when one is clicked the page jumps to the start of that category of posts. So basically I need some code added to the last few lines to create anchor points, which will be unique to each category title on the page, such as:
<a name=category_name>
so that I can then target those in the side bar list with:
<a href='#category_name'>
<?php $cat_args=array( 'orderby' => 'name', 'order' => 'ASC' ); $categories=get_categories($cat_args); foreach($categories as $category) { $args=array( 'showposts' => -1, 'category__in' => array($category->term_id), 'caller_get_posts'=>1 ); $posts=get_posts($args); if ($posts) { echo '<p class="topic-titles">'. $category->name.'</p> '; foreach($posts as $post) { setup_postdata($post); ?>
Would really appreciate some help with this, thank you.
- The topic ‘Create Anchor Points in Category Titles of Loop’ is closed to new replies.