WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Issues when using the_content() with query_posts() (8 posts)

  1. majkelos
    Member
    Posted 1 year ago #

    Hi everbody,
    I'm trying to create the static page (named HOME) which would have some querried posts on it. When i'm executing code as this one:

    <?php
    	$args = array(
    		'cat'=>8,
    	);
    	query_posts($args) ?>	
    
    	<!-- while funkcja -->
    	<?php while ( have_posts() ) : the_post(); ?>
    	<!---  ----------- --->
    		<div class="sticky-header">
    			<h1><?php the_title() ?></h1>
    		</div><!-- .sticky-header -->
    
    		<div class="entry-summary">
    			the_content()
    		</div><!-- .entry-summary -->
    
    	<?php endwhile; ?>
    	<?php wp_reset_query(); ?>

    I'm getting only first post from the querry (with all the titles and content) and after that there is a title "HOME", as the loop is giving back name of the static page and nothing else.

    On the other hand when i'm putting something like:

    <?php
    	$args = array(
    		'cat'=>8,
    	);
    	query_posts($args) ?>	
    
    	<!-- while funkcja -->
    	<?php while ( have_posts() ) : the_post(); ?>
    	<!---  ----------- --->
    		<div class="sticky-header">
    			<h1><?php the_title() ?></h1>
    		</div><!-- .sticky-header -->
    
    		<div class="entry-summary">								
    
    	</div><!-- .entry-summary -->
    
    	<?php endwhile; ?>
    	<?php wp_reset_query(); ?>

    I'm getting all the titles as requested (without any content obviously), and now not sure what is causing the problems.

    Any ideas

    Thank you

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    Try putting the_content() in php tags:

    <?php the_content(); ?>
  3. majkelos
    Member
    Posted 1 year ago #

    Hi,
    thanks for your reply - it is actually like you said.
    But still showing only one post with content, and then HOME title and nothing more

  4. keesiemeijer
    moderator
    Posted 1 year ago #

    Maybe setting how many posts you want to show?

    $args = array(
      'cat'=> 8,
      'posts_per_page' => 10
    );
    
    query_posts($args);

    Can you paste and submit the full code of the Page template into a pastebin.com and post the link to it here? see the Forum Rules for posting code and using the pastebin.

  5. majkelos
    Member
    Posted 1 year ago #

    Hi,

    http://pastebin.com/xYHarNQa

    I really have no idea what's going on. Here what i have attached are 2 loops 1st is querrying only for sticky post. --> and this one is returning only one sticky post that i have published with content, and below that there is HOME.

    Second is supposed to show all other posts, in a category (excluding sticky), in the version i posted there is no the_content(); in there and this option is showing just titles of the all posts i want.

    But as soon as i put <?php the_content(); ?> (in line 82), in there what i get is the one title, one content, and below that there is an HOME title and that's all.

    I'm trying now to solve this one using get_posts() maybe this will do, but i'm not sure how will it end up.

    Thank you

  6. keesiemeijer
    moderator
    Posted 1 year ago #

    I've tested your template in the origin theme and have no problem with the_content().

    try:
    - deactivating all plugins to see if this resolves the problem? If this works, re-activate the plugins one by one until you find the problematic plugin(s).

  7. majkelos
    Member
    Posted 1 year ago #

    Hi,

    thank you for this, it was actually one of the plug-in - My Custom Widgets, where i had an widget with small querry on the side. After disabling this one all went back to normal.

    I managed to fix original issues with this chunk of code:

    <?php
    $args = array( 'numberposts' => 10, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date", 'cat'=>8, 'post__in'  => get_option( 'sticky_posts' ));
    $postslist = get_posts( $args );
    foreach ($postslist as $post) : setup_postdata($post); ?>
    <div class="sticky-header">
    <?php echo apply_atomic_shortcode( 'entry_title', '[entry-title]' ); ?>
    <?php get_the_image( array( 'meta_key' => 'Thumbnail', 'size' => 'single-thumbnail', 'image_class' => 'featured' ) ); ?>
    </div>
    <div class="entry-summary">
    <p><?php the_content(); ?></p>
    </div>
    <?php endforeach; ?>

    basically using get_posts() instead of query_posts()

    keesiemeijer thank you again

  8. keesiemeijer
    moderator
    Posted 1 year ago #

    No problem :-)
    I'm glad you got it resolved.

Topic Closed

This topic has been closed to new replies.

About this Topic