Support » Fixing WordPress » Need to Query Post Feed to Appear as Links

  • Resolved rsilvajls

    (@rsilvajls)


    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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Drew Jaynes

    (@drewapicture)

    WordPress Core Developer

    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();

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Need to Query Post Feed to Appear as Links’ is closed to new replies.