This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 3 years ago.
I'm trying to add pagination to my [shortcut]. This is my code:
<?php }
//LatestCar Function
function carforyou_LatestCar($atts){
ob_start();?>
<div class="row">
<?php
extract( shortcode_atts(array('show' =>''), $atts ));
extract( shortcode_atts(array('brand' =>''), $atts ));
$loop = new WP_Query( array(
'post_type' => 'auto',
'auto-brand' => $brand,
'posts_per_page'=>$show,
'offset' => 0
));// $count = $loop->found_posts; echo $count;
while ($loop->have_posts()) : $loop->the_post();
global $post; ?>
<div class="col-list-3">
<div class="featured-car-list">
<div class="featured-car-img">
<a alt="<?php echo get_the_title(); ?>" title="<?php echo get_the_title(); ?>" href="<?php the_permalink();?>">
<?php if(has_post_thumbnail()):
the_post_thumbnail('carforyou_small', array('class' => 'img-responsive'));
else:
echo "<div class='is-empty-img-box'></div>";
endif;
?>
</a>
<?php carforyou_AutoType(); ?>
<div class="compare_item">
<div class="checkbox">
<button id="compare_auto_btn" onclick="<?php echo esc_js('javascript:productCompare('.$post->ID.')'); ?>"><?php esc_html_e('Compare','carforyou'); ?></button>
</div>
</div>
</div>
<div class="featured-car-content">
<h6><a title="<?php echo get_the_title(); ?>" href="<?php the_permalink(); ?>"><?php $title = get_the_title(); echo mb_strimwidth($title, 0, 30, '...'); ?></a></h6>
<div class="price_info">
<?php if(!empty($post->DREAM_auto_price)): ?>
<p class="featured-price"><?php carforyou_curcy_prefix(); ?><?php echo number_format_i18n(esc_html($post->DREAM_auto_price)); ?></p>
<?php endif; ?>
<div class="car-location">
<?php $term_list = wp_get_post_terms($post->ID, 'auto-location', array("fields" => "all"));
foreach($term_list as $term_single)
$location = $term_single->name;
?>
<?php if(!empty($location)): ?>
<span><i class="fa fa-map-marker" aria-hidden="true"></i> <?php echo esc_html($location); ?> </span>
<?php endif; ?>
</div>
</div>
<ul>
<?php carforyou_featuredList(); ?>
</ul>
</div>
</div>
</div>
<?php endwhile; wp_reset_query(); ?>
</div>
<?php }
Above code using [latestcars show="10" brand="ford"] displays 10 cars made by ford. I want to add pagination, so I have added folllwing modification:
<?php }
//LatestCar Function
function carforyou_LatestCar($atts){
ob_start();?>
<div class="row">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
extract( shortcode_atts(array('show' =>''), $atts ));
extract( shortcode_atts(array('brand' =>''), $atts ));
$loop = new WP_Query( array(
'post_type' => 'auto',
'auto-brand' => $brand,
'paged' =>$paged,
'posts_per_page'=>$show,
'offset' => 0
));
// $count = $loop->found_posts; echo $count;
while ($loop->have_posts()) : $loop->the_post();
global $paged, $post;
?>
<div class="col-list-3">
<div class="featured-car-list">
<div class="featured-car-img">
<a alt="<?php echo get_the_title(); ?>" title="<?php echo get_the_title(); ?>" href="<?php the_permalink();?>">
<?php if(has_post_thumbnail()):
the_post_thumbnail('carforyou_small', array('class' => 'img-responsive'));
else:
echo "<div class='is-empty-img-box'></div>";
endif;
?>
</a>
<?php carforyou_AutoType(); ?>
<div class="compare_item">
<div class="checkbox">
<button id="compare_auto_btn" onclick="<?php echo esc_js('javascript:productCompare('.$post->ID.')'); ?>"><?php esc_html_e('Compare','carforyou'); ?></button>
</div>
</div>
</div>
<div class="featured-car-content">
<h6><a title="<?php echo get_the_title(); ?>" href="<?php the_permalink(); ?>"><?php $title = get_the_title(); echo mb_strimwidth($title, 0, 30, '...'); ?></a></h6>
<div class="price_info">
<?php if(!empty($post->DREAM_auto_price)): ?>
<p class="featured-price"><?php carforyou_curcy_prefix(); ?><?php echo number_format_i18n(esc_html($post->DREAM_auto_price)); ?></p>
<?php endif; ?>
<div class="car-location">
<?php $term_list = wp_get_post_terms($post->ID, 'auto-location', array("fields" => "all"));
foreach($term_list as $term_single)
$location = $term_single->name;
?>
<?php if(!empty($location)): ?>
<span><i class="fa fa-map-marker" aria-hidden="true"></i> <?php echo esc_html($location); ?> </span>
<?php endif; ?>
</div>
</div>
<ul>
<?php carforyou_featuredList(); ?>
</ul>
</div>
</div>
</div>
<?php endwhile;
carforyou_pagination();
else:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
extract( shortcode_atts(array('show' =>''), $atts ));
extract( shortcode_atts(array('brand' =>''), $atts ));
$loop = new WP_Query( array(
'post_type' => 'auto',
'auto-brand' => $brand,
'paged' =>$paged,
'posts_per_page'=>$show,
'offset' => 0
));
while ($loop->have_posts()) : $loop->the_post();
?>
<div class="col-list-3">
<div class="featured-car-list">
<div class="featured-car-img">
<a alt="<?php echo get_the_title(); ?>" title="<?php echo get_the_title(); ?>" href="<?php the_permalink();?>">
<?php if(has_post_thumbnail()):
the_post_thumbnail('carforyou_small', array('class' => 'img-responsive'));
else:
echo "<div class='is-empty-img-box'></div>";
endif;
?>
</a>
<?php carforyou_AutoType(); ?>
<div class="compare_item">
<div class="checkbox">
<button id="compare_auto_btn" onclick="<?php echo esc_js('javascript:productCompare('.$post->ID.')'); ?>"><?php esc_html_e('Compare','carforyou'); ?></button>
</div>
</div>
</div>
<div class="featured-car-content">
<h6><a title="<?php echo get_the_title(); ?>" href="<?php the_permalink(); ?>"><?php $title = get_the_title(); echo mb_strimwidth($title, 0, 30, '...'); ?></a></h6>
<div class="price_info">
<?php if(!empty($post->DREAM_auto_price)): ?>
<p class="featured-price"><?php carforyou_curcy_prefix(); ?><?php echo number_format_i18n(esc_html($post->DREAM_auto_price)); ?></p>
<?php endif; ?>
<div class="car-location">
<?php $term_list = wp_get_post_terms($post->ID, 'auto-location', array("fields" => "all"));
foreach($term_list as $term_single)
$location = $term_single->name;
?>
<?php if(!empty($location)): ?>
<span><i class="fa fa-map-marker" aria-hidden="true"></i> <?php echo esc_html($location); ?> </span>
<?php endif; ?>
</div>
</div>
<ul>
<?php carforyou_featuredList(); ?>
</ul>
</div>
</div>
</div>
<?php endwhile;
carforyou_pagination();
endif;
}
?>
Above solution returns following error code which I can't trace:
PHP Parse error: syntax error, unexpected
'else' (T_ELSE) in
/var/www/clients/clientxxx/webxxx/web/wp-content/themes/xxxxxx/functions/basic-functions.php
on line 439
Line 439 is "else:"
<?php endwhile;
carforyou_pagination();
else:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
(...)
Any advice? Thanks
Strip out the HTML tags and it becomes pretty clear that your if...else control structure is not correct. The else in question has no corresponding if structure before it.
while ($loop->have_posts()) : $loop->the_post();
global $paged, $post;?>
<?php if(has_post_thumbnail()): //OPEN IF ONE
the_post_thumbnail('carforyou_small', array('class' => 'img-responsive'));
else:
echo "<div class='is-empty-img-box'></div>";
endif; //CLOSE IF ONE
?>
<?php carforyou_AutoType(); ?>
<?php if(!empty($post->DREAM_auto_price)): ?> //OPEN IF TWO
<?php endif; ?> //CLOSE IF TWO
<?php $term_list = wp_get_post_terms($post->ID, 'auto-location', array("fields" => "all"));
foreach($term_list as $term_single)
$location = $term_single->name;
?>
<?php if(!empty($location)): ?> //OPEN IF THREE
<?php endif; ?> //CLOSE IF THREE
<?php carforyou_featuredList(); ?>
<?php endwhile;
carforyou_pagination();
else: //SO WHERE IS IF FOUR???
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
extract( shortcode_atts(array('show' =>''), $atts ));
...
Related
I am having trouble with wordpress post page with pagination. I have installed a pagination plugin (WP-PageNavi), and I have being able to print all my posts so far, but pagination just shows one page (the present one). How can I make pagination work properly?
<?php
// args query
$args = array(
'post_type' => 'post',
'order' => 'DESC'
);
// custom query
$recent_posts = new WP_Query($args);
// check that we have results
if($recent_posts->have_posts()) : ?>
<ul class="article_list">
<?php
// start loop
while ($recent_posts->have_posts() ) : $recent_posts->the_post(); ?>
<li class="regular">
<a href="<?php echo get_permalink(); ?>">
<div class="text">
<p class="category"><?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?></p>
<h3 class="article_title"><?php echo mb_strimwidth(get_the_title(), 0, 80, '...'); ?></h3>
<p class="date"><?php echo get_the_date( 'Y-m-d' ); ?></p>
</div>
<div class="mask">
<img src="<?php the_post_thumbnail_url();?>" alt="" class="art_img">
</div>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php endif;
// reset query
wp_reset_postdata();
?>
<?php include($path.'libs/pagination.php'); ?>
Here is my pagination.php file:
<div class="pagination">
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
</div>
I guess you have put wp_pagenavi(); function to libs/pagination.php.
So, replace it with
wp_pagenavi(array( 'query' => $recent_posts ));
So, final code should look like,
<?php
// args query
$args = array(
'post_type' => 'post',
'order' => 'DESC'
);
// custom query
$recent_posts = new WP_Query($args);
// check that we have results
if($recent_posts->have_posts()) : ?>
<ul class="article_list">
<?php
// start loop
while ($recent_posts->have_posts() ) : $recent_posts->the_post(); ?>
<li class="regular">
<a href="<?php echo get_permalink(); ?>">
<div class="text">
<p class="category"><?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?></p>
<h3 class="article_title"><?php echo mb_strimwidth(get_the_title(), 0, 80, '...'); ?></h3>
<p class="date"><?php echo get_the_date( 'Y-m-d' ); ?></p>
</div>
<div class="mask">
<img src="<?php the_post_thumbnail_url();?>" alt="" class="art_img">
</div>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php endif;
echo '<div class="pagination">';
if(function_exists('wp_pagenavi')) { wp_pagenavi(array( 'query' => $recent_posts )); }
echo '</div>';
wp_reset_postdata();
?>
I found the problem in my code:
I was not adding anything for the pagination in my query, so it was returning all my posts.
So I added a pagination logic to my custom query and it did work.
<?php $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$custom_args = array(
'post_type' => 'post',
'order' => 'DESC',
'posts_per_page' => 5,
'paged' => $paged
);
// custom query
$recent_posts = new WP_Query($custom_args);
// check that we have results
if($recent_posts->have_posts()) : ?>
<ul class="article_list">
<?php
// start loop
while ($recent_posts->have_posts() ) : $recent_posts->the_post(); ?>
<li class="regular">
<a href="<?php echo get_permalink(); ?>">
<div class="text">
<p class="category"><?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?></p>
<h3 class="article_title"><?php echo mb_strimwidth(get_the_title(), 0, 80, '...'); ?></h3>
<p class="date"><?php echo get_the_date( 'Y-m-d' ); ?></p>
</div>
<div class="mask">
<img src="<?php the_post_thumbnail_url();?>" alt="" class="art_img">
</div>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php endif;
echo '<div class="pagination">';
if(function_exists('wp_pagenavi')) { wp_pagenavi(array( 'query' => $recent_posts )); }
echo '</div>';
wp_reset_postdata();
?>
I created a custom post type called "library", with its "documentation" taxonomy; The problem occurs in the pagination of the taxonomy template (taxonomy-documentation.php).
I have determined a number of "18" posts per page, for the number of posts there should be "7" pages, but I list "16" pages, the pages from "8" to "16" are empty.
The url of archive for the taxonomy is: Documentation Archive
The template loop is as follows:
<?php
$term = $wp_query->queried_object;
$getterm = $term->slug; // get current slug (E.g. winter2015)
$args = (array(
'post_type' => 'library',
'showposts' => 18,
'paged'=>$paged,
'tax_query' => array(
array(
'taxonomy' => 'documentation',
'field' => 'slug',
'terms' => $getterm
),
),
) );
$query = new wp_query( $args );
if ( $query -> have_posts() ) : while ( $query -> have_posts() ) : $query -> the_post(); ?>
<?php setPostViews(get_the_ID()); ?>
<div class="col-md-2">
<?php if ( get_post_meta( get_the_ID(), 'download_image', true ) ) : ?>
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php get_the_title(); ?>">
<?php
$postID = $post->ID;
$imageURI = get_post_meta($postID, 'download_image', true);
$attachmentID = pn_get_attachment_id_from_url ($imageURI);
$imagearray = wp_get_attachment_image_src( $attachmentID, 'full');
$imageURI = $imagearray[0];
$thumbarray = wp_get_attachment_image_src( $attachmentID, 'library-thumbnail');
$thumb_imageURI = $thumbarray[0];
echo "<img class='document-thumbnail' src='". $thumb_imageURI . "' alt='". get_the_title() ."' />";
?>
</a>
<?php endif; ?>
<a class="document-title" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php echo mb_strimwidth(get_the_title(), 0, 40, '...'); ?></a><br />
<span><?php echo __('Published by', 'cyberdocentes'); ?> <a class="author-link" href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ); ?>"><?php the_author(); ?></a></span>
</div>
<?php endwhile; rewind_posts(); ?>
<div class="clear"></div>
<div id="pagination">
<?php include(TEMPLATEPATH . '/pagenavi.php'); if (function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?>
<div class="navigation">
<div class="alignleft">
<?php next_posts_link(__('Next posts','cyberdocentes')); ?>
</div>
<div class="alignright">
<?php previous_posts_link(__('Previous posts','cyberdocentes')); ?>
</div>
</div>
<?php } ?>
</div>
<div class="clear"></div>
<?php else : ?>
<?php endif; ?>
<?php flush(); ?>
Solved code:
<div class="documents-list">
<?php
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'documentation' ) );
global $wp_query;
query_posts( array_merge( $wp_query->query, array( 'posts_per_page' => 18 ) ) );
if (have_posts()) : while ( have_posts() ) : the_post(); ?>
//CODE OF THE ARTICLES HERE
<?php endwhile; rewind_posts(); ?>
<?php endif; ?>
<div class="clear"></div>
<div id="pagination">
<?php include(TEMPLATEPATH . '/pagenavi.php'); if (function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?>
<div class="navigation">
<div class="alignleft">
<?php next_posts_link(__('Next posts','cyberdocentes')); ?>
</div>
<div class="alignright">
<?php previous_posts_link(__('Previous posts','cyberdocentes')); ?>
</div>
</div>
<?php } ?>
</div>
<div class="clear"></div>
<?php flush(); ?>
</div>
How to add post order to this function? I would like to display most recent post from newest to oldest:
<?php
//Establish first post check variable
$first_post = true;
query_posts('category_name=blog&showposts=3');
while (have_posts()) : the_post(); ?>
<li>
<a href="<?php echo get_permalink($post->ID); ?>">
<p class="news_title"><?php $title = get_the_title(); echo wp_trim_words( $title , '4', $more = null ); ?></p></a>
<?php if($first_post) { ?>
<div class="post_skrot"><?php echo wp_trim_words( get_the_content(), $num_words = 8, $more = '... <a class="button_more" href="'. get_permalink($post->ID) . '">show more >> </a>' ); ?></div>
<?php } else { ?>
<div class="post_skrot"><a class="button_more" href="'.get_permalink($post->ID).'">show more>> </a></div>
<?php } ?>
</li>
<?php
//Change value of $first_post
$first_post = false;
endwhile;
wp_reset_query(); ?>
I try add
&orderby=date&order=ASC
but it doesn't work.
Whole code:
<div id="sliders-2-3">
<div class="elementy-oferty">
<div class="slider-4">
<div class="border-video">
<div class="content-slider-4">
<div class="blog_top_title">Blog</div>
<ul>
<?php
//Establish first post check variable
$first_post = true;
$args = array(
'posts_per_page' => 3,
'cat' => 317,
'orderby' => 'DESC'
);
$the_query = new WP_Query( $args );
?>
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="blog_post_sekcja">
<a href="<?php echo get_permalink($post->ID); ?>">
<p class="news_title"><?php $title = get_the_title(); echo wp_trim_words( $title , '4', $more = null ); ?></p></a>
<?php if($first_post) { ?>
<div class="post_skrot"><?php echo wp_trim_words( get_the_content(), $num_words = 30, $more = '... <a class="button_more" href="'. get_permalink($post->ID) . '">pokaż więcej » </a>' ); ?></div>
<?php } else { ?>
<div class="post_skrot"><a class="button_more" href="<?php echo get_permalink($post->ID); ?>">pokaż więcej » </a></div>
<?php } ?>
</div>
<?php
//Change value of $first_post
$first_post = false;
endwhile;
wp_reset_query(); ?>
</ul>
<div class="blog_more">
Więcej wpisów</div>
</div>
</div>
</div>
I've got: Parse error: syntax error, unexpected end of file...on line 145. 145 is my last line in code and on this line I have only <?php get_footer(); ?>
I think it must be something with endwhile; or another syntax.
Your $args array is off a little bit. Should be:
<div id="sliders-2-3">
<div class="elementy-oferty">
<div class="slider-4">
<div class="border-video">
<div class="content-slider-4">
<div class="blog_top_title">Blog</div>
<ul>
<?php
//Establish first post check variable
$first_post = true;
$args = array(
'posts_per_page' => 3,
'cat' => 317,
'orderby' => 'date',
'order' => 'DESC' // or 'ASC like in your original code.'
);
$the_query = new WP_Query( $args );
if ( have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post(); ?>
<div class="blog_post_sekcja">
<a href="<?php echo get_permalink($post->ID); ?>">
<p class="news_title"><?php $title = get_the_title(); echo wp_trim_words( $title , '4', $more = null ); ?></p></a>
<?php if ( $first_post ) : ?>
<div class="post_skrot"><?php echo wp_trim_words( get_the_content(), $num_words = 30, $more = '... <a class="button_more" href="'. get_permalink($post->ID) . '">pokaż więcej » </a>' ); ?></div>
<?php else : ?>
<div class="post_skrot"><a class="button_more" href="<?php echo get_permalink($post->ID); ?>">pokaż więcej » </a></div>
<?php endif; ?>
</div>
<?php
$first_post = false;
}
}
wp_reset_postdata();
?>
</ul>
<div class="blog_more">
Więcej wpisów</div>
</div>
</div>
</div>
Is there a way to edit the following so that rather than bringing in the most recent posts, it bring in posts from a specific category?
if( !function_exists('zolo_recent_posts') ) { function zolo_recent_posts($atts, $content = null) { ob_start(); extract(shortcode_atts(array( "num" => '4', 'columnsizepost' => '', 'data_animation'=>'fadeInDown', 'data_delay'=>'0' ), $atts)); global $post;
query_posts( 'post_type=post&posts_per_page='.$num.'&paged='. #$paged ); ?>
<div class="zolo-recent-post <?php echo $columnsizepost;?>">
<?php $i=1 ; while (have_posts()) : the_post(); if (has_post_thumbnail( $post->ID ) ): ?>
<?php //$image=w p_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'recent_posts_thumb' ); ?>
<?php endif; if( $i % 4==0 ) $class='last' ; else $class='' ; ?>
<div class="blog-box <?php echo $class;?> animated hiding" data-animation="<?php echo $data_animation;?>" data-delay="<?php echo $data_delay; ?>">
<div class="blog-img"><a href="<?php the_permalink(); ?>">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail('recent_posts_thumb');
}
else {
echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/thumb-img.jpg" />';
}
?>
</a>
</div>
<div class="blog-text-area">
<h3><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></h3>
<div class="alltag-row"> <span class="date"><i class="fa fa-calendar"></i>
<?php the_time('F jS, Y') ?>
</span> <span class="add-comment"><a href="<?php the_permalink(); ?>#hello">
<?php comments_number( '0 <i class="fa fa-comment-o"></i>', '1 <i class="fa fa-comment"></i>', '% <i class="fa fa-comments"></i>' ); ?>
</a></span>
</div>
<?php the_excerpt() ;?>
</div>
</div>
</span>
<?php $i++; endwhile; ?>
</div>
<?php wp_reset_query(); $demolp_output=o b_get_clean(); return $demolp_output; } add_shortcode( "zolo_recent_post", "zolo_recent_posts"); }
<?php query_posts('category_name=CATEGORYNAME&showposts=5');
while (have_posts()) : the_post();
// do whatever you want
?>
<b><?php the_title(); ?>
<?php
endwhile;
?>
Using this way you can fetch posts of a specific category in WordPress.
Basically I need this code to display only products from a category id.
Its from a woocomerrce template.
Any help would be appreciated!
<div class="book_wrapper" <?php echo (!empty($book_wrapper)) ? 'style="background-image:url('.esc_url($book_wrapper).');"' : ''; ?>>
<a id="next_page_button"></a>
<a id="prev_page_button"></a>
<div id="loading" class="loading"><?php _e('Loading pages!', THEME_NAME); ?>...</div>
<div id="mybook" style="display:none;">
<div class="b-load">
<?php
$args = array( 'post_type' => 'product', 'posts_per_page' => -1 );
$loop = new WP_Query( $args );
$counter = 0;
echo "<div><ul>";
if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<?php if ($counter == 8): ?>
<?php echo '</ul></div><div><ul>'; $counter = 0; ?>
<?php endif ?>
<li>
<a href="<?php the_permalink(); ?>">
<div class="meal-name"><?php the_title(); ?></div>
<div class="meal-price"><?php echo $product->get_price_html(); ?></div>
</a>
</li>
<?php $counter++; endwhile; endif; ?>
<?php echo '</ul></div>'; ?>
</div>
</div>
</div>
Check this url for more info https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
You will need to add cat in your argument for WP_Query with specific category.
<div class="book_wrapper" <?php echo (!empty($book_wrapper)) ? 'style="background-image:url('.esc_url($book_wrapper).');"' : ''; ?>>
<a id="next_page_button"></a>
<a id="prev_page_button"></a>
<div id="loading" class="loading"><?php _e('Loading pages!', THEME_NAME); ?>...</div>
<div id="mybook" style="display:none;">
<div class="b-load">
<?php
$args = array( 'post_type' => 'product', 'posts_per_page' => -1, cat=> 'Replace with cat id here' );
$loop = new WP_Query( $args );
$counter = 0;
echo "<div><ul>";
if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<?php if ($counter == 8): ?>
<?php echo '</ul></div><div><ul>'; $counter = 0; ?>
<?php endif ?>
<li>
<a href="<?php the_permalink(); ?>">
<div class="meal-name"><?php the_title(); ?></div>
<div class="meal-price"><?php echo $product->get_price_html(); ?></div>
</a>
</li>
<?php $counter++; endwhile; endif; ?>
<?php echo '</ul></div>'; ?>
</div>
</div>
</div>