• Resolved davidelliott294

    (@davidelliott294)


    Hi,

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    	<h1><?php the_title(); ?></h1>
    		<?php the_content(); ?>
    	<?php endwhile; else: endif; ?>
    
    	<?php query_posts('cat=6'.get_the_title().'&post_status=publish,future');?>
    	<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    	<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    	<p><?php the_content(); ?>
    	<?php endwhile; else: endif; ?>

    I’m using that code to post posts in specific categories to specific pages on my wordpress blog. It does what I want it to do but it seems to continuously loop and keep posting as your scroll down.

    Can anyone help me with this?

    Cheers

Viewing 4 replies - 1 through 4 (of 4 total)
  • 1. Don’t use query_posts() to customise anything other than the main query. Use get_posts() or WP_Query() instead.

    2. Remember to add a posts_per_page parameter in your secondary query.

    Thread Starter davidelliott294

    (@davidelliott294)

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    	<h1><?php the_title(); ?></h1>
    		<?php the_content(); ?>
    	<?php endwhile; else: endif; ?>
    
    	<?php get_posts('cat=6'.get_the_title().'&post_status=publish,future'.post_per_page="10");?>
    	<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    	<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    	<p><?php the_content(); ?>
    	<?php endwhile; else: endif; ?>

    So the code looks like that? Specifically aimed at post_per_page parameter as i’m not 100% that is correctly written. I can only edit PHP.

    Wont it take the default settings from what is set in settings?

    Thread Starter davidelliott294

    (@davidelliott294)

    Also changing query_posts to get_posts does nothing other than mess up the layout of the posts.

    Thread Starter davidelliott294

    (@davidelliott294)

    Never mind. Sorted it.

    my code for the page now looks like this:

    <?php
    /**
     * The template for displaying all pages.
     *
     * This is the template that displays all pages by default.
     * Please note that this is the wordpress construct of pages
     * and that other 'pages' on your wordpress site will use a
     * different template.
     *
     * @package WordPress
     */
    /*
    Template Name: howto
    */
    ?>
    <?php get_header(); ?>
    <!--Start Content Wrapper-->
    <div class="grid_24 content_wrapper">
      <div class="grid_16 alpha">
        <!--Start Content-->
    
        <div class="content">
    
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    	<h1><?php the_title(); ?></h1>
    		<?php the_content(); ?>
    	<?php endwhile; else: endif; ?>
    
    	<?php query_posts('cat=6'.get_the_title().'&post_status=publish,future');?>
    	<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    	<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    	<p><?php the_content(); ?>
    	<?php endwhile; else: endif; ?>
    
          <!--Start Comment box-->
          <?php comments_template(); ?>
          <!--End comment Section-->
        </div>
        <!--End Content-->
        <?php endwhile;?>
      </div>
      <!--Start Sidebar-->
      <?php get_sidebar(); ?>
      <!--End Sidebar-->
    </div>
    <!--End Content Wrapper-->
    <div class="clear"></div>
    </div>
    <!--End Container-->
    <?php get_footer(); ?>

    and it works (y).

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Posting posts in a certain category to specific pages’ is closed to new replies.