Showing only 5 post in wordpress - wordpress

HI I have edited and make a template page of responsive theme to make some thumbnails of the features pics of the posts.
ALl it's okay I can see them, but even if the posts are 9 I could see only 5. If I add one ony I see the new one, there is something like "show only latest 5 posts" but I can't understand WHERE!
get_header(); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php get_template_part( 'loop-header' ); ?>
<?php responsive_entry_before(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php responsive_entry_top(); ?>
<?php get_template_part( 'post-meta-page' ); ?>
<div class="post-entry">
<?php the_content(__('Read more ›', 'responsive')); ?>
<?php wp_link_pages(array('before' => '<div class="pagination">' . __('Pages:', 'responsive'), 'after' => '</div>')); ?>
</div><!-- end of .post-entry -->
(this is my added code)
<ul>
<?php
$posts = get_posts();
foreach($posts as $post) : setup_postdata($post);
?>
<li><div class="fotoBoxContent"><a class="fotoBox" href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); the_title(); ?></a></div></li>
<?php endforeach; ?>
</ul>
<?php responsive_entry_bottom(); ?>
</div><!-- end of #post-<?php the_ID(); ?> -->
<?php responsive_entry_after(); ?>
<?php responsive_comments_before(); ?>
<?php comments_template( '', true ); ?>
<?php responsive_comments_after(); ?>
<?php
endwhile;
get_template_part( 'loop-nav' );
else :
get_template_part( 'loop-no-posts' );
endif;
?>

Try adding query_posts( 'posts_per_page=NUMBER_GOES_HERE' ); immediately before the <?php while (have_posts()) : the_post(); ?>
Replacing NUMBER_GOES_HERE with the amount of posts you want displayed. Use -1 to show all posts
Also within Wordpress itself Settings->Reading has a field where you can set Blog pages show at most

I'm still not sure what exactly you want to achieve but if you just want to have thumbnails of posts that are in the main loop, then you do not need to do additional query.
All you need to do is something like this:
1.) Before <?php if (have_posts()) : ?> you initialize some variable:
$thumb_data='';
2.) After <?php if (have_posts()) : ?>
$thumb_data='<ul>';
3.) replace your "added code" with this:
$thumb_data.='<li><div class="fotoBoxContent"><a class="fotoBox" href="'.get_the_permalink().'">'.get_the_post_thumbnail()." ".get_the_title().'</a></div></li>';
4.) After the main while loop, add:
$thumb_data='</ul>';
5.) Mow all the HTML code for the list of thumbnails will be in $thumb_data, so just echo this variable in the template where you want the HTML code to appear.

Related

ACF Group field not displaying on the front end

I have created a group field in ACF to display on posts, pages and custom post type. Please see below screenshots.
And here's the code I'm trying for front-end.
<?php $footerCTA = get_field('footer_cta');
echo $footerCTA['title']; ?>
The code above doesn't output anything on the front-end. Am I missing here something?
Thanks.
try this:
if( have_rows('footer_cta') ):
while( have_rows('footer_cta') ) : the_row();
?>
<p><?php the_sub_field('title'); ?></p>
<?php
endwhile;
endif;
?>
Try using.
echo the_field('footer_cta');
Other Way.
You can do this by adding a second parameter to the get_field or the_field functions. This second parameter will contain the correct ID which can be found using get_option('page_for_posts') like so
<h1><?php the_field('footer_cta', get_option('page_for_posts')); ?></h1>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php if ( have_posts() ) : ?>
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</div><!-- #content -->
</div><!-- #primary -->

Wordpress custom loop pagination - always same content

I have one custom loop in a custom homepage in WordPress that is pulling 4 posts with some banners in middle. All is working fine, however pagination always shows same posts. Is there a way for me to add pagination to this custom loop?
My index.php code:
<?php
query_posts(array(
'post_type' => 'post',
'showposts' => 4,
) );
?>
<?php if (have_posts()) : ?>
<?php $count = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php $count++; ?>
<?php if ($count == 3) : ?>
<!-- banners -->
<h1> <?php the_title(); ?> </h1>
<?php the_content(); ?>
<?php else : ?>
<h1> <?php the_title(); ?> </h1>
<?php the_content(); ?>
<!-- banners -->
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
<p align="center"><?php posts_nav_link(); ?></p>
Inside your query_post array add this line:
'paged' => ( get_query_var('paged') ) ? get_query_var('paged') : 1,
and in settings -> reading set 4 posts per blog page.

Single post template not working in WordPress

page-webinars.php:
<?php
/*
Template Name: Webinars
*/
?>
<?php
$loop = new WP_Query(array('post_type' => array('webinars')));
if ($loop->have_posts()) :
while ($loop->have_posts()) : $loop->the_post();
?>
<?php get_template_part('loop-webinars'); ?>
<?php endwhile; ?>
<?php endif;
wp_reset_postdata(); ?>
loop-webinars.php:
<?php the_title(); ?>
single-webinars.php:
<h1><?php the_title(); ?></h1>
<div>
<?php
the_post();
the_content();
?>
</div>
Looks like everything's correct. Page displays necessary template, but single not working.
You forget to use WordPress loop.
Try with this code in your single-webinars.php file.
<?php
// Start the loop.
while ( have_posts() ) : the_post();
?>
<?php the_title('<h1>', '</h1>'); ?>
<div>
<?php the_content(); ?>
</div>
<?php // End of the loop.
endwhile;
?>
It had just to "reactivate" theme...

Wordpress blog isn't showing posts. Does adding a custom portfolio post field effect this?

Now I've done this a couple other times with no problem, I have a main page using home.php and the blog as another page using "blog-home.php" blog template with all the right code to grab the posts but it's not displaying. The only difference is I've added a custom portfolio post field to the functions, would this be effecting it or could it be something else? I can access a post from the home page under latest post putting the code below but that's it.
<?php query_posts("post_per_page=1"); the_post(); ?>
<p><?php the_excerpt(); ?></p>
<?php wp_reset_query(); ?></div>
*UPDATE: I've tried another code but now it is only displaying the blog page as a post. *
<?php
/*
Template Name: Blog Home
*/
?>
<?php get_header(); ?>
<div id="contentwrapper">
<?php query_posts( array ( 'category_name' => 'Blog', 'posts_per_page' => 5 ) ); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<div class="blogentry">
<h4><?php the_title(); ?> </h4>
<?php the_content(); ?>
<div class="postmetadata">
<?php the_tags('Tags: ', ', ', '<br />'); ?>
</div>
<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
</div>
</div>
<?php endwhile; ?>
<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
</div>
<?php get_footer(); ?>
Maybe if you use
$posts = get_posts(array('numberposts' => 1));
global $post;
$post = $posts[0];
the_excerpt();
instead
query_posts();
is never a good idea change the global query if get_posts dosn't work for you try with WP_Query()

How to loop through a specific category on single.php in Wordpress?

I've created a custom page and it is set as my homepage, within this custom page I am pulling out the latest post from a specific category, I've also created a form of pagination which when clicked upon will take the user to single.php. My intention for the single.php is to have two custom loops.
Custom loop one
I want single.php to distinguish that it has came from the homepage and loop through all of the posts tagged with the same category as the one on the homepage.
Some of these posts will have to be tagged with more than one category, so the loop will have to know to ignore the other categories and just pay attention to the category in question. Does that make sense?
Custom loop two
If the user hasn't arrived from the homepage, single.php will just act as it normally does i.e, if the user comes from index.php (the blog) they will be taken to this second loop (blog post)
However I don't seem to be able to make the distinction between the two loops, I might be over complicating matters, as I've got a loop which wraps everything together and then I have a loop for my custom pagination.
Here is the code below to show you what I'm talking about
custompage.php (set to home) - This works just fine but I'll post it just incase anyone is able to tidy it up
<?php query_posts('cat=1'); ?>
<?php
$myPosts = new WP_Query();
$myPosts->query('showposts=1');
if (have_posts()) :
while ($myPosts->have_posts()) : $myPosts->the_post();
?>
<script type="text/javascript">$.backstretch("<?php $key="image"; echo get_post_meta($post->ID, $key, true);?>");</script>
<div id="post-<?php the_ID(); ?>" class="info">
<h2><?php the_title(); ?></h2>
<ul class="nav">
<?php query_posts('posts_per_page=1&offset=1'); the_post(); ?>
<li class="prev">Previous</li>
<?php wp_reset_query(); ?>
<li class="next"></li>
</ul>
</div>
<!-- end .info -->
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
single.php - Currently broken
<?php if( in_category('1') ) { ?>
<!-- start -->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" class="info">
<script type="text/javascript">$.backstretch("<?php $key="image"; echo get_post_meta($post->ID, $key, true);?>");</script>
<h2><?php the_title(); ?></h2>
<ul class="nav">
<li class="prev"><?php previous_post_link('%link', ' ', 'true', '1') ?></li>
<li class="next"><?php next_post_link('%link', ' ', 'true', '1'); ?></li>
<!--li class="prev"><?php //previous_post_link('%link', '%title;', 'true', '1') ?></li>
<li class="next"><?php //next_post_link('%link', '%title;', 'true', '1'); ?></li-->
</ul>
</div>
<!-- end .info -->
<?php endwhile; else: ?>
<?php endif; ?>
<!-- end -->
<?php }else{ ?>
<div id="content" class="widecolumn" role="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<div class="entry">
<?php the_content('<p class="serif">Read the rest of this entry »</p>'); ?>
</div>
</div>
<?php comments_template(); ?>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
</div>
<?php } ?>
The problem I seem to be running into is when a post has been tagged with two categories, wordpress doesn't seem to be able to make the distinction between the two categories and instead of carrying on to the next category it breaks and defaults to the second loop.
how about this?
HOMEPAGE
<?php
$myPosts = new WP_Query();
$myPosts->query('showposts=1&cat=1');
if (have_posts()) :
while ($myPosts->have_posts()) : $myPosts->the_post();
?>
<script type="text/javascript">$.backstretch("<?php $key="image"; echo get_post_meta($post->ID, $key, true);?>");</script>
<div id="post-<?php the_ID(); ?>" class="info">
<h2><?php the_title(); ?></h2>
<ul class="nav">
<?php query_posts('posts_per_page=1&offset=1'); the_post(); ?>
<li class="prev">Previous</li>
<?php wp_reset_query(); ?> <-- not sure if this will reset the overall query
<li class="next"></li>
</ul>
</div>
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
the queryposts('cat=1') at the top of your query wont run with that category, the category would have to be set inside your custom query
$myPosts->query('showposts=1&cat=1');
the 2nd page (SINGLE.PHP) with 2 loops..
if the user is coming from the homepage to a single page you want to attach the current category to the query, without this wordpress (while on the singles page will default to loop through all posts)
so for the singles page would the below be any good?
<?php if( in_category('1') ) { ?>
<!-- your selected category -->
<!-- start -->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" class="info">
<script type="text/javascript">$.backstretch("<?php $key="image"; echo get_post_meta($post->ID, $key, true);?>");</script>
<h2><?php the_title(); ?></h2>
<ul>
<php global $post;
$my_query = get_posts('numberposts=1&cat=1&offset=-1');
foreach($my_query as $post) :
setup_postdata($post);
$link = get_post_meta($post->ID, 'site-url', true); ?>
<li>
<php the_title(); ?>
</li>
<php endforeach; ?>
<php global $post;
$my_other_query = get_posts('numberposts=1&cat=1&offset=1');
foreach($my_other_query as $post) :
setup_postdata($post);
$link = get_post_meta($post->ID, 'site-url', true); ?>
<li>
<php the_title(); ?>
</li>
<php endforeach; ?>
</ul>
</div>
<!-- end .info -->
<?php endwhile; else: ?>
<?php endif; ?>
<!-- end -->
<?php }else{
include('standard-wp-singles-page-stuff.php');
} ?>
then once your singles page loads it will check for the current category in that post, if its in category 1, then it will load your custom loop, then it will loop through 2 posts, in the same category? giving you 2 links to other posts. also using an offset on that query should give you a link forward and a link backwards?
hope that helps..
fixing code layout.. didnt work too well :P

Resources