Support » Fixing WordPress » the_content and next_posts_link did not work with query_posts

  • Below is my query_post() for a custom query.

    Why is the_content() displaying my full post instead of just the part above the “more” comment tag?

    Why does next_posts_link() not paging through to the rest of the result set? It keeps just displaying the first page. Is it becasue “next_posts_link()” only works when there is /tag/ in the url?

    $myposts = query_posts('tag=dvds-science,dvds-nature&posts_per_page=15');
    foreach($myposts as $post) :
      <div class="post" id="post-<?php the_ID(); ?>">
      <h1><?php the_title(); ?></h1>
          <div class="entry">
    	 <?php the_content('Read more'); ?>
    <?php endforeach; ?>
    <br /><br />
    <?php next_posts_link('Next Page &raquo;') ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • I have the same problem like you, but the_content() can work, and next_posts_link() did not work.
    my pagelate code is:

      <?php query_posts('cat=8'); ?>
      <?php while (have_posts()) : the_post(); ?>
      <?php the_title(); ?>
      <?php endwhile;?>

    Which version of wordpress are you guys using? Some of the prev/next links are not working under specific circumstances has been reported.

    I was having a similar problem – I am using query_posts() to display all but one category on my main page, and this was causing my next_posts_link() and previous_posts_link() functions to break.

    The solution posted here fixed the problem:

    Note however that my $paged/query_posts() is BEFORE the “if (have_posts()) :” line.

    (I am running 2.5)

    Well looks like the thread starter has found a solution somewhere else as well.

    Great! I’m looking for this solution for many days.

    WordPress codex said:

    The query_posts function is intended to be used to modify the main page Loop only.
    It is not intended as a means to create secondary Loops on the page.
    If you want to create separate Loops outside of the main one, you should create separate WP_Query objects and use those instead.

    In main page, I can use this:
    query_posts("$query_string . "category_name=life&paged=$paged");
    but it doesn’t work in my custom Template page.

    Now I use this:

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
    <?php query_posts("category_name=life&paged=$paged"); ?>

    It works well in my custom template page.

    I’m not familiar with php. Now I foud create a WP_Query works well too.

    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    	<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    <?php $wp_query = null; $wp_query = $temp;?>

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘the_content and next_posts_link did not work with query_posts’ is closed to new replies.