I have used taxonomy template texonomy-blog_category.php file.
But gives 404 error when i moved to page 2 .
Below is my code
<?php
get_header('newheader');
$tax = get_query_var('taxonomy');
$term = get_query_var('term');
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$count_args=array( 'post_type' => 'blog_post',
'tax_query' => array(
array(
'taxonomy' => $tax,
'field' => 'slug',
'terms' => $term,
),
),
);
$count_detail=query_posts($count_args);
//echo count($count_detail);exit;
$posts_per_page = 2;// get_option( 'posts_per_page' );
$max_page=ceil(count($count_detail)/$posts_per_page);
//wp_reset_query();
$args = array( 'post_type' => 'blog_post',
'tax_query' => array(
array(
'taxonomy' => $tax,
'field' => 'slug',
'terms' => $term,
),
),
'posts_per_page'=>$posts_per_page,
'paged' => $paged,'page'=>$paged,
'max_num_pages'=>$max_page,
);
$post_detail=query_posts($args);
?>
<div class="container">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 main-conten">
<div class="col-lg-8 col-md-8 col-sm-12 col-xs-12 blog-main">
<ul class="blog_listing">
<?php
for($i=0;$i<count($post_detail);$i++)
{
$postId=$post_detail[$i]->ID;
$ttl=get_the_title($postId);
$url=$post_detail[$i]->guid;
//print_r($post_detail[$i]);
?>
<li>
<a href="<?php echo $post_detail[$i]->guid; ?>" ><h1><?php echo get_the_title($postId); ?></h1></a>
<div class="blog-img">
<a href="<?php echo $post_detail[$i]->guid; ?>" >
<?php //$retina = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ) ?>
<?php echo get_the_post_thumbnail( $postId,array(760,331), $attr ); ?>
</a>
</div>
<span>
<?php echo date('d F , Y',strtotime($post_detail[$i]->post_date)); ?>
</span>
<p>
<?php echo $post_detail[$i]->post_excerpt; ?>
</p>
<a class="read-more" href="<?php echo $post_detail[$i]->guid; ?>">Read More</a> </li>
</li>
<?php }?>
</ul>
<div class="case_blog">
<?php
//wp_reset_postdata();
if (function_exists(custom_pagination)) {
custom_pagination($max_page,"",$paged);
}
?>
</div>
<?php //$custom_query = $temp; ?>
</div>
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12 blog_right_list blog-side">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Blog Sidebar") ) : ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php get_footer();
?>
I don't know what is going wrong.please help me to get out of this.
Thanks in advance
Remove page parameter from $args, your code look like this.
$args = array( 'post_type' => 'blog_post',
'tax_query' => array(
array(
'taxonomy' => $tax,
'field' => 'slug',
'terms' => $term,
),
),
'posts_per_page'=>$posts_per_page,
'paged' => $paged,
'max_num_pages'=>$max_page,
);
Related
I have a pizza sales site which offers 'Ingredients' of which these are simple products, for example: Pizza NapolĂ is a bundle product, this product has ingredients grouped together.
What I'm looking for is to show in a custom loop (wp_query) the children products or ingredients of this pizza, which are 'Cheese(Queso)', 'Bacon(Tocineta)', etc.
Images reference here:
My code:
<?php
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'orderby' => 'date',
'order' => 'ASC',
'meta_key' => '_stock_status',
'posts_per_page' => 10,
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'terms' => array('pizzas'),
'field' => 'name',
'operator' => 'IN'
)
)
);
// End query
$products = new WP_Query( $args, 'woocommerce'); ?>
<div class="menu-grid-pizzas">
<?php if ($products->have_posts()): ?>
<div class="container">
<ul class="grid-pizzas-list">
<?php while ($products->have_posts()): $products->the_post(); ?>
<li class="grid-pizzas-content">
<div class="content-left">
<div class="grid-img">
<a href="<?php the_permalink();?>">
<?php the_post_thumbnail('medium');?>
</a>
</div>
</div>
<div class="content-right">
<div class="grid-product-title">
<a href="<?php the_permalink();?>">
<h4><?php the_title();?></h4>
</a>
</div>
<div class="grid-product-content">
<?php $content = get_the_content();?>
<p><?php echo mb_strimwidth($content, 0, 120, "...");?></p>
</div>
<div class="grid-product-ingredints">
<!-- HERE get DATA items bundles -->
</div>
<div class="grid-product-price">
<?php $precio = get_post_meta( get_the_ID(), '_price', true );?>
<p><?php echo wc_price( $precio ); ?></p>
</div>
<div class="grid-product-add-to-card">
<?php do_action('woocommerce_after_shop_loop_item' , 'woocommerce_template_loop_add_to_cart' , 10 );?>
</div>
</div>
</li>
<?php endwhile;?>
<?php wp_reset_postdata();?>
</ul>
</div>
<?php endif;?>
</div>
As you can see, it is a custom loop from which I call all products with the category 'Pizza' with a wp_query.
I hope you can help me, thank you.
My shortcode is working fine but how to set a fallback image in there? Please suggestion
// display default post as a shortcode with prev/next link
function genericposts_shortcode($atts){
extract( shortcode_atts( array(
'expand' => '',
), $atts) );
global $paged;
$posts_per_page = 10;
$settings = array(
'showposts' => $posts_per_page,
'post_type' => 'post',
'orderby' => 'menu_order',
'order' => 'ASC',
'paged' => $paged
);
$post_query = new WP_Query( $settings );
$total_found_posts = $post_query->found_posts;
$total_page = ceil($total_found_posts / $posts_per_page);
$list = '<div class="bloglist">';
while($post_query->have_posts()) : $post_query->the_post();
$list .= '
<div class="bloglist__item">
<div class="bloglist__imgwrap">
<img src=" '. get_the_post_thumbnail_url(get_the_ID(),'full') .'">
</div>
<div class="bloglist__wrapt">
<div class="bloglist__datetitle">
<span class="bloglist__date"> '. get_the_date( 'd' ) . '</span>
<span class="bloglist__mnt"> '. get_the_date( 'M' ) . '</span>
<span class="bloglist__yr"> '. get_the_date( 'Y' ) . '</span>
<div class="bloglist__title"> '. get_the_title() .' </div>
</div>
<div class="bloglist__more">
Read More
</div>
</div>
</div>
';
endwhile;
$list.= '</div>';
if(function_exists('wp_pagenavi')) {
$list .='<div class="page-navigation">'.wp_pagenavi(array('query' => $post_query, 'echo' => false)).'</div>';
} else {
$list.='
<span class="prev-posts-links">'.get_previous_posts_link('Previous page').'</span>
<span class="next-posts-links">'.get_next_posts_link('Next page', $total_page).'</span>
';
}
return $list;
}
add_shortcode('post-shortcode', 'genericposts_shortcode');
I have solved the issue below way.
add_shortcode( 'post-shortcode', 'genericposts_shortcode' );
function genericposts_shortcode( $atts ) {
ob_start();
global $paged;
$posts_per_page = 9;
$settings = array(
'showposts' => $posts_per_page,
'post_type' => 'post',
'orderby' => 'menu_order',
'order' => 'ASC',
'paged' => $paged
);
$post_query = new WP_Query( $settings );
$total_found_posts = $post_query->found_posts;
$total_page = ceil($total_found_posts / $posts_per_page);
if ($post_query->have_posts() ) { ?>
<div class="bloglist">
<?php while ( $post_query->have_posts() ) : $post_query->the_post(); ?>
<div class="bloglist__item" id="post-<?php the_ID(); ?>">
<div class="bloglist__imgwrap">
<?php if( !empty(get_the_post_thumbnail()) ) { ?>
<?php the_post_thumbnail('full');?>
<?php } else { ?>
<img src="https://kanooelite.com/upgrade/wp-content/uploads/2020/11/placeholder.png" />
<?php } ?>
</div>
<div class="bloglist__wrapt">
<div class="bloglist__datetitle">
<span class="bloglist__date"> <?php echo get_the_date( 'd' ); ?></span>
<span class="bloglist__mnt"> <?php echo get_the_date( 'M' ); ?></span>
<span class="bloglist__yr"> <?php echo get_the_date( 'Y' ); ?></span>
<div class="bloglist__title"> <?php echo get_the_title(); ?></div>
</div>
<div class="bloglist__more">
Read More
</div>
</div>
</div>
<?php endwhile;
wp_reset_postdata(); ?>
</div>
<span class="prev-posts-links"><?php echo get_previous_posts_link('Previous page'); ?></span>
<span class="next-posts-links"><?php echo get_next_posts_link('Next page', $total_page); ?></span>
<?php $myvariable = ob_get_clean();
return $myvariable;
} ?>
<?php } ?>
I'm building a theme in WordPress, I'm a newbie, along with the image HTML is being outputted, please do help me resolve this issue, thank you.
<?php
$args = array( 'numberposts' => 4, 'order'=> 'ASC', 'orderby' => 'title', 'category' => '5' );
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?>
<li>
<div class="timeline-image">
<a href="<?php the_permalink(); ?>">
<img class="rounded-circle img-fluid" src="<?php echo the_post_thumbnail(); ?>">
</a>
</div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4 class="subheading text-left"><?php the_title(); ?></h4>
</div>
<div class="timeline-body">
<p class="text-muted text-justify"><?php the_excerpt(); ?>
Read More >>
</p>
</div>
</div>
</li>
<?php endforeach; ?>
You should be looping through the posts as such and not using foreach:
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => 4,
'orderby' => 'title',
'order' => 'ASC',
'category__in' => 5
);
$loop = new wp_query( $args );
while( $loop->have_rows() ) : $loop->the_row();
?>
Your article content…
<h4 class="subheading text-left"><?php the_title(); ?></h4>
<?php endif; ?>
If you need to loop through a different custom post types, use this guide.
I have tried to create custom blog page with navigation. Everything works fine without navigation. I have tried fix the pagenation issue but it was not working below is the code for my custom page template.
<?php /*
Template Name: My Blog Page
*/
get_header();
?>
<div class="container-fluid"><div class="row bkg-grey"><div class="container"><div class="row">
<div class="col-md-8"><div class="row">
<?php
$args = array( 'post_type' => 'post');
if ( have_posts() ) :
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<div class="col-md-12"><div class="row lwp-posts">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="col-md-4"><div class="row">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail('homepage-thumb',array('class' => 'img-responsive' ) );
} ?></div></div>
<div class="col-md-8"><div class="row">
<div class="rjs-post-title"><h2><?php the_title(); ?></h2></div>
<div class="rjs-post-meta"><span>Posted on :<?php the_time( 'j M Y' ); ?></span><span>Posted by : <?php the_author(); ?></span><span itemprop="interactionCount" content='UserComments: <?php comments_popup_link( '0', '1', '%' ); ?> '>Comments : <?php comments_popup_link( '0', '1', '%' ); ?></span><span>Category : <?php the_category(', '); ?></span></div>
<?php the_excerpt(); ?>
</div></div>
<?php edit_post_link(); ?>
<?php wp_link_pages(); ?>
</article></div></div>
<?php endwhile; ?>
<nav class="navigation index">
<div class="alignleft"><?php next_posts_link( 'Older Entries' ); ?></div>
<div class="alignright"><?php previous_posts_link( 'Newer Entries' ); ?></div>
</nav>
</div></div>
<?php else : endif; ?>
<div class="col-md-4"><div class="row">
<?php if ( is_active_sidebar( 'home_right_1' ) ) : ?>
<div id="primary-sidebar" class="primary-sidebar widget-area" role="complementary">
<?php dynamic_sidebar( 'home_right_1' ); ?>
</div><!-- #primary-sidebar -->
<?php endif; ?>
</div></div></div></div></div></div>
<?php get_footer(); ?>
You need to add some parameters to your query args:
$args = array(
'post_type' => 'post',
'posts_per_page' => 6,
'paged' => $paged
);
And if you want to customize navigation links, use this pattern:
<nav class="navigation index">
<?php
echo paginate_links( array(
'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
'total' => $query->max_num_pages,
'current' => max( 1, get_query_var( 'paged' ) ),
'format' => '?paged=%#%',
'show_all' => false,
'type' => 'plain',
'end_size' => 2,
'mid_size' => 1,
'prev_next' => true,
'prev_text' => sprintf( '<i></i> %1$s', __( 'Newer Posts', 'text-domain' ) ),
'next_text' => sprintf( '%1$s <i></i>', __( 'Older Posts', 'text-domain' ) ),
'add_args' => false,
'add_fragment' => '',
) );
?>
</nav>
I'm creating a one-page theme for WordPress. In my index.php I'm listing all pages underneath each other:
<?php $args = array(
'sort_order' => 'ASC',
'sort_column' => 'menu_order', //post_title
'hierarchical' => 1,
'exclude' => '',
'child_of' => 0,
'parent' => -1,
'exclude_tree' => '',
'number' => '',
'offset' => 0,
'post_type' => 'page',
'post_status' => 'publish'
);
$pages = get_pages($args);
//start loop
foreach ($pages as $page_data) {
$content = apply_filters('the_content', $page_data->post_content);
$title = $page_data->post_title;
$slug = $page_data->post_name;
?>
<div id='<?php echo "$slug" ?>' class="section">
<div id="inner-content" class="wrap cf">
<div id="main" class="m-all cf" role="main">
<div class="content">
<h2 class="section-title"><?php echo "$title" ?></h2>
<?php echo "$content" ?>
<?php the_post_thumbnail('full'); ?>
</div>
</div>
</div>
<?php } ?>
However, my thumbnail does not show up... There is no error message, but as well no thumb. Any ideas?
Try this code
<?php $args = array(
'sort_order' => 'ASC',
'sort_column' => 'menu_order', //post_title
'hierarchical' => 1,
'exclude' => '',
'child_of' => 0,
'parent' => -1,
'exclude_tree' => '',
'number' => '',
'offset' => 0,
'post_type' => 'page',
'post_status' => 'publish'
);
$pages = get_pages($args);
//start loop
foreach ($pages as $page_data) {
$content = apply_filters('the_content', $page_data->post_content);
$title = $page_data->post_title;
$slug = $page_data->post_name;
?>
<div id='<?php echo "$slug" ?>' class="section">
<div id="inner-content" class="wrap cf">
<div id="main" class="m-all cf" role="main">
<div class="content">
<h2 class="section-title"><?php echo "$title" ?></h2>
<?php echo "$content" ?>
<?php echo get_the_post_thumbnail( $page_data->ID, 'thumbnail' ); ?>
</div>
</div>
</div>
<?php } ?>