So I query the posts, I get back everything that matches, then do my loop - but I want to do some sort of print_r type thing on each loop so I can see 100% of what data is being fetched. I've got a total brain block here.. Help!
Here is my query, and then my loop:
<?php query_posts('post_type=property'); ?>
<?php while (have_posts()) : the_post(); ?>
<?php endwhile; ?>
Just can't figure out how to echo out 100% of what was fetch through each iteration of the loop?
Thanks for the help everyone!
Does it have to use the loop? If not then I would try:
<? $posts_array = get_posts('post_type=property');
print_r($posts_array); ?>
inside your loop
print_r($post);
I like to add the following to the top of any of my single php pages where I want to see the output...
<?php global $post; var_dump($post);die;?>
and in the loop :-
the_post();
global $post;
print_r($post);
Related
I know how to use few loops without duplicate posts.
But My question is:
Suppose I have two loops, each two loop shows 1 post only, both of them have the same newest post. if I use the code below, the duplicate post will be not shown at the second loop, but it is also stop to continue with the next post. how to solve it. million thx!
code:
<?php $my_query = new WP_Query('cat=1,2&posts_per_page=1');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID; ?>
first loop
<?php endwhile; ?>
<?php query_posts('cat=10&posts_per_page=1'); if (have_posts()) : while (have_posts()) : the_post(); if (in_array($post->ID, $do_not_duplicate)) continue;?>
second loop
<?php endwhile; endif; ?>
I think you need to clean the example up a little bit:
You have $do_not_duplicate = $post->ID;, assuming your variable is the String post_id, then you check if (in_array($post->ID, $do_not_duplicate)) continue;
At this point $do_not_duplicate is NOT an array().
If you want to store an array(), try this: $do_not_duplicate[] = $post->ID;, then you can perform your current check.
I have created a custom post type calles articles and a custom "category like" taxonomy called areas which seem to be working fine. The problem is that in my taxonomy-areas.php page they don't show up if I use the regular loop, I have to explicitly append "post_type=articles" to the query string for it to work. Shouldn't this be picked up by default?
My taxonomy page looks like this:
<?php $paged = (get_query_var('page')) ? get_query_var('page') : 1; ?>
<?php global $query_string; query_posts($query_string . '&post_type=articles&paged=' . $paged); ?>
<?php if (have_posts()) while (have_posts()) : the_post(); ?>
// Handle loop
<?php endwhile; ?>
I just fixed it with this: http://walrusinacanoe.com/web-development/742
And removed the 2 extra lines on top of the loop :)
I tried everything found in the web, but i'm getting errors or that's not what I am searching for...
I have to make a PAGE in wordpress, to show ONLY the posts of the category with a certain ID ( in my case id=8 )
i tryed to edit the loop-xxxx.php .. the template file... everything but I get always a problem
navigation system doesn't work. I mean... getting back to older posts won't work cause the output shows the last posts instead of older one.
The code I'm using in the loop or in the template file is:
<?php
query_posts('cat=8');
while (have_posts()) : the_post();
the_content();
endwhile;
?>
i tried inserting it before the
<?php while ( have_posts() ) : the_post(); ?>
in loop.php
or before the call of loop inside the index.php
please help me :\
One solution is to use a custom WP_Query. In the custom page's TEMPLATE file, where ID is the id of the targeted category:
<?php $tmp_query = new WP_Query('cat=ID');
while ( $tmp_query->have_posts() ) : $tmp_query->the_post();
the_content();
endwhile;
wp_reset_postdata();
?>
Check this.
<?php query_posts($query_string . '&cat=8'); ?>
<?php if (have_posts()) : ?>
<optional> You can write here: "You are in category X". </optional>
<?php while (have_posts()) : the_post(); ?>
Good luck.
Does anyone know what the best way to implement a list/grid togglable view in wordpress would be?
To be more clear: the default view shows the posts in a list, I would like to have the option to show them in a grid.
I have so far created a loop which shows only the thumbnails, and included it in another template.
But I don't know how I would link to that view. Would I best off using an archive view?
Thanks.
One of the easiest solutions is to create a page template containing a grid view and add a link to this page in the list view. Very simple but just what you need.
I had the same issue with pagination. WordPress has built in function posts_nav_link that automatically prints links to previous and next pages if needed. The problem is that this function works only with $wp_query instance of WP_Query (this instance is used by default, for example to get page's content or the latest posts in home). So the solution for you:
<?php
$temp=$wp_query;
$wp_query=null;
$wp_query = new WP_Query('showposts=4');
while(have_posts() ) : the_post(); ?>
<?php the_post_thumbnail( array(160,160) );?>
<h2><?php the_title(); ?></h2>
<?php endwhile;
posts_nav_link();
$wp_query = $temp; ?>
I think that's quite obvious and there is no need of explanation :) should be working
Thanks dude. I kind of got it working for now with this:
<?php $latest = new WP_Query('showposts=4'); ?>
<?php while( $latest->have_posts() ) : $latest->the_post(); ?>
<?php the_post_thumbnail( array(160,160) );?>
<h2><?php the_title(); ?></h2>
<?php endwhile; ?>
I think my mistake was trying to get it to use get_template_part( 'loop', 'grid' ); It would show the page, but no posts. Even if used get_template_part( 'loop', 'index' );
I'll need to figure out the pagination, but I'm putting it down for now to work on something else.
Thanks for your help so far! #Gediminas
I am using the following code to try and display posts from only a certain category horizontally in three rows. I have the horizontal display issue figured out (using css) but with the following code it displays all posts and not posts from specific category.
<?php query_posts('showposts=5'); ?>
<?php query_posts('cat=7'); ?>
<?php $posts = get_posts('numberposts=5&offset=0'); foreach ($posts as $post) : start_wp(); ?>
<?php static $count1 = 0; if ($count1 == "5") { break; } else { ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php $count1++; } ?>
<?php endforeach; ?>
Any help would be greatly appreciated.
You're misunderstanding some concepts in query_posts and get_posts.
query_posts is to be used inside the loop. get_pages isn't. If you want to use query_posts, you don't need to create the get_pages call. Use query_posts or get_pages to accomplish what you're trying to do.
You need to combine your category parameters in query_posts.
<?php
query_posts('showposts=5&cat=7');
//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
..
endwhile; else:
..
endif;
//Reset Query
wp_reset_query();
?>
If you want to do the same logic but without The Loop, just call
$posts = get_posts('numberposts=5&offset=0&category=7').
Read the links I provided. They have all information you need to understand how to do what you need.