Support » Fixing WordPress » query for page content after default post query in index.php as blog template

  • query for page content after default post query in index.php as blog template

    Hi there,
    I am having some serious problem. Tried in at least hundreds of ways. nothing din work. what is very funny it has a pattern of out putting wrong info. like

    1. shows 3 the latest post (number post to show is comes from the default query no matte what i set in the second query )
    2. show last published page content. not the one I am working on. (index.php)
    3. or errors; when there’s a mistake.

    What I wan to do is to show the content of page named blog using default template profile (index.php).

    Scenery Details:
    1. on top of the index.php I have queried for 3 latest post using default query if hav_posts(); while have_post(). which is fine having no prob.

    2. 1 page got page content query in the top portion of the template. then a query for 4 latest post from single category with post excerpt.

    1 page got 2 different queries for 2 category.
    1 page got page content query in top portion of the page template. and in below div got q query for a custom post.

    what code I am using to query for the page content is as follows

    <div class="col2 marg_right1 blog_page">
    	<?php
    		global $post;
    		$args = array( 'posts_per_page' => 1, 'post_type'=> 'page' );
    		$myposts = get_posts( $args );
    		foreach( $myposts as $post ) : setup_postdata($post); ?>
    	<?php $post_title = get_post_meta($post->ID, 'page_title', true);
    		if ($post_title) {
    		?>
    		<h3><?php echo $post_title; ?></h3>
    
    		<?php } else { ?>
    
    		<h3><?php the_title(); ?></h3>
    
    	<?php } ?>
    	<div class="wrapper">
    		<figure class="left marg_right2"><?php the_post_thumbnail('single-post-image', array('class' => 'featured_img')); ?></figure>
    		<?php the_content(); ?> 
    
    	</div>
    	<?php endforeach; ?>
    </div>

    What it show are the contents from the latest I have created. when a new page is created the content change to the newer page.

    well the loop from top is common so I am not putting it here.

    and the queris on there page i have used for latest from a catergory is as follwos.

    <div class="wrapper">
    	<h3>Our History</h3>
    	<?php if (!is_paged() ) { ?>
    		<?php
    			$args = array(
    				'cat' => 5,
    				'post_type' => 'post',
    				'post_status' => 'publish',
    				'posts_per_page' => 4,
    				'caller_get_posts'=> 1
    				);
    			$loop = null;
    			$loop = new WP_Query($args, 'paged=' . get_query_var( 'page' ));
    		?>
    		<?php while ( $loop->have_posts () ) : $loop->the_post() ; ?>
    	<div class="col1 marg_right2">
    		<h3 class="color1"><?php the_title();?></h3>
    		<?php the_post_thumbnail('post-image', array('class' => 'post-thumb')); ?>
    		<?php the_excerpt(); ?>
    	</div>
    	<?php endwhile; ?>
    		<?php wp_reset_query(); ?>
    	<?php } ?>
    	<div class="pagination">
    	<?php if(function_exists('wp_paginate')) {
    		wp_paginate();
    	} ?>
    </div>
    
    </div>

    all other pages shows the contents it has. with page content query on top and category query loop below. but index page got the loop on the top and page content query below.

    wish any one do seriously read it and help me out from such disaster.

    thank you very much in advance.

  • The topic ‘query for page content after default post query in index.php as blog template’ is closed to new replies.