rsilvajls
Member
Posted 4 months ago #
I have used the following code to display a category post feed on a page on my site however I cant seem to get it to link to their pages.
// The Query
query_posts( array ( 'category_name' => 'news-articles', 'posts_per_page' => -1 ) );
// The Loop
while ( have_posts() ) : the_post();
echo '<li><a href="#">';
the_title();
echo '</a></li>';
echo '';
endwhile;
// Reset Query
wp_reset_query();
Mod edit: Code fixed
Hi rsilvajls,
I'd suggest you use the WP_Query class instead. Perhaps something like this:
// The Query
$query = new WP_Query( array(
'category_name' => 'news-articles',
'posts_per_page' => -1
) );
// The Loop
while ( $query->have_posts() ) : $query->the_post();
?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
<?php
endwhile;
// Reset Query
wp_reset_postdata();
rsilvajls
Member
Posted 4 months ago #
Wow thank you! soo much! Worked like a charm!