I have a loop - It is pulling all the posts from category id # 4. I want to upload the image but NOT insert it when i'm writing my post. How can i make it so that i can pull the images uploaded that i uploaded for each post since its in the loop?
<?php query_posts('cat=4'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<h3><?php the_content(); ?></h3>
<?php endwhile; endif; ?>
I found this link and the code was the answer:
http://www.wpbeginner.com/wp-themes/how-to-get-all-post-attachments-in-wordpress-except-for-featured-image/
Related
I'm having some real trouble with the below code in my taxonomy.php template in Wordpress. The query is working (i.e pulling posts only from within that custom taxonomy) but it is only displaying 2 posts (4 are in the taxonomy).
All my efforts to convert this into a standard loop using $args simply result in posts from all taxonomies being pulled into the page. I was hoping it is as simple as adding posts_per_page => -1 but this just causes every post in the entire site to display.
As I understand it from the codex, taxonomy pages should pull the relevent posts by default, without a need for a loop?
Any help much appreciated!
taxonomy.php
<?php get_header(); ?>
<main>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<figure>
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
} ?>
<figcaption>
<h4><?php the_title(); ?></h4>
<h5><?php the_excerpt(); ?></h5>
</figcaption>
</figure>
<?php endwhile; ?>
<?php endif; ?>
</main>
<?php get_footer(); ?>
UPDATE
<main>
<?php
$args = array(
'posts_per_page' => -1
);
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<figure>
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
} ?>
<figcaption>
<h4><?php the_title(); ?></h4>
<h5><?php the_excerpt(); ?></h5>
</figcaption>
</figure>
<?php endwhile; ?>
<?php endif; ?>
</main>
<?php get_footer(); ?>
If you have 6 different taxonomies then there will be 6 different template files to show those taxonomies appropriately. In your case your templates will be taxonomy-topics.php taxonomy-places.php taxonomy-dates.php taxonomy-interviewee.php taxonomy-period.php and taxonomy-a-z.php
In this way once these templates are created your templates will be showing appropriate posts. To achieve that you can use posts_per_page argument or you can visit this page for better understanding about fetching posts WP_Query Codex Page Hope that makes sense by now
I am making a products page and I want to let the user to upload the image and show it according to the design (the thumbnail is placed at top, then the title and then the description) how can I place it outside the_content(); function
Here's my code:
<section class="products">
<?php query_posts( 'posts_per_page=8' ); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<article class="products__item">
<div class="products__item--thumbnail">
</div>
<h2 class="products__item--title"><?php the_title(); ?></h2>
<p class="products__item--info"><?php the_content(); ?></p>
<h3 class="products__item--price">60.00</h3>
<span class="fa fa-search products__item-cart"></span>
test
</article>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
</section>
Regards!
if you are using featured image and need to display it, place the code bellow where you need the image ( this should be within the loop )
<?php the_post_thumbnail(); ?>
or if you need to get the featured image's link, and display it as a img tag, you can use this code to get the src link of featured image
<?php $image = get_the_post_thumbnail();
Hope this answer helped you any sort
Last time I checked I knew how to write a loop to display all my posts.....How ever when I wrote this:
if (have_posts()){
while (have_posts()): the_post();
?>
<div clas="span6">
<h3><?php echo the_title(); ?></h3>
<p><?php echo the_excerpt(); ?></p>
</div>
<?php
endwhile;
}
I ran into an issue:
If I have the following posts:
Post1, Post2, Post3
Posts 1 - 2 will show up in a list, its only until I write a new post (Post 4) and publish it that post 3 will show up in that list.
So whats wrong with my loop?
never had this issue before.
Note: WordPress 3.5 is being used.
I have checked WordPress Docs to make sure I am doing things right and as far as I know I am.
I see a couple things that could be causing your problems. First, you have a set of { } that are not needed. Your open to the loop should be:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
Instead of:
<?php if (have_posts()){ while (have_posts()): the_post(); ?>
See the curly brackets in your loop?
Then as McNab said, just fix your div class by adding the "s" and remove the echo from content pullers.
You also need to to include an endif; after your endwhile;.
So your full loop should loop like this:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="span6">
<h3><?php the_title(); ?></h3>
<p><?php the_excerpt(); ?></p>
</div>
<?php endwhile; endif; ?>
I think this should correct your problem.
You can use it like below. This is mainly used in wordpress.
if (have_posts()) : // your code if (have_posts()){
while (have_posts()): the_post();
?>
<div clas="span6">
<h3><?php echo the_title(); ?></h3>
<p><?php echo the_excerpt(); ?></p>
</div>
<?php
endwhile;
endif; //your code here }
Hope it may work.
I want to get the Post title, image and excerpt of the specific WordPress category. I am using the below code to get the post titles of the specific category.
global $post;
$myposts = get_posts('numberposts=5&category_name=Cooling Towers');
foreach($myposts as $post) :
?>
<li><?php the_title(); ?></li>
<?php endforeach; ?>
Any ideas, how do I get post image as well as excerpt for the specific WordPress category?
You can use this
<?php
query_posts( array('posts_per_page'=>5, 'category_name'=>'Cooling Towers') );
while ( have_posts() ) : the_post();
?>
<h2><?php the_title(); ?></h2>
<?php if ( has_post_thumbnail() ): // check for the featured image ?>
<?php the_post_thumbnail(); ?> <!--echo the featured image-->
<?php
endif;
the_excerpt(); // echo the excerpt
endwhile;
wp_reset_query(); // resets main query
?>
I am using the following code to query posts for categories:
<?php query_posts("cat=8"); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<article>
<h4><?php the_title(); ?> </h4>
<p><?php the_content(); ?></p>
</article>
<?php endwhile; ?>
It seems to work fine, until I did it a third time(three instances of the code above) on a single page. Now the page seems to load forever and it breaks as if it is compiling more then 1 page template. I should mention that all works fine unless I publish a post to the third category
Has anyone had a problem like this, or know why it happens?
Is this bad practise for querying posts?
Use WP_query instead so you can make use of the wp_reset_postdata which should clear up the issue.
<?php
$the_query = new WP_Query( 'cat=8' );
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
<article>
<h4><?php the_title(); ?> </h4>
<p><?php the_content(); ?></p>
</article>
<?php
endwhile;
wp_reset_postdata();
?>