Default Loop don't work in Wordpress 3.5 - wordpress

I'm having some trouble calling a loop on a Wordpress Page other than the default article page.
This is my code I'm using:
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
</div>
<div class="navigation">
<div class="next-posts"><?php next_posts_link(); ?></div>
<div class="prev-posts"><?php previous_posts_link(); ?></div>
</div>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1>Not Found</h1>
</div>
That doesn't show up anything.
But if I only use the query:
<?php query_posts('showposts=10');
$ids = array(); while (have_posts()) : the_post();
$ids[] = get_the_ID(); the_title(); the_content(); endwhile;
?>
It works, but I - of course can't style the entries.
Can anybody help?
Thx!

Try this:
<?php query_posts('showposts=10'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<div class="navigation">
<div class="next-posts"><?php next_posts_link(); ?></div>
<div class="prev-posts"><?php previous_posts_link(); ?></div>
</div>
<?php else : ?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1>Not Found</h1>
</div>
<?php endif; ?>
<?php wp_reset_query(); // reset the query ?>

Related

posts showing in same div Wordpress

All my posts are showing in the same div, rather than seperate ones,
<?php get_header(); ?>
<div class="mainwrap">
<div class="bloginner">
<!-- begin section -->
<section>
<div class="postswrap">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="commentsetall"><img src="<?php bloginfo('template_url'); ?>/images/ico_folder.png" alt="Posted" /><span class="commentfix"><?php the_time('F j, Y') ?> in <?php the_category(', ') ?> by <?php the_author() ?></span></div>
<h1><?php the_title(); ?></h1>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<div class="clearfix"></div>
</div>
</section>
<!-- end section -->
</div>
<div class="clearfix"></div>
</div>
<?php get_footer(); ?>
Is there a clearfix im maybe missing to stop this from happening?
thanks
put the <div class="postswrap"> inside the loop.something like that:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="postswrap">
<div class="commentsetall"><img src="<?php bloginfo('template_url'); ?>/images/ico_folder.png" alt="Posted" /><span class="commentfix"><?php the_time('F j, Y') ?> in <?php the_category(', ') ?> by <?php the_author() ?></span></div>
<h1><?php the_title(); ?></h1>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<div class="clearfix"></div>
</div>
<?php endif; ?>

Show heading only if there are posts in a category in WordPress

I need to show a heading over a category and it must only be shown if there are posts in the category in WordPress. The heading should not be placed over every post. How can it be solved?
The code I got right now:
<?php query_posts('category_name=onestar&showposts=5'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="wrapper orangecolor">
<article class="intro">
<h2><?php the_title(); ?></h2>
<div><?php the_content(); ?></div>
</article>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php query_posts('category_name=onestar&showposts=5'); ?>
<?php if ( have_posts() ) : ?>
Put the header here
<?php while ( have_posts() ) : the_post(); ?>
<div class="wrapper orangecolor">
<article class="intro">
<h2><?php the_title(); ?></h2>
<div><?php the_content(); ?></div>
</article>
</div>
<?php endwhile; ?>
<?php endif; ?>

WordPress Query Posts To Show All & Style Each One

I am trying to include every post onto my index page on WordPress and have each one of them be styled with the included CSS. I am able to query all of the posts and have them show up, but only the first post is actually styled. The rest inherit the base h1, h2, p and other generic styles, but they aren't inheriting the "box" class for each one. All of the information is being thrown into one 'box' class instead of starting a new 'box' class for each post like I would like it to do. Any help on this would be appreciated.
Here is my code I am using
<?php get_header(); ?>
<div id="index-float-left">
<div class="box">
<?php query_posts( 'showposts=-1' ); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?></p>
<p class="post-date"><?php echo $post_date = get_the_date(); ?></p>
</div>
</div> <!-- END BOX -->
</div> <!-- FLOAT BOX BOX -->
<?php endwhile; ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
There is a problem with "End Box" and "Fload Box Box". Can you try like this:
<?php get_header(); ?>
<div id="index-float-left">
<?php query_posts( 'showposts=-1' ); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="box">
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?></p>
<p class="post-date"><?php echo $post_date = get_the_date(); ?></p>
</div>
</div> <!-- END BOX -->
<?php endwhile; ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
</div> <!-- FLOAT BOX BOX -->
<?php get_sidebar(); ?>

Wordpress loop count

I have created a simple Wordpress loop already but now it should loop a little differently and i dont know how to start or even where to start. I have inside DIV class="item-row-wrap" my loop it loops through DIV class="vinyl-wrap" normally.
My problem: i would like it to loop three times and then to create a new DIV class="item-row-wrap" and start again looping DIV class="vinyl-wrap" three times...and go on and on
Here is the code:
<code>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if(get_field('artist-repeater')): while(has_sub_field('artist-repeater')): ?>
<div class="item-row-wrap"> <!--START of item-row-wrap-->
<div class="vinyl-wrap"> <!--START of vinyl-wrap-->
<?php if(get_sub_field('play-repeater-songlink')): ?>
<a class="play" href='<?php the_sub_field('play-repeater-songlink'); ?>' target="_blank"></a>
<?php endif; ?>
<?php if(get_sub_field('moreinfo-repeater-song')): ?>
<a class="more-info" href='<?php the_sub_field('moreinfo-repeater-song'); ?>' target="_blank"></a>
<?php endif; ?>
<div class="vinyl-cover">
<div class="vinyl-cover-plastik"></div>
<?php if(get_sub_field('album-repeater-image')): ?>
<?php $image = wp_get_attachment_image_src(get_sub_field('album-repeater-image'), 'thumbnail'); ?>
<img class="album-cover-art" src="<?php echo $image[0]; ?>" alt="<?php get_the_title(get_field('album-repeater-image')) ?>" />
<?php endif; ?>
</div> <!--End of vinyl-cover-->
<div class="likeit">
<?php if(function_exists(getILikeThis)) getILikeThis('get'); ?>
</div>
<div class="artist-name-wrap">
<div class="artist-wrap-left"></div>
<div class="artist-wrap-mid">
<p><?php the_title(); ?></p>
</div>
<div class="artist-wrap-right"></div>
</div> <!--End of artist-name-wrap-->
<div style="clear:both;"></div>
<div class="song-name-wrap">
<div class="song-wrap-left"></div>
<div class="song-wrap-mid">
<?php if(get_sub_field('song-repeater-name')): ?>
<p><?php the_sub_field('song-repeater-name'); ?></p>
<?php endif; ?>
</div>
<div class="song-wrap-right"></div>
</div> <!--end of song-name-wrap-->
</div> <!--END OF VINYL-WRAP-->
<?php endwhile; endif; ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<?php else: ?>
Yhtään artikkelia ei ole vielä julkaistu.
<?php endif; ?>
</div> <!--END OF ITEM-ROW-WRAP-->
Make $i var before the loop.
Up the value just before the loops closes: $i++
Set a Modulo check around the <div class="item-row-wrap"> (and the closing </div>)
Modulo tutorial
Not a complete answer but enough to get you started.
example
The example below shows how you should do this
<?php
$i = 0;
if (have_posts()) : while (have_posts()) : the_post();
if(get_field('artist-repeater')): while(has_sub_field('artist-repeater')):
if ($i % 3 == 0) {
echo '<div class="item-row-wrap"> <!--START of item-row-wrap-->';
}
$i++; // up the numer of looped
?>
DO your magic
<?php
if ($i % 3 == 0) {
echo '</div> <!--END OF ITEM-ROW-WRAP-->';
}
endwhile; //end have_posts()
endif;

WordPress Pagination on Page

I have the following code on a WordPress page. It basically just grabs 3 posts and displays them as well as the page content itself up top. What I want to add is pagination so that a user can flick through all the posts, how do I get this working with custom loops like this?
<?PHP
get_header();
/* Template Name: News */
?>
<div style="padding: 0 20px;">
<div class="box clearfix side" style="margin:10px 0;">
<div style="float:left;width:628px;">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="content" id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?><?php edit_post_link('Edit', ' <small>[', ']</small>'); ?></h2>
<?php the_content('<p>Read the rest of this page »</p>'); ?>
<?php wp_link_pages(array('before' => '<p>Pages: ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
<hr />
</div>
<?php endwhile; endif; ?>
<hr />
<?php $blog_query = new WP_Query('posts_per_page=3'); while ($blog_query->have_posts()) : $blog_query->the_post(); ?>
<div class="content" id="post-<?php the_ID(); ?>">
<h4><?php the_title(); ?></h4>
<?php the_excerpt(); ?>
</div>
<?php endwhile; ?>
<?php if ($blog_query->have_posts()) : ?>
<?php if(function_exists('wp_pagenavi'))
{
wp_pagenavi();
}
?>
<?php else: ?>
<h2>oooops!!!</h2>
<?php endif; ?>
</div>
</div>
</div>
<?PHP
get_footer();
?>
Are you sure you're not re-inventing the wheel a little here? Why not set the number of posts to display in the admin, then use WP's native paging for the blog?
Turns out you have to do something like this:
<?php $temp = $wp_query; $wp_query= null; ?>
<?php $wp_query = new WP_Query(array('posts_per_page' => 3, 'paged' => $paged)); while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="content" id="post-<?php the_ID(); ?>">
<h4><?php the_title(); ?></h4>
<?php the_excerpt(); ?>
</div>
<?php endwhile; ?>
<?php if(function_exists('wp_pagenavi'))
{
wp_pagenavi();
}
?>
<?php $wp_query = null; $wp_query = $temp; ?>

Resources