WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Need to Query Post Feed to Appear as Links (3 posts)

  1. rsilvajls
    Member
    Posted 1 year 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

  2. 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();
  3. rsilvajls
    Member
    Posted 1 year ago #

    Wow thank you! soo much! Worked like a charm!

Topic Closed

This topic has been closed to new replies.

About this Topic