I have this custom template in Wordpress which includes a script that paginates ACF fields. Here is the source code:
<?php get_header(); ?>
<div class="container">
<div class="row">
<div class="col-xs-12">
<h1 class="pagetitle"><?php the_title(); ?></h1>
</div> <!-- col -->
</div> <!-- row -->
</div> <!-- container -->
<?php
if( get_query_var('page') ) {
$page = get_query_var( 'page' );
} else {
$page = 1;
}
$row = 0;
$files_per_page = 30; // How many images to display on each page
$files = get_field( 'fisier' );
$total = count( $files );
$pages = ceil( $total / $files_per_page );
$min = ( ( $page * $files_per_page ) - $files_per_page ) + 1;
$max = ( $min + $files_per_page ) - 1;
?>
<div class="container">
<div class="row">
<div class="col-md-8">
<section id="content">
<div class="wrapper">
<?php while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php if( have_rows('fisier') ): ?>
<div class="article-files">
<h4>Files</h4>
<div class="row">
<?php while ( have_rows('fisier') ) : the_row();
$row++;
if($row < $min) { continue; }
if($row > $max) { break; }
?>
<div class="col-xs-12 file">
<?php $x = 0; ?>
<?php $file = get_sub_field('link'); if( $file ): ?>
<i class="fa fa-angle-right" aria-hidden="true"></i> <?php the_sub_field('nume_fisier'); ?>
<div class="file-description"><?php the_sub_field('descriere'); ?></div>
<?php $x = 1; ?>
<?php endif; ?>
<?php $file = get_sub_field('fisier_intern'); if( $file ): ?>
<i class="fa fa-angle-right" aria-hidden="true"></i> <?php the_sub_field('nume_fisier'); ?>
<div class="file-description"><?php the_sub_field('descriere'); ?></div>
<?php $x = 1; ?>
<?php endif; ?>
<?php if( $x == 0 ): ?>
<i class="fa fa-angle-right" aria-hidden="true"></i> <?php the_sub_field('nume_fisier'); ?>
<div class="file-description"><?php the_sub_field('descriere'); ?></div>
<?php $x = 1; ?>
<?php endif; ?>
</div>
<?php endwhile; ?>
</div>
<div class="file-pagination">
<?php
echo paginate_links( array(
'base' => get_permalink() . '%#%' . '/',
'format' => '?page=%#%',
'current' => $page,
'show_all' => false,
'prev_text' => __('«'),
'next_text' => __('»'),
'total' => $pages
));
?>
</div> <!-- file-pagination -->
</div>
<?php endif; ?>
</div> <!-- wrapper -->
</section> <!-- content -->
</div> <!-- col -->
<div class="col-md-4">
<aside id="sidebar">
<?php get_sidebar(); ?>
</aside> <!-- aside -->
</div> <!-- col -->
</div> <!-- row -->
</div> <!-- container -->
<?php get_footer(); ?>
The code above doesn't display the pagination links but if I remove this part:
<?php while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
Everything works perfectly. Any idea about how I can fix this?
Thanks
Solved the problem! I had to move the pagination settings after the_content() as shown below:
<?php get_header(); ?>
<div class="container">
<div class="row">
<div class="col-xs-12">
<h1 class="pagetitle"><?php the_title(); ?></h1>
</div> <!-- col -->
</div> <!-- row -->
</div> <!-- container -->
<div class="container">
<div class="row">
<div class="col-md-8">
<section id="content">
<div class="wrapper">
<?php while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php
if( get_query_var('page') ) {
$page = get_query_var( 'page' );
} else {
$page = 1;
}
$row = 0;
$files_per_page = 30; // How many images to display on each page
$files = get_field( 'fisier' );
$total = count( $files );
$pages = ceil( $total / $files_per_page );
$min = ( ( $page * $files_per_page ) - $files_per_page ) + 1;
$max = ( $min + $files_per_page ) - 1;
?>
<?php if( have_rows('fisier') ): ?>
<div class="article-files">
<h4>Files</h4>
<div class="row">
<?php while ( have_rows('fisier') ) : the_row();
$row++;
if($row < $min) { continue; }
if($row > $max) { break; }
?>
<div class="col-xs-12 file">
<?php $x = 0; ?>
<?php $file = get_sub_field('link'); if( $file ): ?>
<i class="fa fa-angle-right" aria-hidden="true"></i> <?php the_sub_field('nume_fisier'); ?>
<div class="file-description"><?php the_sub_field('descriere'); ?></div>
<?php $x = 1; ?>
<?php endif; ?>
<?php $file = get_sub_field('fisier_intern'); if( $file ): ?>
<i class="fa fa-angle-right" aria-hidden="true"></i> <?php the_sub_field('nume_fisier'); ?>
<div class="file-description"><?php the_sub_field('descriere'); ?></div>
<?php $x = 1; ?>
<?php endif; ?>
<?php if( $x == 0 ): ?>
<i class="fa fa-angle-right" aria-hidden="true"></i> <?php the_sub_field('nume_fisier'); ?>
<div class="file-description"><?php the_sub_field('descriere'); ?></div>
<?php $x = 1; ?>
<?php endif; ?>
</div>
<?php endwhile; ?>
</div>
<div class="file-pagination">
<?php
echo paginate_links( array(
'base' => get_permalink() . '%#%' . '/',
'format' => '?page=%#%',
'current' => $page,
'show_all' => false,
'prev_text' => __('«'),
'next_text' => __('»'),
'total' => $pages
));
?>
</div> <!-- file-pagination -->
</div>
<?php endif; ?>
</div> <!-- wrapper -->
</section> <!-- content -->
</div> <!-- col -->
<div class="col-md-4">
<aside id="sidebar">
<?php get_sidebar(); ?>
</aside> <!-- aside -->
</div> <!-- col -->
</div> <!-- row -->
</div> <!-- container -->
<?php get_footer(); ?>
Related
i'm trying to auto load all my post in single.php i have tried several plugins but neither works
what's might be the problem i have also tried several nav-menu but i can't find what the problem is
i have the same problem in this question
https://wordpress.stackexchange.com/questions/102604/enable-infinite-scroll-on-single-php
this is my single page
<?php
/**
* The template for displaying all single posts
*
* #link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
*
* #package NewsCard
*/
get_header();
newscard_layout_primary(); ?>
<main id="main" class="site-main">
<?php
while ( have_posts() ) :
the_post();
get_template_part( 'template-parts/content', get_post_type() );
the_post_navigation();
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile; // End of the loop.
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
do_action('newscard_sidebar');
if ( $newscard_settings['newscard_footer_featured_posts_hide'] === 0 ) {
$footer_newscard_cat = absint($newscard_settings['newscard_footer_featured_post_categories']);
$footer_post_type = array(
'posts_per_page' => 4,
'post__not_in' => get_option('sticky_posts'),
'post_type' => array(
'post'
),
);
if ( $newscard_settings['newscard_footer_featured_latest_post'] == 'category' ) {
$footer_post_type['category__in'] = $footer_newscard_cat;
}
$footer_newscard_get_featured_post = new WP_Query($footer_post_type); ?>
<div class="container">
<section class="featured-stories">
<h2 class="stories-title"><?php echo esc_html($newscard_settings['newscard_footer_featured_posts_title']); ?></h2>
<div class="row gutter-parent-14">
<?php while ($footer_newscard_get_featured_post->have_posts()) {
$footer_newscard_get_featured_post->the_post(); ?>
<div class="col-sm-6 col-lg-3">
<div class="post-boxed">
<?php if ( has_post_thumbnail() ) { ?>
<div class="post-img-wrap">
<div class="featured-post-img">
</div>
<div class="entry-meta category-meta">
<div class="cat-links"><?php the_category(' '); ?></div>
</div><!-- .entry-meta -->
</div><!-- .post-img-wrap -->
<?php } ?>
<div class="post-content">
<?php if ( !has_post_thumbnail() ) { ?>
<div class="entry-meta category-meta">
<div class="cat-links"><?php the_category(' '); ?></div>
</div><!-- .entry-meta -->
<?php } ?>
<?php the_title( '<h3 class="entry-title">', '</h3>' ); ?>
<?php if ( 'post' === get_post_type() ) { ?>
<div class="entry-meta">
<?php newscard_posted_on(); ?>
</div>
<?php } ?>
</div><!-- .post-content -->
</div><!-- .post-boxed -->
</div><!-- .col-sm-6 .col-lg-3 -->
<?php }
// Reset Post Data
wp_reset_postdata(); ?>
</div><!-- .row -->
</section><!-- .featured-stories -->
</div><!-- .container -->
<?php }
get_footer();
?>
Can someone take a look on my code ? I can't figure why post pagination not showing, although when I type page/2 in browser url, the list of post works properly.
<?php
/**
* Template Name: Frontpage
*
* #package Bootstrap Canvas WP
* #since Bootstrap Canvas WP 1.0
*/
get_header(); ?>
<?php
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$args = array('post_type' => 'post', 'orderby' => 'ASC', 'paged' => $paged, 'posts_per_page' => 9 );
$loop = new WP_Query($args);
$count = 0;
?>
<div class="row">
<div class="col-sm-12 blog-main pt-3 pb-5">
<?php if ($loop->have_posts()) : while ($loop->have_posts()) : $loop->the_post(); ?>
<?php $count++ ?>
<?php $date_format = get_option( 'date_format' ); ?>
<?php if($count == 1) : ?>
<div class="row">
<?php endif ?>
<?php if(($count == 1) || ($count == 9)) : ?>
<div id="post-<?php the_ID(); ?>" class="col-sm-12 col-md-8 col-xl-8 np-big">
<?php endif ?>
<?php if($count == 2 || $count == 7) : ?>
<div class="col-sm-12 col-md-4 col-xl-4 np-small">
<?php endif ?>
<?php if($count > 1 && $count < 4 || $count > 6 && $count <= 9 ) : ?>
<div id="post-<?php the_ID(); ?>" class="col-sm-12 col-md-12 col-xl-12">
<?php elseif ($count >= 4) : ?>
<?php if ($count == 5) : ?>
<div id="post-<?php the_ID(); ?>" class="col-sm-12 col-md-4 col-xl-4 np-small">
<?php else : ?>
<div id="post-<?php the_ID(); ?>" class="col-sm-12 col-md-4 col-xl-4">
<?php endif ?>
<?php endif ?>
<a href="<?php echo get_the_permalink(); ?>"><div class="post-bg-home" style="background: linear-gradient( rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.7) ), url(<?php echo get_the_post_thumbnail_url() ?>);">
<h2><?php echo get_the_title(); ?></h2>
<p class="data"><?php echo the_time( $date_format ); ?></p>
</div></a>
<?php if($count == 1) : ?>
</div>
<?php endif ?>
<?php if($count > 1 ) : ?>
</div>
<?php endif ?>
<?php if($count == 3 || $count == 8) : ?>
</div>
<?php endif ?>
<?php endwhile; ?>
</div>
</div>
<div class="paginacja col-sm-12 col-md-12 col-xl-12">
<hr class="paginacja-hr">
<?php the_posts_pagination(); ?>
</div>
<?php else : ?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1>Not Found</h1>
</div>
<?php endif; ?>
</div><!-- /.blog-main -->
</div><!-- /.row -->
<?php get_footer(); ?>
Try this code
<?php
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$args = array('post_type' => 'post', 'orderby' => 'ASC', 'paged' => $paged, 'posts_per_page' => 3 );
$loop = new WP_Query($args);
$count = 0;
?>
<div class="row">
<div class="col-sm-12 blog-main pt-3 pb-5">
<?php if ($loop->have_posts()) : while ($loop->have_posts()) : $loop->the_post(); ?>
<?php $count++ ?>
<?php $date_format = get_option( 'date_format' ); ?>
<?php if($count == 1) : ?>
<div class="row">
<?php endif ?>
<?php if(($count == 1) || ($count == 9)) : ?>
<div id="post-<?php the_ID(); ?>" class="col-sm-12 col-md-8 col-xl-8 np-big">
<?php endif ?>
<?php if($count == 2 || $count == 7) : ?>
<div class="col-sm-12 col-md-4 col-xl-4 np-small">
<?php endif ?>
<?php if($count > 1 && $count < 4 || $count > 6 && $count <= 9 ) : ?>
<div id="post-<?php the_ID(); ?>" class="col-sm-12 col-md-12 col-xl-12">
<?php elseif ($count >= 4) : ?>
<?php if ($count == 5) : ?>
<div id="post-<?php the_ID(); ?>" class="col-sm-12 col-md-4 col-xl-4 np-small">
<?php else : ?>
<div id="post-<?php the_ID(); ?>" class="col-sm-12 col-md-4 col-xl-4">
<?php endif ?>
<?php endif ?>
<a href="<?php echo get_the_permalink(); ?>"><div class="post-bg-home" style="background: linear-gradient( rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.7) ), url(<?php echo get_the_post_thumbnail_url() ?>);">
<h2><?php echo get_the_title(); ?></h2>
<p class="data"><?php echo the_time( $date_format ); ?></p>
</div></a>
<?php if($count == 1) : ?>
</div>
<?php endif ?>
<?php if($count > 1 ) : ?>
</div>
<?php endif ?>
<?php if($count == 3 || $count == 8) : ?>
</div>
<?php endif ?>
<?php endwhile; ?>
</div>
</div>
<div class="paginacja col-sm-12 col-md-12 col-xl-12">
<hr class="paginacja-hr">
<?php $GLOBALS['wp_query']->max_num_pages = $loop->max_num_pages;
the_posts_pagination( array(
'mid_size' => 1,
'prev_text' => __( 'Back', 'green' ),
'next_text' => __( 'Next', 'green' ),
'screen_reader_text' => __( 'Posts navigation' )
) ); ?>
</div>
<?php else : ?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1>Not Found</h1>
</div>
<?php endif; ?>
</div><!-- /.blog-main -->
</div><!-- /.row -->
<?php get_footer(); ?>
i'm trying to change my single-post template ,But i can't the the_content Function.
Where should it be ?
<div class="single-post-content clearfix">
<?php
the_content(esc_html__('Read more!', 'voyager'));
wp_link_pages(array('before' => '<div class="page-link">' . esc_html__('Pages', 'voyager') . ': ', 'after' => '</div>'));
?>
</div>
Update 1 the entire code
<?php
/**
* The template for displaying all single posts and attachments
*/
get_header();
$pf = get_post_format();
$voyager_single_post_sidebar_under = cstheme_option( 'single_post_sidebar_under' );
$single_post_sidebar = cstheme_option( 'single_post_sidebar' );
$single_post_sidebar_position = '';
if( $single_post_sidebar == 'left-sidebar' ) {
$single_post_sidebar_position = 'pull-right';
}
/* ADD 1 view for this post */
$post_views = (get_post_meta(get_the_ID(), "post_views", true) > 0 ? get_post_meta(get_the_ID(), "post_views", true) : "0");
update_post_meta(get_the_ID(), "post_views", (int)$post_views + 1);
$single_post_featured_img = cstheme_option( 'single_post_featured_img' );
$featured_image_url = wp_get_attachment_url(get_post_thumbnail_id());
?>
<div class="container">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="blog-single-wrap" class="<?php echo 'format-' . $pf . ' featured_img_' . $single_post_featured_img ?> clearfix">
<?php if( isset( $single_post_featured_img ) && $single_post_featured_img == 'fullwidth' ) { ?>
<div class="single_post_header">
<div class="featured_img_bg" style="background-image:url(<?php echo $featured_image_url; ?>);"></div>
<div class="single_post_meta_category"><?php the_category(', '); ?></div>
<h2 class="single-post-title"><?php the_title(); ?></h2>
<div class="single_post_header_bottom">
<div class="single_post_meta">
<span class="post-meta-date"><?php the_time('M j, Y') ?></span>
<span class="post_meta_views"><i class="fa fa-eye"></i> <span><?php echo (get_post_meta(get_the_ID(), "post_views", true) > 0 ? get_post_meta(get_the_ID(), "post_views", true) : "0"); ?></span></span>
<span class="post-meta-likes"><?php echo cstheme_likes(); ?></span>
<span class="post-meta-comments"><i class="fa fa-comments"></i><?php echo get_comments_number(get_the_ID()); ?></span>
</div>
</div>
</div>
<?php if ( $single_post_sidebar != 'no-sidebar' && $voyager_single_post_sidebar_under != 'next' && ( $pf != 'image' && $pf != 'standard' ) ) { ?>
<div class="post_format_content mb55 text-center">
<?php get_template_part( 'framework/post-format/post', get_post_format() ); ?>
</div>
<?php } ?>
<?php } else { ?>
<div class="single_post_header">
<div class="single_post_meta_category"><?php the_category(', '); ?></div>
<h2 class="single-post-title"><?php the_title(); ?></h2>
<div class="row single_post_header_bottom">
<div class="col-md-4 text-left">
<div class="single_post_meta_author"><?php echo esc_html__('posted by', 'voyager') ?> <a class="heading_font" href="<?php echo esc_url( get_author_posts_url(get_the_author_meta('ID')) ); ?>"><?php echo get_the_author_meta('display_name') ?></a></div>
</div>
<div class="col-md-4">
<div class="single_post_meta">
<span class="post-meta-date"><?php the_time('M j, Y') ?></span>
<span class="post_meta_views"><i class="fa fa-eye"></i> <span><?php echo (get_post_meta(get_the_ID(), "post_views", true) > 0 ? get_post_meta(get_the_ID(), "post_views", true) : "0"); ?></span></span>
<span class="post-meta-likes"><?php echo cstheme_likes(); ?></span>
<span class="post-meta-comments"><i class="fa fa-comments"></i><?php echo get_comments_number(get_the_ID()); ?></span>
</div>
</div>
<div class="col-md-4 text-right">
<?php if(cstheme_option('single_post_sharebox') != 0) { get_template_part( 'templates/blog/sharebox' ); } ?>
</div>
</div>
</div>
<?php if ( $voyager_single_post_sidebar_under != 'next' ) { ?>
<div class="post_format_content mb55 text-center">
<?php get_template_part( 'framework/post-format/post', get_post_format() ); ?>
</div>
<?php } ?>
<?php } ?>
<?php if( $single_post_sidebar != 'no-sidebar' ) { ?>
<div class="row">
<div class="col-md-9 <?php echo $single_post_sidebar_position; ?>">
<?php } ?>
<?php if( isset( $single_post_featured_img ) && ( $single_post_featured_img == 'fullwidth' ) && ( $pf != 'image' && $pf != 'standard' ) && $voyager_single_post_sidebar_under != 'under' ) { ?>
<div class="post_format_content mb55 text-center">
<?php get_template_part( 'framework/post-format/post', $pf ); ?>
</div>
<?php } else if ( $single_post_featured_img != 'fullwidth' && $voyager_single_post_sidebar_under != 'under' ) { ?>
<div class="post_format_content mb55 text-center">
<?php get_template_part( 'framework/post-format/post', get_post_format() ); ?>
</div>
<?php } ?>
<div class="single-post-content clearfix">
<?php
the_content(esc_html__('Read more!', 'voyager'));
wp_link_pages(array('before' => '<div class="page-link">' . esc_html__('Pages', 'voyager') . ': ', 'after' => '</div>'));
?>
</div>
<div class="posts_nav_link"><?php posts_nav_link(); ?></div>
<div class="single_sharebox_wrap clearfix">
<div class="single_post_meta_tags pull-left">
<?php if( has_tag() ) {
the_tags('','', '');
} ?>
</div>
<div class="pull-right">
<?php if(cstheme_option('single_post_sharebox') != 0) { get_template_part( 'templates/blog/sharebox' ); } ?>
</div>
</div>
<?php if(cstheme_option('single_post_authorinfo') != 0) { get_template_part( 'templates/blog/authorinfo' ); } ?>
<?php if(cstheme_option('single_post_navigation') != 0) { ?>
<div class="single_post_nav clearfix">
<?php
$prev_post = get_adjacent_post(false, '', true);
$next_post = get_adjacent_post(false, '', false);
if($prev_post){
$post_url = get_permalink($prev_post->ID);
echo '<div class="pull-left"><p class="heading_font"><i class="fa fa-chevron-left"></i>' . esc_html__('Previous','voyager') . '</p><b>' . $prev_post->post_title . '</b></div>';
}
if($next_post) {
$post_url = get_permalink($next_post->ID);
echo '<div class="pull-right text-right"><p class="heading_font">' . esc_html__('Next','voyager') . '<i class="fa fa-chevron-right"></i></p><b>' . $next_post->post_title . '</b></div>';
}
?>
</div>
<?php } ?>
<?php if( $single_post_sidebar != 'no-sidebar' ) { ?>
</div>
<div class="col-md-3">
<?php get_sidebar(); ?>
</div>
</div>
<?php } ?>
<?php if(cstheme_option('single_post_relatedposts') != 0) { get_template_part('templates/blog/related-posts'); } ?>
<?php
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
?>
</div>
<?php endwhile; endif; ?>
</div>
<?php get_footer(); ?>
The page is enter link description here
I'm trying to achieve a 3x3 grid view of all the WordPress posts on the "blog" page (index.php). I'm building the site based on Bootstrap 3.
Therefore the loop has to create the columns and rows with PHP.
I'd like to have it set up in rows, so that potential height differences are being reset every row. The bootstrap grid would look like this:
<div class="row">
<div class="col-sm-4">content</div>
<div class="col-sm-4">content</div>
<div class="col-sm-4">content</div>
</div>
<div class="row">
<div class="col-sm-4">content</div>
<div class="col-sm-4">content</div>
<div class="col-sm-4">content</div>
</div>
<div class="row">
<div class="col-sm-4">content</div>
<div class="col-sm-4">content</div>
<div class="col-sm-4">content</div>
</div>
Lacking the PHP skills for setting up the loop properly, I tried hacking my way around, coming up with 3 times this (modifying the offsets):
<?php query_posts('posts_per_page=1&offset=0'); while (have_posts()) : the_post(); ?>
<div class="row">
<div class="col-sm-4 blog-post thumb">
<?php get_template_part('templates/content', get_post_format()); ?>
</div>
<?php endwhile; ?>
<?php query_posts('posts_per_page=1&offset=1'); while (have_posts()) : the_post(); ?>
<div class="col-sm-4 blog-post thumb">
<?php get_template_part('templates/content', get_post_format()); ?>
</div>
<?php endwhile; ?>
<?php query_posts('posts_per_page=1&offset=2'); while (have_posts()) : the_post(); ?>
<div class="col-sm-4 blog-post thumb">
<?php get_template_part('templates/content', get_post_format()); ?>
</div>
</div>
<?php endwhile; ?>
It has obvious disadvantages:
a lot of unnecessary PHP requests/loops
filtering by categories, tags, etc doesn't work
Could you help me out with creating the PHP loop?
The most related question I found is this, but the column layout is somehow skewed!
Thanks a lot! Philipp
The easiest would be to use one container and put all the contetn items in it, then equal their height via js like that.
PHP
<?php query_posts('posts_per_page=9');while (have_posts()) : the_post();?>
<div class="col-sm-4 blog-post thumb">
<?php get_template_part('templates/content', get_post_format()); ?>
</div>
<?php endwhile?>
JS:
function equalHeight(group) {
tallest = 0;
group.each(function() {
thisHeight = $(this).height();
if(thisHeight > tallest) {
tallest = thisHeight;
}
});
group.each(function() { $(this).height(tallest); });
}
$(document).ready(function() {
equalHeight($(".thumb"));
});
If thats no option, you could do sth. like that:
PHP
<div class="row">
<?php
$count=0;
query_posts('posts_per_page=9');
while (have_posts()) : the_post();
?>
<div class="col-sm-4 blog-post thumb">
<?php get_template_part('templates/content', get_post_format()); ?>
</div>
<?php
$count++;
if($count == 3 || $count == 6 ) echo '</div><div class="row">';
endwhile;
?>
</div>
Every three post objects must be contained within a row. So it will be like <div class="row"> <!-- post - post - post -> </div> <div class="row"> <!-- post - post - post -> </div>
If you would like to do this in php, and still maintain proper 'rowage' your code could look something like this:`
<div class="container">
<?php
$countturtle = 0 ;
$countbang = 0 ;
$count_posts = wp_count_posts( 'portobello' )->publish;
$args = array( 'post_type' => 'portobello', 'posts_per_page' => 32 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php $countbang++ ?>
<?php if ( $countbang >= 2 ) {
$countturtle = $countturtle + 1 ; } ?>
<?php if ( $countbang == 1 ) {
echo '<div class="row first-training">'; } elseif ( ( $countturtle % 3 ) == 0 ) {
echo '<div class="row">'; } ; ?>
<div id="post-<?php the_ID(); ?>" class="training-block <?php echo $countbang; ?>-block-training col-sm-4" >
<header class="entry-header training-header">
<h1 class="entry-title train">
<?php the_title(); ?>
</h1>
</header><!-- .entry-header -->
<div class="entry-imogin">
ddd
</div><!-- .entry-imogin -->
</div><!-- #post -->
<?php if ( $countbang % 3 == 0 ) {
echo '</div>'; }
elseif ( $countposts == $countbang ) { echo '</div>';} ; ?>
<?php endwhile; ?>
</div>
Here a solution for 3 columns
layout :
1 | 2 | 3
4 | 5 | 6
7 | 8 | 9
...
<div class="row">
<div class="col-sm-4">
<?php $i = 1 ?>
<?php $posts = get_posts(array(
'post_type' => 'news',
'posts_per_page' => -1
));
foreach ($posts as $post) : start_wp(); ?>
<?php if ($i == 1): ?>
<h2><?php the_title(); ?></h2>
<?php endif; ?>
<?php if($i == 3){$i = 1;} else {$i++;} ?>
<?php endforeach; ?>
</div>
<div class="col-sm-4">
<?php $i = 1 ?>
<?php $posts = get_posts(array(
'post_type' => 'news',
'posts_per_page' => -1
));
foreach ($posts as $post) : start_wp(); ?>
<?php if ($i == 2): ?>
<h2><?php the_title(); ?></h2>
<?php endif; ?>
<?php if($i == 3){$i = 1;} else {$i++;} ?>
<?php endforeach; ?>
</div>
<div class="col-sm-4">
<?php $i = 1 ?>
<?php $posts = get_posts(array(
'post_type' => 'news',
'posts_per_page' => -1
));
foreach ($posts as $post) : start_wp(); ?>
<?php if ($i == 3): ?>
<h2><?php the_title(); ?></h2>
<?php endif; ?>
<?php if($i == 3){$i = 1;} else {$i++;} ?>
<?php endforeach; ?>
</div>
</div>
I have an archive page that's set up to display category specific posts. However, instead of showing only the posts from a given category on the category page, it's showing all posts. For an example, see here.
Here's the code I'm using on my archive.php page. I know it's improper use of the loop, but I'm not sure how to fix it. Thanks for the help.
<?php get_header(); ?>
<div id="content">
<div id="inner-content" class="wrap clearfix">
<h1 class="blogTitle" style="margin:10px 0 3px 0;">Blog Title</h1>
<nav class="blogNav" role="navigation">
<?php bones_blog_nav(); // Adjust using Menus in Wordpress Admin ?>
</nav>
<div id="main" class="eightcol first clearfix" role="main">
<div class="catwhiteBg">
<?php if (is_category()) { ?>
<h1 class="catTitle">
<span><?php _e("", "bonestheme"); ?></span> <?php single_cat_title(); ?>
</h1>
<?php echo category_description( $category_id ); ?>
<?php } elseif (is_author()) { ?>
<div class="authorTop">
<?php
$curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
?>
<div class="author-pic"><?php echo get_avatar( $curauth->user_email, '80' ); ?></div>
<div class="author-name"><span style="font-weight: 200; color: #575757;">POSTS BY:</span>
<?php echo $curauth->first_name; ?> <?php echo $curauth->last_name; ?>
</div>
<div class="author-bio"><?php echo $curauth->description; ?></div>
<div class="author-twitter"><span>twitter</span></div>
</div>
<?php } elseif (is_day()) { ?>
<h1 class="archive-title h2">
<span><?php _e("Daily Archives:", "bonestheme"); ?></span> <?php the_time('l, F j, Y'); ?>
</h1>
<?php } elseif (is_month()) { ?>
<h1 class="archive-title h2">
<span><?php _e("Monthly Archives:", "bonestheme"); ?></span> <?php the_time('F Y'); ?>
</h1>
<?php } elseif (is_year()) { ?>
<h1 class="archive-title h2">
<span><?php _e("Yearly Archives:", "bonestheme"); ?></span> <?php the_time('Y'); ?>
</h1>
<?php } ?>
</div>
<div class="psts">
<?php
global $wp_query;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} elseif ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}
query_posts(array('posts_per_page' => '8','paged'=>$paged));
?>
<?php
$count = 1;
while (have_posts()) : the_post(); ?>
<div class="sixcol small pst<?php if ((isset($count)) && ($count % 2 == 0 )) { echo ' last';} // same logic to add class of last to last item in row of two ?>" id="post-<?php the_ID(); ?>">
<article id="post-<?php the_ID(); ?>" role="article">
<div class="thumb-wrapper mobile">
<?php if(has_post_thumbnail()) { $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'post-thumb' ); echo '<img src="' . $image_src[0] . '" width="100%" class="post-thumb" />'; } ?>
<header class="post-thumb-header">
<h2 class="post-title"><?php the_title(); ?></h2>
</header> <!-- end article header -->
<p class="meta"><?php the_category(', '); ?></p>
</div>
<section class="mobile-content">
<?php the_excerpt(); ?>
</section>
</article> <!-- end article -->
</div>
<?php $count++; ?>
<?php endwhile; ?>
<nav class="wp-prev-next">
<?php echo rb_pagination(); ?>
</nav>
</div> <!-- end .psts -->
</div> <!-- end #main -->
<?php get_sidebar(); // sidebar 1 ?>
</div> <!-- end #inner-content -->
</div> <!-- end #content -->
<?php get_footer(); ?>
I think you're overriding the original query with this line:
query_posts(array('posts_per_page' => '8','paged'=>$paged));
Can you swap this line with this, and let me know the results?
global $query_string;
query_posts( $query_string . "&posts_per_page=8&paged=$paged" );
if that fails try this:
query_posts(array('posts_per_page' => '8','paged'=>$paged, 'cat' => $category_id ));