I am trying to have the layout of my posts on my search results be 2 posts per line. Right now there is 1 post, so I am trying to add in 'col-sm-6 col-md-6' to my search.php file. However, every time I try to add it in nothing changes. Does anyone have any solutions?
search.php
<?php get_header(); ?>
<div id="page">
<div class="column span-9 first" id="maincontent">
<div class="content">
<?php if (have_posts()) : ?>
<form role="search" method="get" class="search-form-search form-inline-search" action="">
<div class="input-group-search">
<input type="search" value="" name="s" class="input-sm-search search-field-search form-control-search" placeholder="<?php echo $s ?>">
</div>
</form>
<div class="clear"></div>
<?php while (have_posts()) : the_post(); ?>
<div class="search-post" id="post-<?php the_ID(); ?>">
<?php the_post_thumbnail('full', array('class' => 'medium-front-thumbnail')); ?>
<div class="front-page-date"><?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?></div>
<h2><a class="front-page-post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
<div class="front-page-post-info">
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
<?php get_template_part( 'front-shop-the-post' ); ?>
<?php get_template_part( 'share-buttons' ); ?>
<div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div>
</div>
</div>
<?php endwhile; ?>
<?php else : ?>
<h2 class="center">No posts found. Try a different search?</h2>
<?php include (TEMPLATEPATH . '/searchform.php'); ?>
<?php endif; ?>
</div> <!-- /content -->
</div> <!-- /maincontent-->
</div> <!-- /page -->
<?php get_footer(); ?>
Here is another version of a search.php I have been playing around with. However, with this one the web page doesn't show up.
<?php
get_header();
$the_query = new WP_Query( [
'posts_per_page' => 15,
'paged' => get_query_var('paged', 1)
] );
if ( $the_query->have_posts() ) { ?>
<div id="ajax">
<?php
while ( $the_query->have_posts() ) { $the_query->the_post(); ?>
<div class="row">
<article <?php post_class( 'col-sm-6 col-md-6' ); ?>>
<div class="large-front-container">
<?php the_post_thumbnail('full', array('class' => 'large-front-thumbnail')); ?>
</div>
<div class="front-page-date"><?php echo str_replace('mins', 'minutes', human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'); ?></div>
<h2><a class="front-page-post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
<div class="front-page-post-info">
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
<?php get_template_part( 'front-shop-the-post' ); ?>
<?php get_template_part( 'share-buttons' ); ?>
<div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div>
</div>
</article>
</div>
<?php if(get_query_var('paged') < $the_query->max_num_pages) {
}
}
elseif (!get_query_var('paged') || get_query_var('paged') == '1') {
echo '<p>Sorry, no posts matched your criteria.</p>';
}
wp_reset_postdata();
get_footer();
Related
I am trying to paginate archived post in WordPress when I click "next button" but it doesn't work. Please guide me to do it in a simple way. My code is given below:
<div class="grid-wrapper ">
<?php $args = array(
'posts_per_page' => 3,
'paged' => $paged
);
$the_query = new WP_Query($args);
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="inner-blog">
<div class="row">
<div class="col-lg-4 col-md-2">
<div class="post-thumbnail">
<img class="img-fluid" src="<?php the_post_thumbnail_url(); ?>">
</div>
</div>
<div class="col-lg-8 col-md-9">
<h2 class="post-title"><?php the_title();?></h2>
<?php the_excerpt(); ?>
</div>
</div>
</div>
<?php endwhile; ?>
<?php else : ?>
<?php wp_reset_postdata(); ?>
<p><?php __('No News'); ?></p>
<?php endif; ?>
<ul class="pagination pull-right">
<li><?php echo get_next_posts_link( 'Next Page', $the_query->max_num_pages ); ?> »</li>
<li><?php echo get_previous_posts_link( 'Previous Page' ); ?></li>
</ul>
</div>
</div>
I am using Advanced Custom Fields in order to show different banner image for each language with qTranslate plugin.
<?php get_header(); ?>
<section id="linea">
<?php if(qtrans_getLanguage()=='en') {
?>
<img src="<?php the_field('banner')?>">
<?php }
else if(qtrans_getLanguage()=='es') {?>
<img src="<?php the_field('banner_image_es')?>">
<?php }?>
</section>
<section id="categoria1">
<div class="pagewidth clearfix">
<div class="breadcrumbs" xmlns:v="http://rdf.data-vocabulary.org/#">
<?php if(function_exists('bcn_display'))
{
bcn_display();
}?>
</div>
<h1 class="categoria-title"><span class="left"></span><b><?php single_term_title(); ?></b><span class="right"></span></h1>
</div>
</section>
<section id="categoria2">
<div class="pagewidth clearfix">
<ul class="product-list">
<?php $my_query = new WP_Query(array('post_type' => 'productos','taxonomy'=>'categoria','term'=>'conformink-cunero-luxy','paged' => get_query_var('paged'))); ?>
<?php while ( $my_query->have_posts() ) : $my_query->the_post();?>
<li>
<h5><a style="color: #f79646;" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
<a class="verdetalle" href="<?php the_permalink(); ?>"><?php if( qtranxf_getLanguage() == 'es' ){ ?>Ver detalle<?php }else { ?>See More<?php } ?></a>
<!-- <p><?php echo substr(get_the_excerpt(), 0,120); ?></p> -->
<?php the_post_thumbnail('thumbnail'); ?>
</li>
<?php
endwhile;
wp_pagenavi( array( 'query' => $my_query ) );?>
<?php wp_reset_query(); ?>
</ul>
</div>
</section>
<?php get_footer(); ?>
The problem is that it keep showing the image of only one post on all templates, although I have already assigned the different images to different categories.
Can anyone help?
If you want the banner to show up on every post you'll have to move the section inside the loop:
<section id="categoria2">
<div class="pagewidth clearfix">
<ul class="product-list">
<?php
$my_query = new WP_Query(array('post_type' => 'productos','taxonomy'=>'categoria','term'=>'conformink-cunero-luxy','paged' => get_query_var('paged')));
if ( $my_query->have_posts() ) : while ( $my_query->have_posts() ) : $my_query->the_post();?>
<li>
<section id="linea">
<?php if ( qtrans_getLanguage() == 'en' ) : ?>
<img src="<?php the_field('banner'); ?>">
<?php elseif ( qtrans_getLanguage() == 'es' ) : ?>
<img src="<?php the_field('banner_image_es'); ?>">
<?php endif; ?>
</section>
<h5><a style="color: #f79646;" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
<a class="verdetalle" href="<?php the_permalink(); ?>"><?php if( qtranxf_getLanguage() == 'es' ){ ?>Ver detalle<?php }else { ?>See More<?php } ?></a>
<!-- <p><?php echo substr(get_the_excerpt(), 0,120); ?></p> -->
<?php the_post_thumbnail('thumbnail'); ?>
</li>
<?php
endwhile; endif;
wp_pagenavi( array( 'query' => $my_query ) );
wp_reset_query(); ?>
</ul>
</div>
</section>
I'm having trouble being able to insert an ad after every 3rd post in Wordpress. This is the code in the theme. I know I need a counter and an if statement.
<section id="recentnews">
<div class="headline"><h2><?php _e( 'Recent News', THB_THEME_NAME ); ?></h2></div>
<?php $args = array(
'posts_per_page' => '5',
'offset' => '5',
'ignore_sticky_posts' => '1'
);
?>
<?php $query = new WP_Query($args); ?>
<?php if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
<article class="post">
<div class="row">
<div class="five columns">
<div class="post-gallery">
<?php the_post_thumbnail('recent'); ?>
<?php echo thb_DisplayImageTag(get_the_ID()); ?>
</div>
</div>
<div class="seven columns">
<div class="post-title">
<aside><?php echo thb_DisplaySingleCategory(false); ?></aside>
<h2><?php the_title(); ?></h2>
</div>
<div class="post-content">
<p><?php echo ShortenText(get_the_excerpt(), 150); ?></p>
<?php echo thb_DisplayPostMeta(true,true,true,false); ?>
</div>
</div>
</div>
</article>
<?php endwhile; else: ?>
<article>
<?php _e( 'Please select tags from your Theme Options Page', THB_THEME_NAME ); ?>
</article>
<?php endif; ?>
<a id="loadmore" href="#" data-loading="<?php _e( 'Loading ...', THB_THEME_NAME ); ?>" data-nomore="<?php _e( 'No More Posts to Show', THB_THEME_NAME ); ?>" data-count="5" data-action="thb_ajax_home"><?php _e( 'Load More', THB_THEME_NAME ); ?></a>
</section>
I could show you what I tried and failed at, just to show that I tried. Don't give me negative points for that please.
<section id="recentnews">
<div class="headline"><h2><?php _e( 'Recent News', THB_THEME_NAME ); ?></h2></div>
<?php $args = array(
'posts_per_page' => '5',
'offset' => '5',
'ignore_sticky_posts' => '1'
);
?>
<?php $query = new WP_Query($args); ?>
<?php $i = 1; if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); if($i == 1) : ?>
<article class="post">
<div class="row">
<div class="five columns">
<div class="post-gallery">
<?php the_post_thumbnail('recent'); ?>
<?php echo thb_DisplayImageTag(get_the_ID()); ?>
</div>
</div>
<div class="seven columns">
<div class="post-title">
<aside><?php echo thb_DisplaySingleCategory(false); ?></aside>
<h2><?php the_title(); ?></h2>
</div>
<div class="post-content">
<p><?php echo ShortenText(get_the_excerpt(), 150); ?></p>
<?php echo thb_DisplayPostMeta(true,true,true,false); ?>
</div>
</div>
</div>
</article>
<div class="clear"> </div>
<?php if ( $i == 3|| $i == 9 || $i == 15 ) : ?>
<?php if (function_exists ('adinserter')) echo adinserter (2); ?>
<div class="clear"> </div>
<?php endif; ?><?php endif; ?>
<?php $i++; ?>
<?php endwhile; else: ?>
<article>
<?php _e( 'Please select tags from your Theme Options Page', THB_THEME_NAME ); ?>
</article>
<?php endif; ?>
</section>
Thank you.
You're close. You'll want to increment your counter within the while loop (using $i++), and then use the modulus operator % to determine whether or not the counter is evenly divisible by 3:
<?php if ($query->have_posts()) : $i = 1; while ($query->have_posts()) : $query->the_post(); ?>
<!-- Article -->
<?php if ( $i % 3 == 0 ) : ?>
<!-- Advertisement Here -->
<?php endif; ?>
<?php $i++; endwhile; else: ?>
<!-- Display Notice -->
<?php endif; ?>
In my theme I have a blog page and a homepage (without blog loop). Now I would like to add some blog posts on my homepage (like most recent).
I am using the blog page as a template for the homepage ( I copied and renamed the original), wich works good. But I can't make any changes to it without changing the original blog page (the loop is called in an external php).
I Have no idea were to start.
This is the piece on the homepage calling the blog loop:
<?php if(have_posts()) : the_post(); ?>
<div id="main">
<div class="central-wrapper clearfix">
<div id="center" class="fullwidth">
<div id="content">
<?php if($gallery_select && $gallery_position == 1) : ?>
<?php codeus_gallery($gallery_select, $gallery_size, $gallery_style); ?>
<?php endif; ?>
<div class="inner">
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="pagination"><div class="page-links-title">' . __( 'Pages:', 'codeus' ) . '</div>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?>
<div class="bloghome">
<?php codeus_blog_list(); ?>
</div>
<?php if($quickfinder_position == 2) : ?>
<?php codeus_quickfinder($quickfinder_select); ?>
<?php endif; ?>
<?php if($portfolio_position == 2) : ?>
<?php codeus_portfolio(implode(',',$portfolio_select), $portfolio_size, $portfolio_count, $portfolio_filter, $portfolio_title); ?>
<?php endif; ?>
<?php if($gallery_select && $gallery_position == 3) : ?>
<?php codeus_gallery($gallery_select, $gallery_size, $gallery_style); ?>
<?php endif; ?>
</div>
</div><!-- #content -->
</div><!-- #center -->
</div><!-- .central-wrapper -->
</div><!-- #main -->
<?php endif; ?>
</div><!-- wrap end -->
And this is the piece in the external php called blog.php
<?php if($blog_loop->have_posts()) : ?>
<div class="blog_list">
<ul class="styled">
<?php while ( $blog_loop->have_posts() ) : $blog_loop->the_post(); ?>
<li class="clearfix">
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php $image_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'codeus_post_list_image'); ?>
<div class="comment-info">
<?php echo get_the_date('d'); ?>
<div class="date-month"><?php echo get_the_date('M'); ?></div>
</div>
<div class="post-info">
<h3><?php the_title(); ?></h3>
<?php if($image_url[0]) : ?>
<div class="post-image">
<div class="image wrap-box shadow middle">
<div class="shadow-left"></div><div class="shadow-right"> </div>
<img src=" <?php echo $image_url[0]; ?>" alt="<?php the_title(); ?>" />
</div>
</div>
<?php endif; ?>
<div class="text clearfix"><?php the_excerpt(); ?></div>
<?php codeus_author_info(get_the_ID()); ?>
</div>
</div>
</li>
<?php $post = $portfolio_posttemp; wp_reset_postdata(); ?>
<?php endwhile; ?>
</ul>
<?php codeus_pagination($page_num, $pages_count); ?>
</div>
<?php endif; ?>
Remember, I don't want to make changes in the original blog.php, because the normal blog page needs to work as it is now. I would like to make the blog work on the homepage also, but just with a maximum of 3 posts showing, perhaps of a certain category.
Help would be so welcome!!
I think I found a solution, I edited the homepage template like this:
<!-- wrap start --><div class="content-wrap">
<?php if(have_posts()) : the_post(); ?>
<div id="main">
<div class="central-wrapper clearfix">
<div id="center" class="fullwidth">
<div id="content">
<div class="inner">
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="pagination"><div class="page-links-title">' . __( 'Pages:', 'codeus' ) . '</div>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?>
<div class="bloghome">
<?php
$page_num = (get_query_var('paged')) ? get_query_var('paged') : 1;
$items_per_page = 2;
$blog_loop = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => $items_per_page,
'paged' => $page_num
));
$pages_count = ceil($blog_loop->found_posts/$items_per_page);
global $post;
$portfolio_posttemp = $post;
?>
<?php if($blog_loop->have_posts()) : ?>
<div class="blog_list">
<ul class="styled">
<?php while ( $blog_loop->have_posts() ) : $blog_loop->the_post(); ?>
<li class="clearfix">
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php $image_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'codeus_post_list_image'); ?>
<div class="comment-info">
<?php echo get_the_date('d'); ?>
<div class="date-month"><?php echo get_the_date('M'); ?></div>
</div>
<div class="post-info">
<h3><?php the_title(); ?></h3>
<?php if($image_url[0]) : ?>
<div class="post-image">
<div class="image wrap-box shadow middle">
<div class="shadow-left"></div><div class="shadow-right"></div>
<img src="<?php echo $image_url[0]; ?>" alt="<?php the_title(); ?>" />
</div>
</div>
<?php endif; ?>
<div class="text clearfix"><?php the_excerpt(); ?></div>
<?php codeus_author_info(get_the_ID()); ?>
</div>
</div>
</li>
<?php $post = $portfolio_posttemp; wp_reset_postdata(); ?>
<?php endwhile; ?>
</ul>
</div>
<?php endif; ?>
</div>
</div>
</div><!-- #content -->
</div><!-- #center -->
</div><!-- .central-wrapper -->
</div><!-- #main -->
<?php endif; ?>
</div><!-- wrap end -->
I need an advice on where to add my google custom search engine code in the search.php file ?
here is the php file:
note that endwhile and endif are included, I have checked on youtube and I tried to delete the code between (if have post) and (endif) and add the google code there but it did not work..
<?php $mts_options = get_option('point'); ?>
<?php get_header(); ?>
<div id="page" class="home-page">
<div class="content">
<div class="article">
<h1 class="postsby">
<span><?php _e("Search Results for:", "mythemeshop"); ?></span> <?php the_search_query(); ?>
</h1>
<?php $j=0; $i =0; if (have_posts()) : while (have_posts()) : the_post(); ?>
<article class="<?php echo 'pexcerpt'.$i++?> post excerpt <?php echo (++$j % 2 == 0) ? 'last' : ''; ?>">
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="nofollow" id="featured-thumbnail">
<?php if ( has_post_thumbnail() ) { ?>
<?php echo '<div class="featured-thumbnail">'; the_post_thumbnail('featured',array('title' => '')); echo '</div>'; ?>
<?php } else { ?>
<div class="featured-thumbnail">
<img src="<?php echo get_template_directory_uri(); ?>/images/nothumb.png" class="attachment-featured wp-post-image" alt="<?php the_title(); ?>">
</div>
<?php } ?>
<div class="featured-cat"><?php $category = get_the_category(); echo $category[0]->cat_name; ?></div>
</a>
<header>
<h2 class="title">
<?php the_title(); ?>
</h2>
<div class="post-info"><span class="theauthor"><?php the_author_posts_link(); ?></span> | <span class="thetime"><?php the_time( get_option( 'date_format' ) ); ?></span></div>
</header><!--.header-->
<div class="post-content image-caption-format-1">
<p>
<?php echo mts_excerpt(29);?>
<span class="readMore"><?php _e('Read More','mythemeshop'); ?></span>
</p>
</div>
</article>
<?php endwhile; else: ?>
<div class="no-results">
<h5><?php _e('No Results found. We apologize for any inconvenience, please hit back on your browser or use the search form below.', 'mythemeshop'); ?></h5>
<?php get_search_form(); ?>
</div><!--noResults-->
<?php endif; ?>
<!--Start Pagination-->
<?php if ( isset($mts_options['mts_pagenavigation']) && $mts_options['mts_pagenavigation'] == '1' ) { ?>
<?php $additional_loop = 0; global $additional_loop; mts_pagination($additional_loop['max_num_pages']); ?>
<?php } else { ?>
<div class="pagination">
<ul>
<li class="nav-previous"><?php next_posts_link( __( '← '.'Older posts', 'mythemeshop' ) ); ?></li>
<li class="nav-next"><?php previous_posts_link( __( 'Newer posts'.' →', 'mythemeshop' ) ); ?></li>
</ul>
</div>
<?php } wp_reset_query(); ?>
<!--End Pagination-->
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Regards !!
Just Create A New File Called searchform.php and paste your Google Custom Search Code There.
I managed to change where to add the code and here is the full code of search.php
<?php $mts_options = get_option('point'); ?>
<?php get_header(); ?>
<div id="page" class="home-page">
<div class="content">
<div class="article">
<h1 class="postsby">
<span><?php _e("Search Results for:", "mythemeshop"); ?></span> <?php the_search_query(); ?>
</h1>
<?php $j=0; $i =0; if (have_posts()) : while (have_posts()) : the_post(); ?>
<script>
(function() {
var cx = '000306723311332550300:tfoukb5efrq';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
<gcse:search></gcse:search>
</div>
</article>
<?php endwhile; else: ?>
<div class="no-results">
<h5><?php _e('No Results found. We apologize for any inconvenience, please hit back on your browser or use the search form below.', 'mythemeshop'); ?></h5>
<?php get_search_form(); ?>
</div><!--noResults-->
<?php endif; ?>
<!--Start Pagination-->
<?php if ( isset($mts_options['mts_pagenavigation']) && $mts_options['mts_pagenavigation'] == '1' ) { ?>
<?php $additional_loop = 0; global $additional_loop; mts_pagination($additional_loop['max_num_pages']); ?>
<?php } else { ?>
<div class="pagination">
<ul>
<li class="nav-previous"><?php next_posts_link( __( '← '.'Older posts', 'mythemeshop' ) ); ?></li>
<li class="nav-next"><?php previous_posts_link( __( 'Newer posts'.' →', 'mythemeshop' ) ); ?></li>
</ul>
</div>
<?php } wp_reset_query(); ?>
<!--End Pagination-->
</div>
<?php get_footer(); ?>