I have extra field in my template, it looks like:
" >
<div class="entry-content clearfix">
<div class="col-left">
<?php the_content(); ?>
</div>
<div class="col-right">
<?php
if(function_exists('get_field')) {
$sc = get_field('second_column');
echo apply_filters( the_post_thumbnail( 'thumbnail' ), $sc );
}
?>
</div>
</div><!-- .entry-content -->
</div><!-- #post-## -->
It should be like that: col-left displaying posts (recent 10) and in col-right displaying thumnail to each post.
How I should put while, to have all content inside this template? Sitting a while on it, and no idea for it. The best, but not working as I need, is:
<?php if ( $category_posts->have_posts() ) ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry-content clearfix">
<div class="col-left">
<?php while ( $category_posts->have_posts() ) : $category_posts->the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
</div>
<div class="col-right">
<?php
while ( $category_posts->have_posts() ) : $category_posts->the_post();
if(function_exists('get_field')) {
$sc = get_field('second_column');
echo apply_filters( the_post_thumbnail( 'thumbnail' ), $sc );
}
?>
</div>
</div><!-- .entry-content -->
</div><!-- #post-## -->
Tomu, if you want to run loop twice on same page than you have to use <?php rewind_posts(); ?>. You can try below code.
<?php if ( $category_posts->have_posts() ) ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry-content clearfix">
<div class="col-left">
<?php while ( $category_posts->have_posts() ) : $category_posts->the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
</div>
<div class="col-right">
<?php rewind_posts(); ?>
<?php
while ( $category_posts->have_posts() ) : $category_posts->the_post();
if(function_exists('get_field')) {
$sc = get_field('second_column');
echo apply_filters( the_post_thumbnail( 'thumbnail' ), $sc );
}
?>
</div>
</div><!-- .entry-content -->
Related
I am displaying an image and a text excerpt of the posts on my landing page. However I would like to prevent image captions from appearing on those excerpts.
Is there an quick way of doing this?
<?php while ( have_posts() ) : the_post() ?>
<div id="post-<?php the_ID() ?>" class="<?php sandbox_post_class() ?>">
<div class="entry-meta clearfix">
<h2 class="entry-title"><?php the_title() ?></h2>
</div>
<div class="entry-content">
<p class="thePic clearfix">
<?php the_post_image('thumbnail'); ?>
</p>
<p>
<?php the_content_rss('', TRUE, '', 40); ?>Read More
</p>
</div><!-- .entry-content -->
</div><!-- .post -->
<?php endwhile ?>
add this code to your functions.php
function excerpt_bz( $content, $limit=25, $endPoints = '[...]', $tags_accepts = '' ) {
$excerpt = explode(' ', strip_tags($content, $tags_accepts), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).' '.$endPoints;
} else {
$excerpt = implode(" ",$excerpt);
}
return $excerpt;
}
note that this pulls the content and cuts it and you pass the allowed data
<?php while ( have_posts() ) : the_post() ?>
<div id="post-<?php the_ID() ?>" class="<?php /*sandbox_post_class()*/ ?>">
<div class="entry-meta clearfix">
<h2 class="entry-title"><?php the_title() ?></h2>
</div>
<div class="entry-content">
<p class="thePic clearfix">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<!--here you have greater control -->
<figure>
<?php get_the_post_thumbnail('thumbnail'); ?>
</figure>
</a>
</p>
<p>
<!-- use ( note that this function you need to fill the field in the panel in wp )-->
<?php the_excerpt(); ?>
<!-- or (note that this pulls the content and cuts it and you pass the allowed data) -->
<?php echo excerpt_bz( get_the_content(), 500, '...', '<a><p><br><strong><em>' ) ?>
Read More
</p>
</div><!-- .entry-content -->
</div><!-- .post -->
<?php endwhile ?>
Got it by replacing the "the_content_rss" for "the_excerpt"
<div id="post-<?php the_ID() ?>" class="<?php sandbox_post_class() ?>">
<div class="entry-meta clearfix">
<h2 class="entry-title"><?php the_title() ?></h2>
</div>
<div class="entry-content">
<p class="thePic clearfix">
<?php the_post_image('thumbnail'); ?>
</p>
<p>
<?php the_excerpt('', TRUE, '', 40); ?><div class="read-more">Read More</div>
</p>
</div><!-- .entry-content -->
</div><!-- .post -->
<?php endwhile ?>
I need to display all posts on the main page that will vary. That is, they will not repeat on the same page. I display them using WP_Query, but for each column of posts I need to have another 'posts_per_page'. How to do it?
I trying this:
<?php $my_query = new WP_Query($args); ?>
and
this <?php $my_query->set('posts_per_page', 3);
$my_query->query($my_query->query_vars); ?>
Here is my code example one:
<div class="row">
<div class="col-xl-9 col-lg-9 col-md-12 featured-posts">
<?php $my_query->set('posts_per_page', 3); $my_query->query($my_query->query_vars); ?>
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
<article class="post post-id-<?php echo the_ID(); ?>">
<a class="post-thumbnail" href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a>
<div class="post-content">
<h3 class="post-title"><?php the_title(); ?></h3>
<?php healthybroom_posted_on(); ?>
<?php healthybroom_entry_footer(); ?>
<p class="post-excerpt"><?php echo get_the_excerpt(); ?></p>
</div>
</article>
<?php endwhile; ?>
</div>
<div class="col-xl-3 col-lg-3 col-md-12 front-random-posts">
<?php $my_query->set('posts_per_page', 5); $my_query->query($my_query->query_vars); ?>
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
<article class="post post-id-<?php echo the_ID(); ?>">
<a class="post-thumbnail" href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a>
<div class="post-content">
<?php healthybroom_entry_footer(); ?>
<h3 class="post-title"><?php the_title(); ?></h3>
<?php healthybroom_posted_on(); ?>
</div>
</article>
<?php endwhile; ?>
</div>
</div>
I want the posts to not be repeated simply.
If you have 2 loops with random posts and you want to avoid to have same posts in the 2 loops, you can use the following code :
<!-- We create an array for saving the IDs of the post displaying in the first loop -->
<?php $store_posts_ids = array(); ?>
<div class="row">
<div class="col-xl-9 col-lg-9 col-md-12 featured-posts">
<?php
$my_query->set('posts_per_page', 3);
$my_query->query($my_query->query_vars);
?>
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
<!-- We store the post id for the second loop -->
<?php array_push( $store_posts_ids, get_the_ID() ); ?>
<!-- Your code here -->
<?php endwhile; ?>
</div>
<div class="col-xl-3 col-lg-3 col-md-12 front-random-posts">
<?php
/*
If you want to display 5 posts, you need to have a loop
of 7 posts because you have 3 posts in your first loop
*/
$number_post = 0;
$my_query->set('posts_per_page', 5);
$my_query->query($my_query->query_vars);
?>
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
<?php array( $store_posts_ids, get_the_ID() ); ?>
<!-- If we have our 5 posts, no need to display more posts -->
<?php if( $number_post < 5 ): ?>
<!-- If the post is not in the first loop -->
<?php if( !in_array( $store_posts_ids, get_the_ID() ) ): ?>
<?php $number_post = $number_post + 1; ?>
<!-- Your code here -->
<?php endif; ?>
<?php endif; ?>
<?php endwhile; ?>
</div>
</div>
Before I decided to post, I read all I could on this site with people of the same issues. Nothing seemed to work... I will explain it the best I can, I am using ACF + Repeater add-on to make A Restaurant Menu. I have Bootstrap loaded to help with making things easier, I want to have 3 columns going across. This is the HTML and PHP side of things.. I am using Bridge Theme, so I had to change the Bootstrap container class to container-acf because it kept going to the Bridge style instead. My end Goal if for it Look Similar To This All help is appreciated Thanks
My guess is I will need a Foreach loop.
`<?php
/*
Template Name: Restaurant Menu Template
*/
get_header(); ?>
<div class="content-fill-in-menu">HERE</div>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
// Start the loop.
while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header><!-- .entry-header -->
<div class="entry-content wpb_wrapper container-acf">
<?php if ( have_rows('menu_sections') ):
while ( have_rows('menu_sections') ): the_row(); ?>
<h2 class="section_desc"><?php the_sub_field('section_title'); ?></h2>
<?php if ( have_rows('section_items') ): ?>
<?php while ( have_rows('section_items') ): the_row(); ?>
<article class="lmenu">
<ul>
<li>
<div class="container-acf">
<div class="row">
<div class="col-md-3 item_info">
<img class="dish_pic" src="<?php the_sub_field('dish_pic'); ?>" alt="<?php the_sub_field('dish_name'); ?>">
<h3 class="item_name"><?php the_sub_field('dish_name'); ?></h3>
<p class="item_desc"><?php the_sub_field('dish_description'); ?></p>
<h4 class="price">$<?php the_sub_field('dish_price'); ?></h4>
<span class="separator"></span>
</div>
</div>
</div>
</li>
</ul>
</article>
<?php endwhile; ?>
</table>
<?php endif; ?>
<?php endwhile;
endif; ?>
</div><!-- .entry-content -->
</article><!-- #post-## -->
<?php endwhile; // End the loop. ?>
</main><!-- .site-main -->
</div><!-- .content-area -->
<div class="content-fill-in-menu">HERE</div>
<?php get_footer(); ?>`
I think a lot of your problems are in the loop into "section_items" repeater field.
In the "while" loop, you open and close a container and a row for each item, so you don't have your render in columns.
Here in a idea of changes, you need open a row before the start of the loop. I put a counter ($i) to restart a row each 4 items to prevent problems :
<?php if ( have_rows('menu_sections') ): ?>
<?php while ( have_rows('menu_sections') ): the_row(); ?>
<h2 class="section_desc"><?php the_sub_field('section_title'); ?></h2>
<?php if ( have_rows('section_items') ): ?>
<?php $i = 1; ?>
<div class="row">
<?php while ( have_rows('section_items') ): the_row(); ?>
<div class="col-md-3 item_info">
<article class="lmenu">
<img class="dish_pic" src="<?php the_sub_field('dish_pic'); ?>" alt="<?php the_sub_field('dish_name'); ?>">
<h3 class="item_name"><?php the_sub_field('dish_name'); ?></h3>
<p class="item_desc"><?php the_sub_field('dish_description'); ?></p>
<h4 class="price">$<?php the_sub_field('dish_price'); ?></h4>
<span class="separator"></span>
</article>
</div><!-- /.col -->
<?php
if( $i == 4 ){
echo '</div><div class="row">';
$i = 0;
}
$i++;
?>
<?php endwhile; ?>
</div><!-- /.row -->
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
how to list only 10 post in one page and solve pagination, i found repeated loop in this.
i want to apply css in comment also . how can i separate comments each part and can give individual css?
<?php query_posts('post_type=post&post_status=publish&posts_per_page=10&paged='. get_query_var('paged')); ?>
<?php if( have_posts() ): ?>
<?php while( have_posts() ): the_post(); ?>
<div id="post-<?php get_the_ID(); ?>" <?php post_class(); ?>>
<?php the_post_thumbnail( array(200,220),'thumbnail', array( 'class' => 'alignleft' ) ); ?>
<h2><?php the_title(); ?></h2>
<span class="meta"><?php //author_profile_avatar_link(48); ?> <strong><?php the_time('F jS, Y'); ?></strong> / <strong><?php the_author_link(); ?></strong> / <span class="comments"><?php comments_popup_link(__('0 comments','twentythirteen'),__('1 comment','twentythirteen'),__('% comments','twentythirteen')); ?></span></span>
<?php the_excerpt(__('Continue reading »','twentythirteen')); ?>
</div><!-- /#post-<?php get_the_ID(); ?> -->
<?php endwhile; ?>
<div class="navigation">
<span class="newer"><?php previous_posts_link(__('« Newer','twentythirteen')) ?></span> <span class="older"><?php next_posts_link(__('Older »','twentythirteen')) ?></span>
</div><!-- /.navigation -->
<?php else: ?>
<div id="post-404" class="noposts">
<p><?php _e('None found.','twentythirteen'); ?></p>
</div><!-- /#post-404 -->
<?php endif; wp_reset_query(); ?>
</div><!-- /#content -->
In my theme I have a blog page and a homepage (without blog loop). Now I would like to add some blog posts on my homepage (like most recent).
I am using the blog page as a template for the homepage ( I copied and renamed the original), wich works good. But I can't make any changes to it without changing the original blog page (the loop is called in an external php).
I Have no idea were to start.
This is the piece on the homepage calling the blog loop:
<?php if(have_posts()) : the_post(); ?>
<div id="main">
<div class="central-wrapper clearfix">
<div id="center" class="fullwidth">
<div id="content">
<?php if($gallery_select && $gallery_position == 1) : ?>
<?php codeus_gallery($gallery_select, $gallery_size, $gallery_style); ?>
<?php endif; ?>
<div class="inner">
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="pagination"><div class="page-links-title">' . __( 'Pages:', 'codeus' ) . '</div>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?>
<div class="bloghome">
<?php codeus_blog_list(); ?>
</div>
<?php if($quickfinder_position == 2) : ?>
<?php codeus_quickfinder($quickfinder_select); ?>
<?php endif; ?>
<?php if($portfolio_position == 2) : ?>
<?php codeus_portfolio(implode(',',$portfolio_select), $portfolio_size, $portfolio_count, $portfolio_filter, $portfolio_title); ?>
<?php endif; ?>
<?php if($gallery_select && $gallery_position == 3) : ?>
<?php codeus_gallery($gallery_select, $gallery_size, $gallery_style); ?>
<?php endif; ?>
</div>
</div><!-- #content -->
</div><!-- #center -->
</div><!-- .central-wrapper -->
</div><!-- #main -->
<?php endif; ?>
</div><!-- wrap end -->
And this is the piece in the external php called blog.php
<?php if($blog_loop->have_posts()) : ?>
<div class="blog_list">
<ul class="styled">
<?php while ( $blog_loop->have_posts() ) : $blog_loop->the_post(); ?>
<li class="clearfix">
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php $image_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'codeus_post_list_image'); ?>
<div class="comment-info">
<?php echo get_the_date('d'); ?>
<div class="date-month"><?php echo get_the_date('M'); ?></div>
</div>
<div class="post-info">
<h3><?php the_title(); ?></h3>
<?php if($image_url[0]) : ?>
<div class="post-image">
<div class="image wrap-box shadow middle">
<div class="shadow-left"></div><div class="shadow-right"> </div>
<img src=" <?php echo $image_url[0]; ?>" alt="<?php the_title(); ?>" />
</div>
</div>
<?php endif; ?>
<div class="text clearfix"><?php the_excerpt(); ?></div>
<?php codeus_author_info(get_the_ID()); ?>
</div>
</div>
</li>
<?php $post = $portfolio_posttemp; wp_reset_postdata(); ?>
<?php endwhile; ?>
</ul>
<?php codeus_pagination($page_num, $pages_count); ?>
</div>
<?php endif; ?>
Remember, I don't want to make changes in the original blog.php, because the normal blog page needs to work as it is now. I would like to make the blog work on the homepage also, but just with a maximum of 3 posts showing, perhaps of a certain category.
Help would be so welcome!!
I think I found a solution, I edited the homepage template like this:
<!-- wrap start --><div class="content-wrap">
<?php if(have_posts()) : the_post(); ?>
<div id="main">
<div class="central-wrapper clearfix">
<div id="center" class="fullwidth">
<div id="content">
<div class="inner">
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="pagination"><div class="page-links-title">' . __( 'Pages:', 'codeus' ) . '</div>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?>
<div class="bloghome">
<?php
$page_num = (get_query_var('paged')) ? get_query_var('paged') : 1;
$items_per_page = 2;
$blog_loop = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => $items_per_page,
'paged' => $page_num
));
$pages_count = ceil($blog_loop->found_posts/$items_per_page);
global $post;
$portfolio_posttemp = $post;
?>
<?php if($blog_loop->have_posts()) : ?>
<div class="blog_list">
<ul class="styled">
<?php while ( $blog_loop->have_posts() ) : $blog_loop->the_post(); ?>
<li class="clearfix">
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php $image_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'codeus_post_list_image'); ?>
<div class="comment-info">
<?php echo get_the_date('d'); ?>
<div class="date-month"><?php echo get_the_date('M'); ?></div>
</div>
<div class="post-info">
<h3><?php the_title(); ?></h3>
<?php if($image_url[0]) : ?>
<div class="post-image">
<div class="image wrap-box shadow middle">
<div class="shadow-left"></div><div class="shadow-right"></div>
<img src="<?php echo $image_url[0]; ?>" alt="<?php the_title(); ?>" />
</div>
</div>
<?php endif; ?>
<div class="text clearfix"><?php the_excerpt(); ?></div>
<?php codeus_author_info(get_the_ID()); ?>
</div>
</div>
</li>
<?php $post = $portfolio_posttemp; wp_reset_postdata(); ?>
<?php endwhile; ?>
</ul>
</div>
<?php endif; ?>
</div>
</div>
</div><!-- #content -->
</div><!-- #center -->
</div><!-- .central-wrapper -->
</div><!-- #main -->
<?php endif; ?>
</div><!-- wrap end -->