Add image with Post url after content - wordpress

I would like to add an image with the link to the post - <?php echo esc_url($theme_post['url']); in the bottom right corner of the class "blog-grid-content".
Could someone please guide me to the best approach?
Thank you
<div class="blog-grid grid-2<?php echo esc_attr( $blog_grid_class ); ?>" <?php echo esc_attr( $anim_attrs ); ?>>
<div class="blog-grid-content">
<?php if ( $theme_post['categories'] ) : ?>
<div class="tags">
<?php if ( in_array( 'sticky', get_post_class( '', $theme_post['post_id'] ) ) ) : ?>
<span class="tag tag-sticky"><?php esc_html_e( 'Featured', 'theme' ); ?></span>
<?php endif; ?>
<?php foreach ($theme_post['categories'] as $_category) : ?>
<a class="tag brand-bg-color" href="<?php echo esc_url( get_category_link( $_category->cat_ID ) ); ?>">
<?php echo esc_html( $_category->name ); ?>
</a>
<?php endforeach; ?>
</div>
</div>
</div>

Related

Problem with displaying wooccomerce related products

Bello my singleproduct.php, but my related products not shown on all categories, some work and some no, it is depend on query and fonts. For example here is work https://avestone.ru/product-category/nashi-raboti/, but if I change name of category it will not work. And it does not work at all at any russian named category.
<?php
/**
* The Template for displaying all single products
*
* This template can be overridden by copying it to yourtheme/woocommerce/single-product.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* #see https://docs.woocommerce.com/document/template-structure/
* #package WooCommerce\Templates
* #version 1.6.4
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
get_header(); ?>
<div class="popup_form" id="popup_form_product">
<div class="popup_form_content" id="popup_form_content_product">
<a href="javascript:PopUpHide()" class="popup_close">
<svg width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M17.1875 4.8125L4.8125 17.1875" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M17.1875 17.1875L4.8125 4.8125" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</a>
<div class="form_title">Заказать расчет</div>
<?php echo do_shortcode( '[contact-form-7 id="6241" title="Попап товары"]' ); ?>
</div>
</div>
<?php
/**
* woocommerce_before_main_content hook.
*
* #hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
* #hooked woocommerce_breadcrumb - 20
*/
do_action( 'woocommerce_before_main_content' );
?>
<div id="product-<?php the_ID(); ?>" <?php wc_product_class( '', $product ); ?>>
<div class="product_content">
<div class="breadcrumb">
<?php $values = get_the_terms( $product->id, 'pa_brend'); ?>
<ul>
<li>Каталог</li>
<li> - </li>
<li>
<?php foreach ( $values as $value ) {
echo '' . $value->name .'';
} ?></li>
<li> - </li>
<li><?php the_title(); ?></li>
</ul>
</div>
<?php the_title( '<h1 class="product_title mobile-product_title">', '</h1>' ); ?>
<?php while ( have_posts() ) : ?>
<?php the_post(); ?>
<div class="product_top_content">
<div class="product_top_content_block">
<div class="product_img">
<?php
$columns = apply_filters( 'woocommerce_product_thumbnails_columns', 4 );
$post_thumbnail_id = $product->get_image_id();
$wrapper_classes = apply_filters(
'woocommerce_single_product_image_gallery_classes',
array(
'woocommerce-product-gallery',
'woocommerce-product-gallery--' . ( $post_thumbnail_id ? 'with-images' : 'without-images' ),
'woocommerce-product-gallery--columns-' . absint( $columns ),
'images',
)
);
?>
<div class="<?php echo esc_attr( implode( ' ', array_map( 'sanitize_html_class', $wrapper_classes ) ) ); ?>" data-columns="<?php echo esc_attr( $columns ); ?>" style="opacity: 0; transition: opacity .25s ease-in-out;">
<figure class="woocommerce-product-gallery__wrapper">
<?php
if ( $post_thumbnail_id ) {
$html = wc_get_gallery_image_html( $post_thumbnail_id, true );
} else {
$html = '<div class="woocommerce-product-gallery__image--placeholder">';
$html .= sprintf( '<img src="%s" alt="%s" class="wp-post-image" />', esc_url( wc_placeholder_img_src( 'woocommerce_single' ) ), esc_html__( 'Awaiting product image', 'woocommerce' ) );
$html .= '</div>';
}
echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', $html, $post_thumbnail_id ); // phpcs:disable WordPress.XSS.EscapeOutput.OutputNotEscaped
do_action( 'woocommerce_product_thumbnails' );
?>
</figure>
</div>
</div>
</div>
<div class="product_top_content_block product_top_content_block_right">
<?php the_title( '<h1 class="product_title">', '</h1>' ); ?>
<ul class="product_atr">
<li>Категория: <?php $cats_arr = wc_get_product_category_list( $product->get_id()); $cat_arr = explode(",", $cats_arr); echo $cat_arr[0];?></li>
<?php echo $product->list_attributes(); ?>
<li><?php esc_html_e( 'SKU:', 'woocommerce' ); ?> <span><?php echo $product->get_sku(); ?><span></li>
</ul>
<?php if( $product->get_price_html()) { ?>
<div class="product_price">
<p class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) ); ?>"><span><?php echo $product->get_price_html(); ?></span> РУБ / м2</p>
<div class="single_product_text">Cтоимость за квадратный метр материала, без учета стоимости изготовления, доставки и монтажа изделия</div>
</div>
<?php } ?>
<form class="product_price_cart cart" action="<?php echo esc_url( apply_filters( 'woocommerce_add_to_cart_form_action', $product->get_permalink() ) ); ?>" method="post" enctype='multipart/form-data'>
<?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
<div class="single_product_btn">
Расчитать стоимость
</div>
</form>
</div>
</div>
<?php $the_content = apply_filters( 'the_content', get_the_content() ); ?>
<div class="product_text_container">
<div class="product_text_tabs">
<?php if ( ! empty( $the_content ) ) : ?>
<div class="product_text_tab_title tab_1 active">Описание</div>
<?php endif; ?>
<?php if( have_rows('reviews') ): ?>
<div class="product_text_tab_title tab_2 <?php if ( empty( $the_content ) ) echo 'active'; ?>">Отзывы <span class="count"></span></div>
<?php endif; ?>
</div>
<div class="product_text_tabs_content">
<div class="product_text text_tab_1 active">
<?php the_content(); ?>
</div>
<div class="product_text text_tab_2 <?php if ( empty( $the_content ) ) echo 'active'; ?>">
<div class="product_text_review_container">
<?php
$count=1;
if( have_rows('reviews') ):
while ( have_rows('reviews') ) : the_row(); ?>
<div class="product_review_block">
<div class="product_review_block_left">
<?php if( get_sub_field('doc') ): ?>
<div class="product_review_title"><?php the_sub_field('doc'); ?></div>
<?php endif; ?>
<ul class="product_review_list">
<?php if( get_sub_field('client') ): ?>
<li>Заказчик: <?php the_sub_field('client'); ?></li>
<?php endif; ?>
<?php if( get_sub_field('adress') ): ?>
<li>Адрес: <?php the_sub_field('adress'); ?></li>
<?php endif; ?>
<?php if( get_sub_field('stone') ): ?>
<li>Камень: <?php the_sub_field('stone'); ?></li>
<?php endif; ?>
<?php if( get_sub_field('price') ): ?>
<li>Стоимость: <?php the_sub_field('price'); ?></li>
<?php endif; ?>
</ul>
<div class="product_review_text product_review_text-<? echo $count?>">
<?php if( get_sub_field('text') ): ?>
<div class="product_review_text_title">Текст:</div>
<p><?php the_sub_field('text'); ?></p>
Показать весть текст
<?php endif; ?>
</div>
</div>
<div class="product_review_block_right">
<?php if( have_rows('gallery') ): ?>
<div class="slider-review-for">
<?php while( have_rows('gallery') ): the_row();?>
<div class="slider-review-for-box"><img src="<?php echo get_sub_field('img'); ?>" alt="<?php echo $image['alt']; ?>"></div>
<?php endwhile; ?>
</div>
<div class="slider-review-nav">
<?php while( have_rows('gallery') ): the_row();?>
<div class="slider-review-nav-box"><img src="<?php echo get_sub_field('img'); ?>" alt="<?php echo $image['alt']; ?>"></div>
<?php endwhile; ?>
</div>
<?php endif; ?>
</div>
</div>
<?php
$count++;
endwhile;
endif;
?>
<div class="product_text_review_container_btn">Показать все отзывы</div>
</div>
</div>
</div>
</div>
<?php endwhile; // end of the loop. ?>
<?php
$cats_arr = wc_get_product_category_list( $product->get_id()); $cat_arr = explode(",", $cats_arr); $cat = $cat_arr[0]; $mycat = preg_replace('#<a.*?>|</a>#sui', '', $cat);
$id5 = get_the_ID();
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => 4,
'orderby' => 'rand',
'post__not_in' => array($id5),
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'terms' => $mycat,
'field' => 'slug',
),
)
);
$loop = new WP_Query($args);
if ($loop->have_posts())
{ ?>
<div class="relative_products">
<h2>Похожие камни:</h2>
<div class="relative_products_container">
<div class="woocommerce columns-4 ">
<ul class="products oceanwp-row clr grid">
<?php
while ($loop->have_posts()):
$loop->the_post(); ?>
<li class="entry has-media col span_1_of_4 owp-content-left owp-thumbs-layout-horizontal owp-btn-normal owp-tabs-layout-horizontal product type-product post-5856 status-publish first instock product_cat-classical product_cat-95 has-post-thumbnail shipping-taxable purchasable product-type-simple">
<div class="product-inner clr">
<div class="woo-entry-image clr">
<?php if (has_post_thumbnail()): ?>
<img src="<?php the_post_thumbnail_url('large'); ?>" alt="<?php the_title(); ?>">
<?php endif; ?>
</div><!-- .woo-entry-image -->
<ul class="woo-entry-inner clr">
<li class="image-wrap">
<div class="woo-entry-image clr">
<?php if (has_post_thumbnail()): ?>
<img src="<?php the_post_thumbnail_url('large'); ?>" alt="<?php the_title(); ?>">
<?php endif; ?>
</div><!-- .woo-entry-image -->
</li>
<li class="title"><?php the_title(); ?></li>
<li class="category">Категория <?php $cats_arr = wc_get_product_category_list( $product->get_id()); $cat_arr = explode(",", $cats_arr); echo $cat_arr[0];?></li>
</ul>
</div>
</li>
<?php
endwhile; ?>
</ul>
</div>
</div>
</div>
<?php } ?>
<?php
/**
* woocommerce_after_main_content hook.
*
* #hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
*/
do_action( 'woocommerce_after_main_content' );
?>
<?php
get_footer();
/* Omit closing PHP tag at the end of PHP files to avoid "headers already sent" issues. */
I tried several solutions, tried to make it work via plugin, nothing help.

How to get all the post titles on a specific page in WordPress

I want to display all the posts on a specific page called "Articles".
However, when I used the_title(); in a loop, it seems that the title of this page is displayed instead.
relative code in articles.php (linked to the Articles page created in dashboard)
<div class="container">
<?php if ( have_posts() ) : ?>
<div class="content">
<?php while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php get_template_part( 'content', get_post_format() ); ?>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
</div>
content.php
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="post-header section medium-padding">
<div class="post-meta-top">
<?php the_time(get_option('date_format')); ?>
<?php
if ( comments_open() ) {
echo '<span class="sep">/</span> ';
if ( is_single() )
comments_popup_link( '0 comments', '1 comment', '% comments', 'post-comments' );
else
comments_number( '0 comments', '1 comment', '% comments' );
}
?>
</div>
<h2 class="post-title"><?php the_title(); ?></h2>
</a>
This part works well in index.php.
Step 1: Create a new template articles.php inside the folder of content.php and insert this code:
<?php
$articles = new WP_Query( array( 'posts_per_page' => -1 ) );
while ( $articles->have_posts() ) :
$articles->the_post();
?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="post-header section medium-padding">
<div class="post-meta-top">
<?php the_time(get_option('date_format')); ?>
<?php
if ( comments_open() ) {
echo '<span class="sep">/</span> ';
if ( is_single() )
comments_popup_link( '0 comments', '1 comment', '% comments', 'post-comments' );
else
comments_number( '0 comments', '1 comment', '% comments' );
}
?>
</div>
<h2 class="post-title"><?php the_title(); ?></h2>
</a>
<?php endwhile; ?>
Step 2: In articles.php replace this line:
<?php get_template_part( 'content', get_post_format() ); ?>
with this one:
<?php get_template_part( 'articles' ); ?>
Not tested but it should work.

Wordpress: Recent post by tags

this is my content.php I am trying to list 2 diffrent tag on my home page. 5 post from each tag. Example 5 tags from tag:Football down of it 5 tags from tag:Basketball and here is my content.php Thanks in advance.
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( has_post_thumbnail() ) : ?>
<div class="entry-thumb col-md-4 col-sm-4 col-xs-12">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" >
<?php the_post_thumbnail('home-thumb'); ?>
</a>
</div>
<?php $has_thumb = "col-md-8 col-sm-8 col-xs-12"; ?>
<?php else : ?>
<?php $has_thumb = ""; ?>
<?php endif; ?>
<div class="entry-summary <?php echo $has_thumb; ?>">
<header class="entry-header">
<?php the_title( sprintf( '<h1 class="entry-title">', esc_url( get_permalink() ) ), '</h1>' ); ?>
</header><!-- .entry-header -->
<div class="post-info">
<?php if ( 'post' == get_post_type() ) : ?>
<?php areview_posted_on(); ?>
<?php endif; ?>
<span class="cat-link">
<?php
$category = get_the_category();
if($category[0]){
echo '<i class="fa fa-folder"></i>' . esc_attr($category[0]->cat_name) . '';
}
?>
</span>
<?php if(function_exists('yasr_get_overall_rating') && function_exists('cfs') && ($cfs->get('show_stars') == 1)) {
echo do_shortcode('[yasr_overall_rating]');
} ?>
</div>
<?php the_excerpt(); ?>
</div><!-- .entry-content -->
<div class="buttons-area">
<?php if ( function_exists('cfs') && ($cfs->get('button_link') !='' ) && ($cfs->get('button_title') !='') && ($cfs->get('button_index') == 1) ) : ?>
<?php echo esc_html($cfs->get('button_title')); ?>
<?php endif; ?>
<?php echo __('Read more', 'areview'); ?>
</div>
You should loop the tags and do a query for each one, and for each post insert your existing HTML, like this:
<?php
$tags = array(
'Football',
'Basketball'
);
foreach ($tags as $tag) {
query_posts(array(
'post_type' => 'post'
'posts_per_page' => 5,
'tax_query' => array(
'taxonomy' => 'post_tag',
'field' => 'name',
'terms' => $tag
)
));
if (have_posts()) {
while(have_posts()) {
the_post();
?>
///.... insert your existing code here
<?php
}
}
wp_reset_query();
}
?>
Just don't forget to insert your existing html instead of the ///.... insert your existing code here block.
Try this
<div class="relatedposts">
<h3>Related posts</h3>
<?php
$args=array(
'post_status' => 'publish',
'tag' => 'football,basketball', //Tag slug
'posts_per_page'=>4, // Number of related posts to display.
);
$my_query = new wp_query( $args );
while( $my_query->have_posts() ) {
$my_query->the_post();
?>
<div class="relatedthumb">
<a rel="external" href="<? the_permalink()?>"><?php the_post_thumbnail(array(150,100)); ?><br />
<?php the_title(); ?>
</a>
</div>
<?php }
wp_reset_query();
?>
</div>
Thank you everyone!! Finally I got it using this code:
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<div class="relatedposts">
<h3 class="widget-title">Football</h3>
<div class="decoration-bar"></div><br>
<?php
$args=array(
'post_status' => 'publish',
'tag' => 'football', //Tag slug
'posts_per_page'=>5, // Number of related posts to display.
);
$my_query = new wp_query( $args );
while( $my_query->have_posts() ) {
$my_query->the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( has_post_thumbnail() ) : ?>
<div class="entry-thumb col-md-4 col-sm-4 col-xs-12">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" >
<?php the_post_thumbnail('home-thumb'); ?>
</a>
</div>
<?php $has_thumb = "col-md-8 col-sm-8 col-xs-12"; ?>
<?php else : ?>
<?php $has_thumb = ""; ?>
<?php endif; ?>
<div class="entry-summary <?php echo $has_thumb; ?>">
<header class="entry-header">
<?php the_title( sprintf( '<h1 class="entry-title">', esc_url( get_permalink() ) ), '</h1>' ); ?>
</header><!-- .entry-header -->
<div class="post-info">
<?php if ( 'post' == get_post_type() ) : ?>
<?php areview_posted_on(); ?>
<?php endif; ?>
<span class="cat-link">
<?php
$category = get_the_category();
if($category[0]){
echo '<i class="fa fa-folder"></i>' . esc_attr($category[0]->cat_name) . '';
}
?>
</span>
<?php if(function_exists('yasr_get_overall_rating') && function_exists('cfs') && ($cfs->get('show_stars') == 1)) {
echo do_shortcode('[yasr_overall_rating]');
} ?>
</div>
<?php the_excerpt(); ?>
</div><!-- .entry-content -->
<div class="buttons-area">
<?php if ( function_exists('cfs') && ($cfs->get('button_link') !='' ) && ($cfs->get('button_title') !='') && ($cfs->get('button_index') == 1) ) : ?>
<?php echo esc_html($cfs->get('button_title')); ?>
<?php endif; ?>
<?php echo __('Read more', 'areview'); ?>
</div>
</article>
<?php }
wp_reset_query();
?>
</div>
<center><h4 >---> More Posts <---</h4></center>
<div class="relatedposts">
<h3 class="widget-title">Basketball</h3>
<div class="decoration-bar"></div><br>
<?php
$args=array(
'post_status' => 'publish',
'tag' => 'basketball', //Tag slug
'posts_per_page'=>3, // Number of related posts to display.
);
$my_query = new wp_query( $args );
while( $my_query->have_posts() ) {
$my_query->the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( has_post_thumbnail() ) : ?>
<div class="entry-thumb col-md-4 col-sm-4 col-xs-12">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" >
<?php the_post_thumbnail('home-thumb'); ?>
</a>
</div>
<?php $has_thumb = "col-md-8 col-sm-8 col-xs-12"; ?>
<?php else : ?>
<?php $has_thumb = ""; ?>
<?php endif; ?>
<div class="entry-summary <?php echo $has_thumb; ?>">
<header class="entry-header">
<?php the_title( sprintf( '<h1 class="entry-title">', esc_url( get_permalink() ) ), '</h1>' ); ?>
</header><!-- .entry-header -->
<div class="post-info">
<?php if ( 'post' == get_post_type() ) : ?>
<?php areview_posted_on(); ?>
<?php endif; ?>
<span class="cat-link">
<?php
$category = get_the_category();
if($category[0]){
echo '<i class="fa fa-folder"></i>' . esc_attr($category[0]->cat_name) . '';
}
?>
</span>
<?php if(function_exists('yasr_get_overall_rating') && function_exists('cfs') && ($cfs->get('show_stars') == 1)) {
echo do_shortcode('[yasr_overall_rating]');
} ?>
</div>
<?php the_excerpt(); ?>
</div><!-- .entry-content -->
<div class="buttons-area">
<?php if ( function_exists('cfs') && ($cfs->get('button_link') !='' ) && ($cfs->get('button_title') !='') && ($cfs->get('button_index') == 1) ) : ?>
<?php echo esc_html($cfs->get('button_title')); ?>
<?php endif; ?>
<?php echo __('Read more', 'areview'); ?>
</div>
</article>
<?php }
wp_reset_query();
?>
</div>
<center><h4 >---> More Posts <---</h4></center>
<div class="relatedposts">
<h3 class="widget-title">Handball</h3>
<div class="decoration-bar"></div><br>
<?php
$args=array(
'post_status' => 'publish',
'tag' => 'handball', //Tag slug
'posts_per_page'=>2, // Number of related posts to display.
);
$my_query = new wp_query( $args );
while( $my_query->have_posts() ) {
$my_query->the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( has_post_thumbnail() ) : ?>
<div class="entry-thumb col-md-4 col-sm-4 col-xs-12">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" >
<?php the_post_thumbnail('home-thumb'); ?>
</a>
</div>
<?php $has_thumb = "col-md-8 col-sm-8 col-xs-12"; ?>
<?php else : ?>
<?php $has_thumb = ""; ?>
<?php endif; ?>
<div class="entry-summary <?php echo $has_thumb; ?>">
<header class="entry-header">
<?php the_title( sprintf( '<h1 class="entry-title">', esc_url( get_permalink() ) ), '</h1>' ); ?>
</header><!-- .entry-header -->
<div class="post-info">
<?php if ( 'post' == get_post_type() ) : ?>
<?php areview_posted_on(); ?>
<?php endif; ?>
<span class="cat-link">
<?php
$category = get_the_category();
if($category[0]){
echo '<i class="fa fa-folder"></i>' . esc_attr($category[0]->cat_name) . '';
}
?>
</span>
<?php if(function_exists('yasr_get_overall_rating') && function_exists('cfs') && ($cfs->get('show_stars') == 1)) {
echo do_shortcode('[yasr_overall_rating]');
} ?>
</div>
<?php the_excerpt(); ?>
</div><!-- .entry-content -->
<div class="buttons-area">
<?php if ( function_exists('cfs') && ($cfs->get('button_link') !='' ) && ($cfs->get('button_title') !='') && ($cfs->get('button_index') == 1) ) : ?>
<?php echo esc_html($cfs->get('button_title')); ?>
<?php endif; ?>
<?php echo __('Read more', 'areview'); ?>
</div>
</article>
<?php }
wp_reset_query();
?>
</div>
<center><h4 >---> More Posts <---</h4></center>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Display the trash posts instead of published posts?

I want to display the posts of post_status="trash" but not post_status="publish". In short, the posts in trash should get displayed on the site. For how long the trash posts would be available in trash? Any help would be appreciated.
index.php
<?php
// show all coupons and setup pagination
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(array(
'post_type' => APP_POST_TYPE,
'ignore_sticky_posts' => 1,
'paged' => $paged
));
?>
<?php get_template_part('loop', 'coupon'); ?>
loop-coupon.php
<?php while (have_posts()) : the_post(); ?>
<?php appthemes_before_post(); ?>
<div <?php post_class('item'); ?> id="post-<?php echo $post->ID; ?>">
<div class="item-holder">
<div class="item-frame">
<div class="store-holder">
<div class="store-image">
<img height="89" width="110" src="<?php echo clpr_store_image($post->ID, APP_TAX_STORE, 'term_id', '110', null); ?>" alt="" />
</div>
<div class="store-name">
<?php echo get_the_term_list($post->ID, APP_TAX_STORE, ' ', ', ', ''); ?>
</div>
</div>
<?php clpr_vote_box_badge($post->ID, $the_trans); ?>
<div class="item-panel">
<?php clpr_coupon_code_box(); ?>
<div class="clear"></div>
<?php appthemes_before_post_title(); ?>
<h1><?php if (mb_strlen(get_the_title()) >= 87) echo mb_substr(get_the_title(), 0, 87).'...'; else the_title(); ?></h1>
<?php appthemes_after_post_title(); ?>
<?php appthemes_before_post_content(); ?>
<p class="desc"><?php echo mb_substr(strip_tags($post->post_content), 0, 200).'... ';?><a class="more" href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'View the %s coupon page', 'appthemes' ), the_title_attribute( 'echo=0' ) ); ?>"><?php _e('more ››', 'appthemes') ?></a></p>
<?php appthemes_after_post_content(); ?>
</div> <!-- #item-panel -->
</div> <!-- #item-frame -->
</div>
</div>
<?php appthemes_after_post(); ?>
<?php appthemes_after_endwhile(); ?>
<?php appthemes_loop_else(); ?>
<h3><?php _e('Sorry, no coupons found', 'appthemes'); ?></h3>
`
Try adding this before your loop
query_posts($query_string. '&post_status=trash');

Wordpress post repeat twice at the last page

I try to display my post using two column, to make sure the fit each other, I tried to create two vertical column, and display the post odd and even seperately. Odd on left side, and even on the right side. And im suing wp_pagenavi() to get navigation working, other page work fine, display the post as I intend it to be, but on the last page, one post will repeat twice.
Here my code for the looping part
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<div id="holder" class="left">
<?php while ( have_posts() ) : ?>
<?php
$postcount++;
if( ($postcount % 2) == 0 ) : // skip 'even' posts
$wp_query->next_post();
else :
?>
<?php the_post(); ?>
<div class="fpost">
<div class="fposttitle">
<h1 class="left"><?php the_title(); ?></h1>
<?php if ( comments_open() || ( '0' != get_comments_number() && ! comments_open() ) ) : ?>
<div class="combox right">
<?php $x = get_comments_number(); if ($x < 10) : ?>
<?php comments_popup_link( __( '00', 'toolbox' ), __( '01', 'toolbox' ), __( '0%', 'toolbox' ) ); ?>
<?php else : ?>
<?php comments_popup_link( __( '00', 'toolbox' ), __( '01', 'toolbox' ), __( '%', 'toolbox' ) ); ?>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="clear"></div>
</div>
<div class="fcontent">
<?php $thumbnail = get_post_meta(get_the_ID(), 'thumbnail', true);
if ($thumbnail) : ?>
<img src="<?php echo $thumbnail; ?>" alt="<?php the_permalink(); ?>" />
<?php else : ?>
<p><?php the_excerpt(); ?></p>
<?php endif; ?>
</div>
<div class="finfo">
<p class="left date"><?php the_time('F j, Y') ?></p>
<p class="left cat"><?php the_category(', ') ?></p>
<p class="right"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'toolbox' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark" >Read More</a></p>
<div class="clear"></div>
</div>
</div>
<?php endif; ?>
<?php endwhile; ?>
</div><!-- #content -->
<div id="holder2" class="left">
<?php while ( have_posts() ) : ?>
<?php
$postcount++;
if( ($postcount % 2) != 0 ) : // skip 'odd' posts
$wp_query->next_post();
else :
?>
<?php the_post(); ?>
<div class="fpost">
<div class="fposttitle">
<h1 class="left"><?php the_title(); ?></h1>
<?php if ( comments_open() || ( '0' != get_comments_number() && ! comments_open() ) ) : ?>
<div class="combox right">
<?php $x = get_comments_number(); if ($x < 10) : ?>
<?php comments_popup_link( __( '00', 'toolbox' ), __( '01', 'toolbox' ), __( '0%', 'toolbox' ) ); ?>
<?php else : ?>
<?php comments_popup_link( __( '00', 'toolbox' ), __( '01', 'toolbox' ), __( '%', 'toolbox' ) ); ?>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="clear"></div>
</div>
<div class="fcontent">
<?php $thumbnail = get_post_meta(get_the_ID(), 'thumbnail', true);
if ($thumbnail) : ?>
<img src="<?php echo $thumbnail; ?>" alt="<?php the_permalink(); ?>" />
<?php else : ?>
<p><?php the_excerpt(); ?></p>
<?php endif; ?>
</div>
<div class="finfo">
<p class="left date"><?php the_time('F j, Y') ?></p>
<p class="left cat"><?php the_category(', ') ?></p>
<p class="right"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'toolbox' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark" >Read More</a></p>
<div class="clear"></div>
</div>
</div>
<?php endif; ?>
<?php endwhile; ?>
</div><!-- #content -->
<?php else : ?>
no post
<?php endif; ?>
<div class="clear"></div>
<div id="nav"> <?php wp_pagenavi() ?> </div>
</div><!-- #primary -->
I thinking maybe because last page, there is not enough number post, but can't figure out why the post repeat.
update: I just tried to add one new post, and everything work fine. but when I add another post, it the last page repeat same post again.
Probably should have included this as an answer instead of a comment, in the case where you have an odd number of posts, you don't reset your $postcount variable to 0, so your 2nd loop doesn't necessarily start on the same condition that the first loop did. So on your last page you're able to notice this happening, but chances are on the other pages you're skipping certain posts altogether:
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<div id="holder" class="left">
<?php $postcount = 0; ?>
<?php while ( have_posts() ) : ?>
<?php
$postcount++;
if( ($postcount % 2) == 0 ) : // skip 'even' posts
$wp_query->next_post();
else :
?>
<?php the_post(); ?>
<?php endif; ?>
<?php endwhile; ?>
...
</div><!-- #content -->
<div id="holder2" class="left">
<?php $postcount = 0; ?>
<?php rewind_posts();//rewind the post counter so you can do another loop ?>
<?php while ( have_posts() ) : ?>
<?php
$postcount++;
if( ($postcount % 2) != 0 ) : // skip 'odd' posts
$wp_query->next_post();
else :
?>
<?php the_post(); ?>
...
<?php endif; ?>
<?php endwhile; ?>
</div><!-- #content -->

Resources