WP Template customizing - wordpress

i'm trying to change my single-post template ,But i can't the the_content Function.
Where should it be ?
<div class="single-post-content clearfix">
<?php
the_content(esc_html__('Read more!', 'voyager'));
wp_link_pages(array('before' => '<div class="page-link">' . esc_html__('Pages', 'voyager') . ': ', 'after' => '</div>'));
?>
</div>
Update 1 the entire code
<?php
/**
* The template for displaying all single posts and attachments
*/
get_header();
$pf = get_post_format();
$voyager_single_post_sidebar_under = cstheme_option( 'single_post_sidebar_under' );
$single_post_sidebar = cstheme_option( 'single_post_sidebar' );
$single_post_sidebar_position = '';
if( $single_post_sidebar == 'left-sidebar' ) {
$single_post_sidebar_position = 'pull-right';
}
/* ADD 1 view for this post */
$post_views = (get_post_meta(get_the_ID(), "post_views", true) > 0 ? get_post_meta(get_the_ID(), "post_views", true) : "0");
update_post_meta(get_the_ID(), "post_views", (int)$post_views + 1);
$single_post_featured_img = cstheme_option( 'single_post_featured_img' );
$featured_image_url = wp_get_attachment_url(get_post_thumbnail_id());
?>
<div class="container">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="blog-single-wrap" class="<?php echo 'format-' . $pf . ' featured_img_' . $single_post_featured_img ?> clearfix">
<?php if( isset( $single_post_featured_img ) && $single_post_featured_img == 'fullwidth' ) { ?>
<div class="single_post_header">
<div class="featured_img_bg" style="background-image:url(<?php echo $featured_image_url; ?>);"></div>
<div class="single_post_meta_category"><?php the_category(', '); ?></div>
<h2 class="single-post-title"><?php the_title(); ?></h2>
<div class="single_post_header_bottom">
<div class="single_post_meta">
<span class="post-meta-date"><?php the_time('M j, Y') ?></span>
<span class="post_meta_views"><i class="fa fa-eye"></i> <span><?php echo (get_post_meta(get_the_ID(), "post_views", true) > 0 ? get_post_meta(get_the_ID(), "post_views", true) : "0"); ?></span></span>
<span class="post-meta-likes"><?php echo cstheme_likes(); ?></span>
<span class="post-meta-comments"><i class="fa fa-comments"></i><?php echo get_comments_number(get_the_ID()); ?></span>
</div>
</div>
</div>
<?php if ( $single_post_sidebar != 'no-sidebar' && $voyager_single_post_sidebar_under != 'next' && ( $pf != 'image' && $pf != 'standard' ) ) { ?>
<div class="post_format_content mb55 text-center">
<?php get_template_part( 'framework/post-format/post', get_post_format() ); ?>
</div>
<?php } ?>
<?php } else { ?>
<div class="single_post_header">
<div class="single_post_meta_category"><?php the_category(', '); ?></div>
<h2 class="single-post-title"><?php the_title(); ?></h2>
<div class="row single_post_header_bottom">
<div class="col-md-4 text-left">
<div class="single_post_meta_author"><?php echo esc_html__('posted by', 'voyager') ?> <a class="heading_font" href="<?php echo esc_url( get_author_posts_url(get_the_author_meta('ID')) ); ?>"><?php echo get_the_author_meta('display_name') ?></a></div>
</div>
<div class="col-md-4">
<div class="single_post_meta">
<span class="post-meta-date"><?php the_time('M j, Y') ?></span>
<span class="post_meta_views"><i class="fa fa-eye"></i> <span><?php echo (get_post_meta(get_the_ID(), "post_views", true) > 0 ? get_post_meta(get_the_ID(), "post_views", true) : "0"); ?></span></span>
<span class="post-meta-likes"><?php echo cstheme_likes(); ?></span>
<span class="post-meta-comments"><i class="fa fa-comments"></i><?php echo get_comments_number(get_the_ID()); ?></span>
</div>
</div>
<div class="col-md-4 text-right">
<?php if(cstheme_option('single_post_sharebox') != 0) { get_template_part( 'templates/blog/sharebox' ); } ?>
</div>
</div>
</div>
<?php if ( $voyager_single_post_sidebar_under != 'next' ) { ?>
<div class="post_format_content mb55 text-center">
<?php get_template_part( 'framework/post-format/post', get_post_format() ); ?>
</div>
<?php } ?>
<?php } ?>
<?php if( $single_post_sidebar != 'no-sidebar' ) { ?>
<div class="row">
<div class="col-md-9 <?php echo $single_post_sidebar_position; ?>">
<?php } ?>
<?php if( isset( $single_post_featured_img ) && ( $single_post_featured_img == 'fullwidth' ) && ( $pf != 'image' && $pf != 'standard' ) && $voyager_single_post_sidebar_under != 'under' ) { ?>
<div class="post_format_content mb55 text-center">
<?php get_template_part( 'framework/post-format/post', $pf ); ?>
</div>
<?php } else if ( $single_post_featured_img != 'fullwidth' && $voyager_single_post_sidebar_under != 'under' ) { ?>
<div class="post_format_content mb55 text-center">
<?php get_template_part( 'framework/post-format/post', get_post_format() ); ?>
</div>
<?php } ?>
<div class="single-post-content clearfix">
<?php
the_content(esc_html__('Read more!', 'voyager'));
wp_link_pages(array('before' => '<div class="page-link">' . esc_html__('Pages', 'voyager') . ': ', 'after' => '</div>'));
?>
</div>
<div class="posts_nav_link"><?php posts_nav_link(); ?></div>
<div class="single_sharebox_wrap clearfix">
<div class="single_post_meta_tags pull-left">
<?php if( has_tag() ) {
the_tags('','', '');
} ?>
</div>
<div class="pull-right">
<?php if(cstheme_option('single_post_sharebox') != 0) { get_template_part( 'templates/blog/sharebox' ); } ?>
</div>
</div>
<?php if(cstheme_option('single_post_authorinfo') != 0) { get_template_part( 'templates/blog/authorinfo' ); } ?>
<?php if(cstheme_option('single_post_navigation') != 0) { ?>
<div class="single_post_nav clearfix">
<?php
$prev_post = get_adjacent_post(false, '', true);
$next_post = get_adjacent_post(false, '', false);
if($prev_post){
$post_url = get_permalink($prev_post->ID);
echo '<div class="pull-left"><p class="heading_font"><i class="fa fa-chevron-left"></i>' . esc_html__('Previous','voyager') . '</p><b>' . $prev_post->post_title . '</b></div>';
}
if($next_post) {
$post_url = get_permalink($next_post->ID);
echo '<div class="pull-right text-right"><p class="heading_font">' . esc_html__('Next','voyager') . '<i class="fa fa-chevron-right"></i></p><b>' . $next_post->post_title . '</b></div>';
}
?>
</div>
<?php } ?>
<?php if( $single_post_sidebar != 'no-sidebar' ) { ?>
</div>
<div class="col-md-3">
<?php get_sidebar(); ?>
</div>
</div>
<?php } ?>
<?php if(cstheme_option('single_post_relatedposts') != 0) { get_template_part('templates/blog/related-posts'); } ?>
<?php
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
?>
</div>
<?php endwhile; endif; ?>
</div>
<?php get_footer(); ?>
The page is enter link description here

Related

WP_Query don't show pagination for frontpage

Can someone take a look on my code ? I can't figure why post pagination not showing, although when I type page/2 in browser url, the list of post works properly.
<?php
/**
* Template Name: Frontpage
*
* #package Bootstrap Canvas WP
* #since Bootstrap Canvas WP 1.0
*/
get_header(); ?>
<?php
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$args = array('post_type' => 'post', 'orderby' => 'ASC', 'paged' => $paged, 'posts_per_page' => 9 );
$loop = new WP_Query($args);
$count = 0;
?>
<div class="row">
<div class="col-sm-12 blog-main pt-3 pb-5">
<?php if ($loop->have_posts()) : while ($loop->have_posts()) : $loop->the_post(); ?>
<?php $count++ ?>
<?php $date_format = get_option( 'date_format' ); ?>
<?php if($count == 1) : ?>
<div class="row">
<?php endif ?>
<?php if(($count == 1) || ($count == 9)) : ?>
<div id="post-<?php the_ID(); ?>" class="col-sm-12 col-md-8 col-xl-8 np-big">
<?php endif ?>
<?php if($count == 2 || $count == 7) : ?>
<div class="col-sm-12 col-md-4 col-xl-4 np-small">
<?php endif ?>
<?php if($count > 1 && $count < 4 || $count > 6 && $count <= 9 ) : ?>
<div id="post-<?php the_ID(); ?>" class="col-sm-12 col-md-12 col-xl-12">
<?php elseif ($count >= 4) : ?>
<?php if ($count == 5) : ?>
<div id="post-<?php the_ID(); ?>" class="col-sm-12 col-md-4 col-xl-4 np-small">
<?php else : ?>
<div id="post-<?php the_ID(); ?>" class="col-sm-12 col-md-4 col-xl-4">
<?php endif ?>
<?php endif ?>
<a href="<?php echo get_the_permalink(); ?>"><div class="post-bg-home" style="background: linear-gradient( rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.7) ), url(<?php echo get_the_post_thumbnail_url() ?>);">
<h2><?php echo get_the_title(); ?></h2>
<p class="data"><?php echo the_time( $date_format ); ?></p>
</div></a>
<?php if($count == 1) : ?>
</div>
<?php endif ?>
<?php if($count > 1 ) : ?>
</div>
<?php endif ?>
<?php if($count == 3 || $count == 8) : ?>
</div>
<?php endif ?>
<?php endwhile; ?>
</div>
</div>
<div class="paginacja col-sm-12 col-md-12 col-xl-12">
<hr class="paginacja-hr">
<?php the_posts_pagination(); ?>
</div>
<?php else : ?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1>Not Found</h1>
</div>
<?php endif; ?>
</div><!-- /.blog-main -->
</div><!-- /.row -->
<?php get_footer(); ?>
Try this code
<?php
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$args = array('post_type' => 'post', 'orderby' => 'ASC', 'paged' => $paged, 'posts_per_page' => 3 );
$loop = new WP_Query($args);
$count = 0;
?>
<div class="row">
<div class="col-sm-12 blog-main pt-3 pb-5">
<?php if ($loop->have_posts()) : while ($loop->have_posts()) : $loop->the_post(); ?>
<?php $count++ ?>
<?php $date_format = get_option( 'date_format' ); ?>
<?php if($count == 1) : ?>
<div class="row">
<?php endif ?>
<?php if(($count == 1) || ($count == 9)) : ?>
<div id="post-<?php the_ID(); ?>" class="col-sm-12 col-md-8 col-xl-8 np-big">
<?php endif ?>
<?php if($count == 2 || $count == 7) : ?>
<div class="col-sm-12 col-md-4 col-xl-4 np-small">
<?php endif ?>
<?php if($count > 1 && $count < 4 || $count > 6 && $count <= 9 ) : ?>
<div id="post-<?php the_ID(); ?>" class="col-sm-12 col-md-12 col-xl-12">
<?php elseif ($count >= 4) : ?>
<?php if ($count == 5) : ?>
<div id="post-<?php the_ID(); ?>" class="col-sm-12 col-md-4 col-xl-4 np-small">
<?php else : ?>
<div id="post-<?php the_ID(); ?>" class="col-sm-12 col-md-4 col-xl-4">
<?php endif ?>
<?php endif ?>
<a href="<?php echo get_the_permalink(); ?>"><div class="post-bg-home" style="background: linear-gradient( rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.7) ), url(<?php echo get_the_post_thumbnail_url() ?>);">
<h2><?php echo get_the_title(); ?></h2>
<p class="data"><?php echo the_time( $date_format ); ?></p>
</div></a>
<?php if($count == 1) : ?>
</div>
<?php endif ?>
<?php if($count > 1 ) : ?>
</div>
<?php endif ?>
<?php if($count == 3 || $count == 8) : ?>
</div>
<?php endif ?>
<?php endwhile; ?>
</div>
</div>
<div class="paginacja col-sm-12 col-md-12 col-xl-12">
<hr class="paginacja-hr">
<?php $GLOBALS['wp_query']->max_num_pages = $loop->max_num_pages;
the_posts_pagination( array(
'mid_size' => 1,
'prev_text' => __( 'Back', 'green' ),
'next_text' => __( 'Next', 'green' ),
'screen_reader_text' => __( 'Posts navigation' )
) ); ?>
</div>
<?php else : ?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1>Not Found</h1>
</div>
<?php endif; ?>
</div><!-- /.blog-main -->
</div><!-- /.row -->
<?php get_footer(); ?>

ACF Pagination not working when the_content is present

I have this custom template in Wordpress which includes a script that paginates ACF fields. Here is the source code:
<?php get_header(); ?>
<div class="container">
<div class="row">
<div class="col-xs-12">
<h1 class="pagetitle"><?php the_title(); ?></h1>
</div> <!-- col -->
</div> <!-- row -->
</div> <!-- container -->
<?php
if( get_query_var('page') ) {
$page = get_query_var( 'page' );
} else {
$page = 1;
}
$row = 0;
$files_per_page = 30; // How many images to display on each page
$files = get_field( 'fisier' );
$total = count( $files );
$pages = ceil( $total / $files_per_page );
$min = ( ( $page * $files_per_page ) - $files_per_page ) + 1;
$max = ( $min + $files_per_page ) - 1;
?>
<div class="container">
<div class="row">
<div class="col-md-8">
<section id="content">
<div class="wrapper">
<?php while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php if( have_rows('fisier') ): ?>
<div class="article-files">
<h4>Files</h4>
<div class="row">
<?php while ( have_rows('fisier') ) : the_row();
$row++;
if($row < $min) { continue; }
if($row > $max) { break; }
?>
<div class="col-xs-12 file">
<?php $x = 0; ?>
<?php $file = get_sub_field('link'); if( $file ): ?>
<i class="fa fa-angle-right" aria-hidden="true"></i> <?php the_sub_field('nume_fisier'); ?>
<div class="file-description"><?php the_sub_field('descriere'); ?></div>
<?php $x = 1; ?>
<?php endif; ?>
<?php $file = get_sub_field('fisier_intern'); if( $file ): ?>
<i class="fa fa-angle-right" aria-hidden="true"></i> <?php the_sub_field('nume_fisier'); ?>
<div class="file-description"><?php the_sub_field('descriere'); ?></div>
<?php $x = 1; ?>
<?php endif; ?>
<?php if( $x == 0 ): ?>
<i class="fa fa-angle-right" aria-hidden="true"></i> <?php the_sub_field('nume_fisier'); ?>
<div class="file-description"><?php the_sub_field('descriere'); ?></div>
<?php $x = 1; ?>
<?php endif; ?>
</div>
<?php endwhile; ?>
</div>
<div class="file-pagination">
<?php
echo paginate_links( array(
'base' => get_permalink() . '%#%' . '/',
'format' => '?page=%#%',
'current' => $page,
'show_all' => false,
'prev_text' => __('«'),
'next_text' => __('»'),
'total' => $pages
));
?>
</div> <!-- file-pagination -->
</div>
<?php endif; ?>
</div> <!-- wrapper -->
</section> <!-- content -->
</div> <!-- col -->
<div class="col-md-4">
<aside id="sidebar">
<?php get_sidebar(); ?>
</aside> <!-- aside -->
</div> <!-- col -->
</div> <!-- row -->
</div> <!-- container -->
<?php get_footer(); ?>
The code above doesn't display the pagination links but if I remove this part:
<?php while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
Everything works perfectly. Any idea about how I can fix this?
Thanks
Solved the problem! I had to move the pagination settings after the_content() as shown below:
<?php get_header(); ?>
<div class="container">
<div class="row">
<div class="col-xs-12">
<h1 class="pagetitle"><?php the_title(); ?></h1>
</div> <!-- col -->
</div> <!-- row -->
</div> <!-- container -->
<div class="container">
<div class="row">
<div class="col-md-8">
<section id="content">
<div class="wrapper">
<?php while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php
if( get_query_var('page') ) {
$page = get_query_var( 'page' );
} else {
$page = 1;
}
$row = 0;
$files_per_page = 30; // How many images to display on each page
$files = get_field( 'fisier' );
$total = count( $files );
$pages = ceil( $total / $files_per_page );
$min = ( ( $page * $files_per_page ) - $files_per_page ) + 1;
$max = ( $min + $files_per_page ) - 1;
?>
<?php if( have_rows('fisier') ): ?>
<div class="article-files">
<h4>Files</h4>
<div class="row">
<?php while ( have_rows('fisier') ) : the_row();
$row++;
if($row < $min) { continue; }
if($row > $max) { break; }
?>
<div class="col-xs-12 file">
<?php $x = 0; ?>
<?php $file = get_sub_field('link'); if( $file ): ?>
<i class="fa fa-angle-right" aria-hidden="true"></i> <?php the_sub_field('nume_fisier'); ?>
<div class="file-description"><?php the_sub_field('descriere'); ?></div>
<?php $x = 1; ?>
<?php endif; ?>
<?php $file = get_sub_field('fisier_intern'); if( $file ): ?>
<i class="fa fa-angle-right" aria-hidden="true"></i> <?php the_sub_field('nume_fisier'); ?>
<div class="file-description"><?php the_sub_field('descriere'); ?></div>
<?php $x = 1; ?>
<?php endif; ?>
<?php if( $x == 0 ): ?>
<i class="fa fa-angle-right" aria-hidden="true"></i> <?php the_sub_field('nume_fisier'); ?>
<div class="file-description"><?php the_sub_field('descriere'); ?></div>
<?php $x = 1; ?>
<?php endif; ?>
</div>
<?php endwhile; ?>
</div>
<div class="file-pagination">
<?php
echo paginate_links( array(
'base' => get_permalink() . '%#%' . '/',
'format' => '?page=%#%',
'current' => $page,
'show_all' => false,
'prev_text' => __('«'),
'next_text' => __('»'),
'total' => $pages
));
?>
</div> <!-- file-pagination -->
</div>
<?php endif; ?>
</div> <!-- wrapper -->
</section> <!-- content -->
</div> <!-- col -->
<div class="col-md-4">
<aside id="sidebar">
<?php get_sidebar(); ?>
</aside> <!-- aside -->
</div> <!-- col -->
</div> <!-- row -->
</div> <!-- container -->
<?php get_footer(); ?>

wordpress reading static page display posts orderd by date desc

Hello i'm kinda new to wordpress and i struggle making a static page displaying posts order by date desc. They are displayed after title and i don't manage to make it work as it should. Here is my page code:
<?php
/*
Template Name: Full Width
*/
?>
<?php
global $wp_query;
$id = $wp_query->get_queried_object_id();
$sidebar = get_post_meta($id, "qode_show-sidebar", true);
$enable_page_comments = false;
if(get_post_meta($id, "qode_enable-page-comments", true) == 'yes') {
$enable_page_comments = true;
}
if(get_post_meta($id, "qode_page_background_color", true) != ""){
$background_color = get_post_meta($id, "qode_page_background_color", true);
}else{
$background_color = "";
}
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
else { $paged = 1; }
?>
<?php get_header(); ?>
<?php if(get_post_meta($id, "qode_page_scroll_amount_for_sticky", true)) { ?>
<script>
var page_scroll_amount_for_sticky = <?php echo get_post_meta($id, "qode_page_scroll_amount_for_sticky", true); ?>;
</script>
<?php } ?>
<?php get_template_part( 'title' ); ?>
<?php
$revslider = get_post_meta($id, "qode_revolution-slider", true);
if (!empty($revslider)){ ?>
<div class="q_slider"><div class="q_slider_inner">
<?php echo do_shortcode($revslider); ?>
</div></div>
<?php
}
?>
<div class="full_width"<?php if($background_color != "") { echo " style='background-color:". $background_color ."'";} ?>>
<div class="full_width_inner">
<?php if(($sidebar == "default")||($sidebar == "")) : ?>
<?php if (have_posts()) :
while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php
$args_pages = array(
'before' => '<p class="single_links_pages">',
'after' => '</p>',
'pagelink' => '<span>%</span>'
);
wp_link_pages($args_pages); ?>
<?php
if($enable_page_comments){
?>
<div class="container">
<div class="container_inner">
<?php
comments_template('', true);
?>
</div>
</div>
<?php
}
?>
<?php endwhile; ?>
<?php endif; ?>
<?php elseif($sidebar == "1" || $sidebar == "2"): ?>
<?php if($sidebar == "1") : ?>
<div class="two_columns_66_33 clearfix grid2">
<div class="column1">
<?php elseif($sidebar == "2") : ?>
<div class="two_columns_75_25 clearfix grid2">
<div class="column1">
<?php endif; ?>
<?php if (have_posts()) :
while (have_posts()) : the_post(); ?>
<div class="column_inner">
<?php the_content(); ?>
<?php
$args_pages = array(
'before' => '<p class="single_links_pages">',
'after' => '</p>',
'pagelink' => '<span>%</span>'
);
wp_link_pages($args_pages); ?>
<?php
if($enable_page_comments){
?>
<div class="container">
<div class="container_inner">
<?php
comments_template('', true);
?>
</div>
</div>
<?php
}
?>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
<div class="column2"><?php get_sidebar();?></div>
</div>
<?php elseif($sidebar == "3" || $sidebar == "4"): ?>
<?php if($sidebar == "3") : ?>
<div class="two_columns_33_66 clearfix grid2">
<div class="column1"><?php get_sidebar();?></div>
<div class="column2">
<?php elseif($sidebar == "4") : ?>
<div class="two_columns_25_75 clearfix grid2">
<div class="column1"><?php get_sidebar();?></div>
<div class="column2">
<?php endif; ?>
<?php if (have_posts()) :
while (have_posts()) : the_post(); ?>
<div class="column_inner">
<?php the_content(); ?>
<?php
$args_pages = array(
'before' => '<p class="single_links_pages">',
'after' => '</p>',
'pagelink' => '<span>%</span>'
);
wp_link_pages($args_pages); ?>
<?php
if($enable_page_comments){
?>
<div class="container">
<div class="container_inner">
<?php
comments_template('', true);
?>
</div>
</div>
<?php
}
?>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
</div>
</div>
<?php get_footer(); ?>
Try changing your loop like this::
$args = array(
'orderby' => 'date',
'order' => 'DESC',
);
$query1 = new WP_Query( $args );
<?php if ($query1->have_posts()) :
while ($query1->have_posts()) : $query1->the_post(); ?>
<div class="column_inner">
<?php the_content(); ?>
<?php
$args_pages = array(
'before' => '<p class="single_links_pages">',
'after' => '</p>',
'pagelink' => '<span>%</span>'
);
wp_link_pages($args_pages); ?>
<?php
if($enable_page_comments){
?>
<div class="container">
<div class="container_inner">
<?php
comments_template('', true);
?>
</div>
</div>
<?php
}
?>
</div>
<?php endwhile; ?>
<?php endif; ?>

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

Resources