WordPress Query Posts To Show All & Style Each One - wordpress

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(); ?>

Related

How to display ACF values in the front-page in index.php

Hi Guys my name is Fotis and i am a junior web developer.
The reason i need your help is because i am trying to create this gallery http://www.elliotcondon.com/creating-an-image-gallery-with-advanced-custom-fields/ and i am using custom fields and the add on repeater.
But i can’t see anything on my browser and in my home page.But when i create anotherpage template without beign declared as front page or page for posts it works fine. So the question is what should i include in my code to make this happen.?
Please anyone who know to help me
Thank you for reading my request!
<?php get_header(); ?>
<div id="content">
<div id="main">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; else: endif; ?>
<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?>
<?php endwhile; else: endif; ?>
<!-- Slider -->
<?php if(get_field('images')): ?>
<div id="slider">
<?php while(the_repeater_field('images')): ?>
<?php $image = wp_get_attachment_image_src(get_sub_field('image'), 'full'); ?>
<?php $thumb = wp_get_attachment_image_src(get_sub_field('image'), 'thumbnail'); ?>
<img src="<?php echo $image[0]; ?>" alt="<?php the_sub_field('title');?>" rel="<?php echo $thumb[0]; ?>" />
<?php endwhile; ?>
</div>
<?php endif; ?>
</div>
</div>

Custom Blog Post Listing in Genesis Sample Child Theme

I want to add several images and divs and also customize the look of my Blog post listing... But i can't find the way to do it.
Here's the Blog Template code
<?php
/*
WARNING: This file is part of the core Genesis framework. DO NOT edit
this file under any circumstances. Please do all modifications
in the form of a child theme.
*/
/**
* Template Name: Blog
* This file handles blog post listings within a page.
*
* This file is a core Genesis file and should not be edited.
*
* The blog page loop logic is located in lib/structure/loops.php
*
* #category Genesis
* #package Templates
* #author StudioPress
* #license http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
* #link http://www.studiopress.com/themes/genesis
*/
genesis();
and just above the genesis(); code.. i tried to put some divs and images there.. But i guess that's not the way it works. ..
I also tried to make my own Blog listing template using a normal wordpress code theme..
<?php /*
Template Name: List Post Pages
*/
?>
<?php get_header(); ?>
<?php if ( has_post_thumbnail() ) { ?>
<div class="featured">
<?php the_post_thumbnail(); ?>
</div>
<?php } ?>
<div class="divider"></div>
<div id="content" class="hfeed">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>">
<?php the_title(); ?>
</a></h2>
<div class="entry">
<?php the_content(); ?>
</div>
<div class="postmetadata">
<?php the_tags('Tags: ', ', ', '<br />'); ?>
Posted in
<?php the_category(', ') ?>
|
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
</div>
</div>
<?php endwhile; ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
<?php genesis_after_loop(); ?>
</div>
<?php get_footer(); ?>
But no luck, what's the right way to do this?
***Update -code below is the one i want.. but instead of having the Content of the page. I want the list of Post with excerpts ....How can i do that????
<?php /*
Template Name: Page Template
*/ ?>
<?php get_header(); ?>
<?php if ( has_post_thumbnail() ) { ?>
<div class="featured">
<?php the_post_thumbnail(); ?>
</div>
<?php } ?>
<div class="divider"></div>
<?php genesis_before_content_sidebar_wrap(); ?>
<div id="content-sidebar-wrap">
<?php genesis_before_content(); ?>
<div id="content" class="hfeed">
<?php genesis_before_loop(); ?>
<?php genesis_loop(); ?>
<?php genesis_after_loop(); ?>
</div>
<!-- end #content -->
<?php genesis_after_content(); ?>
</div>
<!-- end #content-sidebar-wrap -->
<?php genesis_after_content_sidebar_wrap(); ?>
<?php get_footer(); ?>
Im shocked that no one answered my question.. anyway, if someone bumps onto this post with similar problem. The answer is adding
<?php query_posts( $args ); ?>
just above the <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
All in all, my code looks like this ...
<?php /*
Template Name: Page Template
*/ ?>
<?php get_header(); ?>
<?php if ( has_post_thumbnail() ) { ?>
<div class="featured">
<?php the_post_thumbnail(); ?>
</div>
<?php } ?>
<div class="divider"></div>
<?php genesis_before_content_sidebar_wrap(); ?>
<div id="content-sidebar-wrap">
<?php genesis_before_content(); ?>
<div id="content" class="hfeed">
<?php genesis_before_loop(); ?>
<?php query_posts( $args ); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>">
<?php the_title(); ?>
</a></h2>
<div class="entry">
<?php the_content(); ?>
</div>
<div class="postmetadata">
<?php the_tags('Tags: ', ', ', '<br />'); ?>
Posted in
<?php the_category(', ') ?>
|
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
</div>
</div>
<?php endwhile; ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
<?php genesis_after_loop(); ?>
</div>
<!-- end #content -->
<?php genesis_after_content(); ?>
</div>
<!-- end #content-sidebar-wrap -->
<?php genesis_after_content_sidebar_wrap(); ?>
<?php get_footer(); ?>

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; ?>

Can't show / hide a part in WordPress with the normal loop

I tried the following. When there is content to show, show it + show H3 <h3>Overview</h3>, if not show noting.
But this will not work for me.
My code:
<?php
$heroimage = get_field('hero_image' );
$alt = $image['title' ];
?>
<?php if ($heroimage) : ?>
<div class="grid_12">
<img src="<?php echo $heroimage; ?>" alt="<?php echo $alt; ?>"/>
</div><!-- End div.grid_12 -->
<?php endif; ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article class="grid_8">
<h3>Overview</h3>
<?php the_content(); ?>
</article><!-- End article.grid_8 -->
<?php endwhile; ?>
The first part of the Hero image is to get the image from the plugin Advanced Custom Fields. The problem lies on the if have_posts etc..
Thanks for advance!
regarding to the codex, it should be
<?php
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<article class="grid_8">
<h3>Overview</h3>
<?php the_content(); ?>
</article><!-- End article.grid_8 -->
<?php endwhile;
endif;
?>
You forgot to close your if statement.

How can I have multiple loops on one page in Wordpress?

I am using a nice jquery slideshow plugin I found and trying to get it to work into my Wordpress template. I have tried the code below in various formats but I can't seem to get it the way I want.
The first part is where the title and content of the post reads into the slider, using a specific category. I have 3 of these sections:
<div class="details_wrapper">
<div class="details">
<div class="detail">
<?php query_posts('cat_ID=7&showposts=1');
if (have_posts()) : while (have_posts()) : the_post();?>
<h2 class="Lexia-Bold"><a href="<?php the_permalink() ?>">
<?php the_title() ?></a><?php the_excerpt(); ?></h2>
<?php endwhile; endif;
?>
</div><!-- /detail -->
<div class="detail">
<?php query_posts('cat_ID=8&showposts=1');
if (have_posts()) : while (have_posts()) : the_post();?>
<h2 class="Lexia-Bold"><a href="<?php the_permalink() ?>">
<?php the_title() ?></a><?php the_excerpt(); ?></h2>
<?php endwhile; endif;
?>
</div><!-- /detail -->
<div class="detail">
<?php query_posts('cat_ID=9&showposts=1');
if (have_posts()) : while (have_posts()) : the_post();?>
<h2 class="Lexia-Bold"><a href="<?php the_permalink() ?>">
<?php the_title() ?></a><?php the_excerpt(); ?></h2>
<?php endwhile; endif;
?>
</div><!-- /detail -->
</div><!-- /details -->
</div>
Now this actually works, but I just need it to post the title and excerpt from one of the posts from the category noted. I was reading that I may need to add the wp_reset_query(); line somewhere to destroy the previous loop's query, but I'm not sure.
Here's the second part of the code where the post's featured image is retrieved:
<div class="item item_1">
<?php query_posts('cat_ID=7&posts_per_page=1'); ?>
<?php the_post_thumbnail( 'single-post-thumbnail' ); ?>
</div><!-- /item -->
<div class="item item_2">
<?php query_posts('cat_ID=8&posts_per_page=1'); ?>
<?php the_post_thumbnail( 'single-post-thumbnail' ); ?>
</div><!-- /item -->
<div class="item item_3">
<?php query_posts('cat_ID=9&posts_per_page=1'); ?>
<?php the_post_thumbnail( 'single-post-thumbnail' ); ?>
</div>
Any help would be greatly appreciated :) Here's an example.
Have you tried using...
query_posts('cat_ID=9&posts_per_page=1');
Or I have used get_post before as while to get certain amount of post like so...
<?php
global $post;
$myposts = get_posts('posts_per_page=1&numberposts=-1&category=1');
foreach($myposts as $post) :
?>
<h6><?php the_title(); ?></h6>
<?php setup_postdata($post);?>
<?php the_excerpt(); ?>
<?php endforeach; ?>
</div>
If its just one post you want you wouldn't really need the foreach or while loop.
I used the method Tianbo84 suggested above both to query the posts AND the featured images from that post to finish the job :) Thanks Tianbo84! To my understanding, the get_posts and <?php endforeach; ?> lines were key... like opening a query and then closing it once the data was retrieved.

Resources