Wordpress - single post template - display all posts - wordpress

i've make a custom template (for single post), but it display all the posts, not the one i've been clicking on before.
here is my template :
<?php
query_posts( 'post_type=catalogue');
if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div class="header">
<h1><?php echo get_the_term_list($post->ID, 'theme', '', '', ''); ?></h1>
</div>
<div class="main">
<div class="categorie-title"><?php echo get_the_term_list($post->ID, 'theme', '', '', ''); ?></div>
<div id="article-header">
<h2><?php the_title(); ?></h2>
<h3><?php echo get_the_term_list($post->ID, 'realisation', 'Un documentaire réalisé par ', ', ', '.'); ?></h3>
<div class="duree"><?php echo get_post_meta($post->ID, 'Duree', true); ?></div>
</div>
<div class="gallerie-couvertures">
<?php /*
$uploads = wp_upload_dir();
echo '<ul>';
if ($dir = opendir($uploads['basedir'].'/images-produits')) {
$images = array();
while (false !== ($file = readdir($dir))) {
if ($file != "." && $file != "..") {
echo '<li><img src="';
echo $uploads['baseurl'].'/images-produits/'.$file;
echo '" alt="" /></li>
';
}
}
closedir($dir);
}
echo '</ul>';
*/?>
</div>
<div class="section">
<h2><?php the_title(); ?></h2>
<h3><?php echo get_the_term_list($post->ID, 'realisation', 'Un documentaire réalisé par ', ', ', '.'); ?></h3>
<div class="content">
<?php the_content(); ?>
</div>
<ul id="film-description">
<li><span>Genre: </span><?php echo get_the_term_list($post->ID, 'genre', ' ',',', '.'); ?></li>
<li><span>Réalisation: </span><ul><?php echo get_the_term_list($post->ID, 'realisation', '<li>', '</li><li>', '</li>'); ?></ul></li>
<li><span>Co-production: </span><ul><?php echo get_the_term_list($post->ID, 'co-production', '<li>', '</li><li>', '</li>'); ?></ul></li>
<li><span>Année: </span><?php echo get_the_term_list($post->ID, 'date-de-sortie'); ?></li>
<li><span>Couleurs: </span><?php echo get_the_term_list($post->ID, 'couleurs', '', ' - ', ''); ?></li>
<li><span>Distribution: </span><?php echo get_the_term_list($post->ID, 'distribution', '', ', ', ''); ?></li>
</ul>
</div>
<div class="section">
<h3 class="uppercase">Extrait</h3>
<?php echo get_the_term_list($post->ID, 'extrait'); ?>
<div class="movie-preview-description">
<h3><span><?php the_title(); ?></span> (trailer)</h3>
<p><?php echo get_the_term_list($post->ID, 'realisation', 'Un documentaire réalisé par ', ', ', ''); ?> - <?php echo get_post_meta($post->ID, 'Duree', true); ?> </p>
<p><?php echo get_the_term_list($post->ID, 'date-de-sortie'); ?> - <?php echo get_the_term_list($post->ID, 'distribution', '', ', ', ''); ?></p>
</div>
<div class="social-links">
<h4>Partagez</h4>
<ul>
<?php $args = array(
'orderby' => 'id',
'order' => 'ASC',
'category_name' => 'Social') ?>
<?php $socials = get_bookmarks($args);
foreach ($socials as $value) {
echo '<li>'.$value->link_name.'</li>';
}
?>
</ul>
</div>
<div class="voir-vodeo">
<h4>Regarder sur VODEO</h4>
<a href="<?php echo get_post_meta($post->ID, 'VODEO', TRUE);?>" class="vodeo" target="_blank" >Vodeo</a>
</div>
</div>
</div>
<?php endwhile;// End the loop. Whew. ?>
<?php wp_reset_query();?>
I think, i've miss something with the loop, any ideas?

Well, i find the problem... I don't need to specify what post_type is, because i click on it. I don't need any query, i ve just delete this : query_posts( 'post_type=catalogue');.

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.

Wordpress theme... error on my loop?

The loop looks good and no errors but when i paginating the loop didn't works and not change the posts showed but the page/2 or page/3 is showed in the url and by these error in the loop the posts are showed 2 hours or more late.
Elsewhere my code is:
<div class="uk-grid contenido" id="contenido">
<div class="uk-width-1-6 uk-hidden-small uk-hidden-medium"></div>
<div class="uk-width-large-2-6 uk-width-small-1-1 uk-width-medium-1-2">
<button class="uk-button-primary" type="button">Al momento</button>
<hr class="uk-grid-divider">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article class="uk-article">
<h2 class="uk-article-title"><?php the_title(); ?></h2>
<p class="uk-article-Meta p4d"><?php the_time('l j'); ?> de <?php the_time('F'); ?> de <?php the_time('Y'); ?> - Hace <?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ); ?> | <?php $categories = get_the_category();
$separator = ','; $output = ''; if ( ! empty( $categories ) ) {foreach( $categories as $category ) {$output .= '' . esc_html( $category->name ) . '' . $separator; } echo trim( $output, $separator );} ?> | <?php if(function_exists('the_views')) { the_views(); } ?></p>
<p class="uk-article-lead"><?php echo substr(get_the_excerpt(), 0,130); ?>...<a class="more" href="<?php the_permalink(); ?>">(+)</a></p>
<div class="uk-thumbnail uk-thumbnail-large uk-overlay-hover uk-overlay-grayscale"><?php echo get_the_post_thumbnail($post->ID, 'articulo-normal-index'); ?></div>
<p class="uk-article-meta"><?php $categories = get_the_category();
$separator = ','; $output = ''; if ( ! empty( $categories ) ) {foreach( $categories as $category ) {$output .= '' . esc_html( $category->name ) . '' . $separator; } echo trim( $output, $separator );} ?> / <?php the_title(); ?></p>
<hr class="uk-article-divider">
</article>
<?php endwhile; ?>
<?php numeric_posts_nav(); ?>
<?php else : ?>
<p>Disculpa, no hay articulos</p>
<?php endif; ?>
</div>
<div class="separate uk-hidden-small uk-hidden-medium"></div>
<div class="uk-width-large-1-6 uk-hidden-small uk-width-medium-1-2 uk-block-muted min-padding">
<button class="uk-button-primary" type="button">Destacadas</button>
<hr class="uk-grid-divider">
<article class="uk-article uk-text-center">
<?php
global $post;
$args = array( 'numberposts' => 10, 'category_name' => 'destacada' );
$posts = get_posts( $args );
foreach( $posts as $post ): setup_postdata($post);
?>
<h2 class="uk-article-title-small uk-text-center"><?php the_title(); ?></h2>
<p class="uk-article-meta uk-text-center"><?php the_time('l j'); ?> de <?php the_time('F'); ?> de <?php the_time('Y'); ?> - Hace <?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ); ?></p>
<div class="uk-thumbnail uk-thumbnail-medium uk-container-center"><?php echo get_the_post_thumbnail($post->ID, 'articulo-destacadas-sidebar'); ?></div>
<hr class="uk-article-divider">
</article>
<?php
endforeach;
?>
<div class="uk-text-center data-uk-lightbox"><?php dynamic_sidebar( 'anuncio-destacadas' ); ?></div>
</div>
<?php get_sidebar(); ?>
<div class="uk-width-1-6"></div>
</div>

Two Wordpress search results pages

I would like to have two different search results depending on the page, that the user is on.
I have duplicated how the previous search contents would display, added the extra code that I want the staff search to show, and then put an if statement around it.
If user is on page 'staff' -
then show this
Else
show this.
I cant seem to get the if-statement to work, any help would be appreciated.
EDIT
This is the original working code, before i put the IF statement in, to try and create another set of results for staff searching from a specific page.
<?php
if ( is_home() ) {
$paged = get_query_var( 'page' ) ? get_query_var( 'page' ) : get_query_var( 'paged' );
$args = array(
'showposts' => (int) get_option('trim_homepage_posts'),
'paged' => $paged,
'category__not_in' => (array) get_option('trim_exlcats_recent'),
);
query_posts( apply_filters( 'et_home_args', $args ) );
}
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article class="entry post clearfix preownedSearch">
<h2 class="et_pt_portfolio_title"><?php the_title(); ?></h2>
<?php
$index_postinfo = get_option('trim_postinfo1');
if ( $index_postinfo ){
echo '<p class="meta">';
et_postinfo_meta( $index_postinfo, get_option('trim_date_format'), esc_html__('0 comments','Trim'), esc_html__('1 comment','Trim'), '% ' . esc_html__('comments','Trim') );
echo '</p>';
}
?>
<div class="post-content clearfix">
<?php
$thumb = '';
$width = apply_filters('et_image_width',260);
$height = apply_filters('et_image_height',170);
$classtext = '';
$titletext = get_the_title();
$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
$thumb = $thumbnail["thumb"];
?>
<?php if ( '' != $thumb && 'on' == get_option('trim_thumbnails_index') ) { ?>
<div class="featured_box filter">
<a href="<?php the_permalink(); ?>">
<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
</a>
</div> <!-- end .featured_box -->
<?php } ?>
</div>
</article> <!-- end .post-->
<?php
endwhile;
if (function_exists('wp_pagenavi')) { wp_pagenavi(); }
else { get_template_part('includes/navigation','entry'); }
else:
get_template_part('includes/no-results','entry');
endif;
if ( is_home() ) wp_reset_query(); ?>
This is the coding after i've put the if-statement in -
<?php
if ( is_home() ) {
$paged = get_query_var( 'page' ) ? get_query_var( 'page' ) : get_query_var( 'paged' );
$args = array(
'showposts' => (int) get_option('trim_homepage_posts'),
'paged' => $paged,
'category__not_in' => (array) get_option('trim_exlcats_recent'),
);
query_posts( apply_filters( 'et_home_args', $args ) );
}
?>
<?php if (is_page('stock-managers')) { ?>
<article class="entry post clearfix preownedSearch">
<h2 class="et_pt_portfolio_title"><?php the_title(); ?><?php the_meta(); ?></h2>
<?php
$index_postinfo = get_option('trim_postinfo1');
if ( $index_postinfo ){
echo '<p class="meta">';
et_postinfo_meta( $index_postinfo, get_option('trim_date_format'), esc_html__('0 comments','Trim'), esc_html__('1 comment','Trim'), '% ' . esc_html__('comments','Trim') );
echo '</p>';
}
?>
<div class="post-content clearfix">
<?php
$thumb = '';
$width = apply_filters('et_image_width',260);
$height = apply_filters('et_image_height',170);
$classtext = '';
$titletext = get_the_title();
$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
$thumb = $thumbnail["thumb"];
?>
<?php if ( '' != $thumb && 'on' == get_option('trim_thumbnails_index') ) { ?>
<div class="featured_box filter">
<a href="<?php the_permalink(); ?>">
<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
</a>
</div> <!-- end .featured_box -->
<?php } ?>
</div>
</article> <!-- end .post-->
<?php } else { ?>
<article class="entry post clearfix preownedSearch">
<h2 class="et_pt_portfolio_title"><?php the_title(); ?></h2>
<?php
$index_postinfo = get_option('trim_postinfo1');
if ( $index_postinfo ){
echo '<p class="meta">';
et_postinfo_meta( $index_postinfo, get_option('trim_date_format'), esc_html__('0 comments','Trim'), esc_html__('1 comment','Trim'), '% ' . esc_html__('comments','Trim') );
echo '</p>';
}
?>
<div class="post-content clearfix">
<?php
$thumb = '';
$width = apply_filters('et_image_width',260);
$height = apply_filters('et_image_height',170);
$classtext = '';
$titletext = get_the_title();
$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
$thumb = $thumbnail["thumb"];
?>
<?php if ( '' != $thumb && 'on' == get_option('trim_thumbnails_index') ) { ?>
<div class="featured_box filter">
<a href="<?php the_permalink(); ?>">
<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
</a>
</div> <!-- end .featured_box -->
<?php } ?>
</div>
</article> <!-- end .post-->
<?php } endif; ?>
<?php
endwhile;
if (function_exists('wp_pagenavi')) { wp_pagenavi(); }
else { get_template_part('includes/navigation','entry'); }
else:
get_template_part('includes/no-results','entry');
endif;
if ( is_home() ) wp_reset_query(); ?>
Edit 2 Match
<?php
if ( is_home() ) {
$paged = get_query_var( 'page' ) ? get_query_var( 'page' ) : get_query_var( 'paged' );
$args = array(
'showposts' => (int) get_option('trim_homepage_posts'),
'paged' => $paged,
'category__not_in' => (array) get_option('trim_exlcats_recent'),
);
query_posts( apply_filters( 'et_home_args', $args ) );
}
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if ($post->post_name('stock-managers')) { ?>
<article class="entry post clearfix preownedSearch">
<h2 class="et_pt_portfolio_title"><?php the_title(); ?><?php the_meta(); ?></h2>
<?php
$index_postinfo = get_option('trim_postinfo1');
if ( $index_postinfo ){
echo '<p class="meta">';
et_postinfo_meta( $index_postinfo, get_option('trim_date_format'), esc_html__('0 comments','Trim'), esc_html__('1 comment','Trim'), '% ' . esc_html__('comments','Trim') );
echo '</p>';
}
?>
<div class="post-content clearfix">
<?php
$thumb = '';
$width = apply_filters('et_image_width',260);
$height = apply_filters('et_image_height',170);
$classtext = '';
$titletext = get_the_title();
$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
$thumb = $thumbnail["thumb"];
?>
<?php if ( '' != $thumb && 'on' == get_option('trim_thumbnails_index') ) { ?>
<div class="featured_box filter">
<a href="<?php the_permalink(); ?>">
<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
</a>
</div> <!-- end .featured_box -->
<?php } ?>
</div>
</article> <!-- end .post-->
<?php else : ?>
<article class="entry post clearfix preownedSearch">
<h2 class="et_pt_portfolio_title"><?php the_title(); ?></h2>
<?php
$index_postinfo = get_option('trim_postinfo1');
if ( $index_postinfo ){
echo '<p class="meta">';
et_postinfo_meta( $index_postinfo, get_option('trim_date_format'), esc_html__('0 comments','Trim'), esc_html__('1 comment','Trim'), '% ' . esc_html__('comments','Trim') );
echo '</p>';
}
?>
<div class="post-content clearfix">
<?php
$thumb = '';
$width = apply_filters('et_image_width',260);
$height = apply_filters('et_image_height',170);
$classtext = '';
$titletext = get_the_title();
$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
$thumb = $thumbnail["thumb"];
?>
<?php if ( '' != $thumb && 'on' == get_option('trim_thumbnails_index') ) { ?>
<div class="featured_box filter">
<a href="<?php the_permalink(); ?>">
<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
</a>
</div> <!-- end .featured_box -->
<?php } ?>
</div>
</article> <!-- end .post-->
<?php endif; ?>
<?php
endwhile;
if (function_exists('wp_pagenavi')) { wp_pagenavi(); }
else { get_template_part('includes/navigation','entry'); }
else:
get_template_part('includes/no-results','entry');
endif;
if ( is_home() ) wp_reset_query(); ?>
Your php Syntax is wrong.
PHP Syntax Check: Parse error: syntax error, unexpected 'endif' (T_ENDIF) in your code on line 7 <?php } endif;?> PHP Syntax Check: Errors parsing your code
With removing endif;you're good to go
<?php if (is_page('staff')) { ?>
<article class="entry post clearfix">
<-- Title / Thumbnail / Price / Description coding -->
</article>
<?php } else { ?>
<article class="entry post clearfix">
<-- Title / Thumbnail / Description coding -->
</article>
<?php } ?>
Learn more about PHP's Alternativ syntax
See explanation of using if(condition){}and if(condition):endif; at this answer
Edit:
If you're using is_page within the Loop, it'll be allways false /see Source.
Instead you could compare a chosen value (here it's staff) to any other field of your current post/page.
<?php if ( $post->post_name=='staff' ) { ?>
<article class="entry post clearfix">
<-- Title / Thumbnail / Price / Description coding -->
</article>
<?php } else { ?>
<article class="entry post clearfix">
<-- Title / Thumbnail / Description coding -->
</article>
<?php } ?>
Edit No.2:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if ($post->post_name('stock-managers')) { ?>
<article class="entry post clearfix preownedSearch">
</article> <!-- end .post-->
<?php else : ?>
<article class="entry post clearfix preownedSearch">
</article> <!-- end .post-->
<?php endif; ?>
<?php
endwhile;
?>

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(); ?>

WordPress sticky post not showing

In my Index.php template file I have the following code which should show a featured post if it's sticky and then loop through the remaining posts below. However on the second loop shows anything and the sticky post does not appear...
The post has definitely been made sticky and second loop has successfully hidden it but the first loop just doesn't acknowledge it :/ it's not set to private and is marked as published.
Can anyone see any issues with the code? Thanks
<?php get_header(); ?>
<div class="clearfix">
<?php if(is_home()) { //if home then show the featured post and others ?>
<div class="main-column">
<?php
$sticky = get_option( 'sticky_posts' );
$sticky_query = new WP_Query( 'p=' . $sticky[0] );
// The Loop
while ( $sticky_query->have_posts() ) : $sticky_query->the_post(); ?>
<div class="featured">
<article class="clearfix">
<h2><?php echo $post->post_title ?></h2>
<p class="who-when">by <?php echo get_the_author_meta('first_name'); ?> <?php echo get_the_author_meta('last_name') ?> on <?php echo get_the_date() ?> </p>
<?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
echo '<a href="'.get_permalink().'">';
the_post_thumbnail();
echo '</a>';
} else {
echo '<img src="'. get_bloginfo('template_directory') .'/images/thumb-placeholder.png" alt="Blog thumbnail" />';
}?>
<p><?php the_excerpt_max_charlength(300) ?></p>
</article>
</div>
<?php endwhile; ?>
<div class="articles">
<?php $query = new WP_Query( array( 'post__not_in' => get_option( 'sticky_posts' ), 'posts_per_page' => 10 ) );
$count = 0;
while ( $query->have_posts() ) : $query->the_post();
$count++; ?>
<div <?php if($count % 2 == 0) echo 'class="no-margin"' ?>>
<article>
<h2><?php echo $post->post_title ?></h2>
<p class="who-when">by <?php echo get_the_author_meta('first_name'); ?> <?php echo get_the_author_meta('last_name') ?> on <?php echo get_the_date() ?> </p>
<?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
echo '<a href="'.get_permalink().'">';
the_post_thumbnail();
echo '</a>';
} else {
echo '<img src="'. get_bloginfo('template_directory') .'/images/thumb-placeholder.png" alt="Blog thumbnail" />';
}?>
<p><?php the_excerpt_max_charlength(150) ?></p>
</article>
</div>
<?php if($count % 2 == 0) echo '<hr/>' ?>
<?php endwhile; ?>
</div>
<?php }else if(is_search() || is_category || is_tag()){ //if other than home (search, tag, category) then show normal list (no featured style) ?>
<div class="main-column search">
<?php
$count = 0;
if(is_search()){
echo '<h1>Search Results</h1>';
} elseif(is_author()){ ?>
<?php $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author)); ?>
<h1><?php echo $curauth->user_firstname; ?> <?php echo $curauth->user_lastname; ?></h1>
<div class="archive-meta">
<p><?php echo $curauth->user_description; ?></p>
</div>
<?php } else if(is_category()){ ?>
<h1><?php single_cat_title( '', true ); ?></h1>
<?php
$category_description = category_description();
if ( ! empty( $category_description ) )
echo '<div class="archive-meta">' . $category_description . '</div>';
?>
<?php }else if (is_tag()){
echo '<h1>'.the_tag().'</h1>';
}
if ( have_posts() ) : while ( have_posts() ) : the_post();
$count++; ?>
<div>
<article>
<h2><?php echo $post->post_title ?></h2>
<p class="who-when">by <?php echo get_the_author_meta('first_name'); ?> <?php echo get_the_author_meta('last_name') ?> on <?php echo get_the_date() ?> </p>
<?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
echo '<a href="'.get_permalink().'">';
the_post_thumbnail();
echo '</a>';
} else {
echo '<img src="'. get_bloginfo('template_directory') .'/images/thumb-placeholder.png" alt="Blog thumbnail" />';
}?>
<p><?php the_excerpt_max_charlength(300) ?></p>
</article>
</div>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
<?php } ?>
</div>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
Changing the code to:
$sticky_query = new WP_Query( 'p=' . $sticky[1] );
fixes the problem but I don't know why???

Resources