Wordpress search results multiple loops by category - php

I found a piece of code that allows me to have two separate loops so I can display search results in two different categories, which is great because they are also styled different.
I would like help amending this code below to include showing a 'no results found' message for each loop and add pagination for the second 'blog' category only, the top one 'shop' should show a max of 6 results.
<?php
get_header(); ?>
<div class="content">
<?php
$s = get_search_query();
?>
<div class="search">
<div class="categoryThumbs">
<?php if (have_posts()) : ?>
<h3><?php printf( __( 'Search Results for: %s'), '<span>' . get_search_query() . '</span>' ); ?></h3>
<?php endif;?>
<?php query_posts("s='$s'&category_name=shop"); ?>
<?php if (have_posts()) : ?>
<?php $blogResults=0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php
$blogResults++;
?>
<?php endwhile; ?>
<h4><?php echo $blogResults; ?> Results in Shop</h4>
<?php while (have_posts()) : the_post(); ?>
<div class="films">
<div class="thumb">
<?php the_post_thumbnail(); ?>
</div>
<h3 id="post-<?php the_ID(); ?>"><?php the_title(); ?></h3>
<div class="entry">
<?php the_excerpt() ?>
</div>
</div>
<?php endwhile; ?>
<?php endif;?>
<?php query_posts("s='$s'&category_name=blog"); ?>
<?php if (have_posts()) : ?>
<?php $blogResults=0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php
$blogResults++;
?>
<?php endwhile; ?>
<h4><?php echo $blogResults; ?> Results in Blog</h4>
<?php while (have_posts()) : the_post(); ?>
<div class="films">
<div class="thumb">
<?php the_post_thumbnail(); ?>
</div>
<h3 id="post-<?php the_ID(); ?>"><?php the_title(); ?></h3>
<div class="entry">
<?php the_excerpt() ?>
</div>
</div>
<?php endwhile; ?>
<?php endif;?>
<div class="spacer"></div>
</div>
</div>
Thanks for any help!

<div class="search">
<div class="categoryThumbs">
<?php if (have_posts()) : ?>
<h3><?php printf( __( 'Search Results for: %s'), '<span>' . get_search_query() . '</span>' ); ?></h3>
<?php endif;?>
<?php if (have_posts()) : ?>
<h4><?php echo wp_count_posts(); ?> Results in Shop</h4>
<?php while (have_posts()) : the_post();
$taxonomy = 'category';
$queried_term = get_query_var($taxonomy);
$term = get_term_by( 'slug', $queried_term, $taxonomy );
$termName = $term->name;
if($termName == 'shop'):
?>
<div class="films">
<div class="thumb">
<?php the_post_thumbnail(); ?>
</div>
<h3 id="post-<?php the_ID(); ?>"><?php the_title(); ?></h3>
<div class="entry">
<?php the_excerpt() ?>
</div>
</div>
<?php else:
// others code for blog
endif; endwhile; ?>
<?php endif;?>
<div class="spacer"></div>
</div>

Related

tired to add pagination on single category.php page

im tried to add pagination and set post per page on my category.php page
how can i solve this
here need set post per page and also pagination
here is my code for category.php
thanks
<?php if( have_posts() ): ?>
<div class="cat-bread-cumb overflow-fix">
<u>
<li><i class="fa fa-home" aria-hidden="true"></i></li>
<li><span>/</span><?php the_archive_title(); ?></li>
</u>
</div>
<?php while( have_posts() ): the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php the_title( sprintf('<h1 class="entry-title">', esc_url( get_permalink() ) ),'</h1>' ); ?>
<small>Posted on: <?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?>, in <?php the_category(); ?></small>
</header>
<div class="row">
<?php if( has_post_thumbnail() ): ?>
<div class="col-xs-12 col-sm-4">
<div class="thumbnail"><?php the_post_thumbnail('medium'); ?></div>
</div>
<div class="col-xs-12 col-sm-8">
<?php the_content(); ?>
</div>
<?php else: ?>
<div class="col-xs-12">
<?php the_content(); ?>
</div>
<?php endif; ?>
</div>
</article>
<?php endwhile; ?>
<?php endif; ?>

repeated loop in wordpress blog page how to solve this?

how to list only 10 post in one page and solve pagination, i found repeated loop in this.
i want to apply css in comment also . how can i separate comments each part and can give individual css?
<?php query_posts('post_type=post&post_status=publish&posts_per_page=10&paged='. get_query_var('paged')); ?>
<?php if( have_posts() ): ?>
<?php while( have_posts() ): the_post(); ?>
<div id="post-<?php get_the_ID(); ?>" <?php post_class(); ?>>
<?php the_post_thumbnail( array(200,220),'thumbnail', array( 'class' => 'alignleft' ) ); ?>
<h2><?php the_title(); ?></h2>
<span class="meta"><?php //author_profile_avatar_link(48); ?> <strong><?php the_time('F jS, Y'); ?></strong> / <strong><?php the_author_link(); ?></strong> / <span class="comments"><?php comments_popup_link(__('0 comments','twentythirteen'),__('1 comment','twentythirteen'),__('% comments','twentythirteen')); ?></span></span>
<?php the_excerpt(__('Continue reading »','twentythirteen')); ?>
</div><!-- /#post-<?php get_the_ID(); ?> -->
<?php endwhile; ?>
<div class="navigation">
<span class="newer"><?php previous_posts_link(__('« Newer','twentythirteen')) ?></span> <span class="older"><?php next_posts_link(__('Older »','twentythirteen')) ?></span>
</div><!-- /.navigation -->
<?php else: ?>
<div id="post-404" class="noposts">
<p><?php _e('None found.','twentythirteen'); ?></p>
</div><!-- /#post-404 -->
<?php endif; wp_reset_query(); ?>
</div><!-- /#content -->

WP - Archive.php - Not showing all posts in a category

I am not finding out why archive.php only shows maximum 10 posts in a category... Could you please help to find where the bug is?
<div id="blogg_header" class="col col-lg-12 col-sm-12"><div class="well">
<?php if (is_category()) {?>
<h1 class="title">Kategori: <i><?php single_cat_title(); ?> </i></h1>
<?php } elseif (is_month()) { ?>
<h2 clss="title"><?php the_time('F, Y'); ?></h2>
<?php } ?>
</div></div>
<div id="blogg_innlegg_left" class="col col-lg-8 col-sm-8"><div class="well">
<ul>
<?php if (have_posts()) :?>
<?php while (have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<a class id="linkforside" href="<?php the_permalink(); ?>">
<?php get_the_post_thumbnail($header_thumb->ID);?><br/>
</a>
<p class id="infotekst"><?php the_time('d.m.Y') ?></p>
<p class="blogg_innlegg_teksten"><?php echo substr(strip_tags($post->post_content), 0, 250);?></p>
<?php endwhile; ?>
<?php else : ?>
<h2>Ingenting ble funnet.</h2>
<?php endif; ?>
</ul>
</div></div>
I guess I may need to insert the following:
<?php wp_get_archives('type=postbypost&limit=none'); ?>

wordpress the_content() == null although $page->content returns value

Any ideas why the_content() is returning null? When I use $page->content in the same place, this returns the correct value from database.
<?php get_header(); ?>
<div id="main" class="clearfix" role="main">
<?php $attachments = new Attachments( 'attachments' ); ?>
<?php if( $attachments->exist() ) : ?>
<div id="myCarousel" class="carousel">
<!-- Carousel items -->
<div class="carousel-inner">
<?php $i = 0; while( $attachments->get() ) : $i++; ?>
<div class="<?php if($i == 1){ echo 'active'; } ?> item item-<?php echo $attachments->id(); ?>">
<?php echo $attachments->image( 'featured-home' ); ?>
<?php if($attachments->field('caption')){ ?>
<div class="carousel-caption">
<?php echo $attachments->field('caption'); ?>
</div>
<?php } ?>
</div>
<?php endwhile; ?>
</div>
<?php if($i > 1) { ?>
<!-- Carousel nav -->
<a class="carousel-control left" href="#myCarousel" data-slide="prev">‹</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">›</a>
<?php } ?>
<div class="carousel-overlay icons">
Facebook
Twitter
YouTube
RSS Feed
</div>
</div>
<?php endif; ?>
<?php if (have_posts()) : ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(array('row-fluid','clearfix')); ?> role="article">
<div id="content" class="span8">
<header>
<h1><?php echo get_post_meta($post->ID, 'custom_tagline' , true);?></h1>
<?php the_content(); ?>
</header>
<section class="post_content hasSidebar">
<?php query_posts('showposts=10');
while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article">
<header>
<?php the_post_thumbnail( 'wpbs-featured' ); ?>
<h2><?php the_title(); ?></h2>
<?php if(get_comments_number() >= 1): ?>
<a href="<?php comments_link() ?>" title="<?php comment_date() . ' - ' . comment_excerpt(); ?>" <?php comment_class(); ?>><?php comments_number(); ?></a>
<?php endif; ?>
<p class="meta"><?php _e("Posted", "bonestheme"); ?> <time datetime="<?php echo the_time('Y-m-j'); ?>" pubdate><?php the_date(); ?></time> <?php _e("by", "bonestheme"); ?> <?php the_author_posts_link(); ?> <span class="amp">&</span> <?php _e("filed under", "bonestheme"); ?> <?php the_category(', '); ?>.</p>
</header>
<section class="post_content">
<?php the_excerpt(); ?>
</section>
<?php if(has_tag()): ?>
<footer>
<p class="tags"><?php the_tags('<span class="tags-title">' . __("Tags","bonestheme") . ':</span> ', ' ', ''); ?></p>
</footer>
<?php endif; ?>
</article>
<?php endwhile ?>
<?php content_paging_nav('nav-below'); ?>
</section>
<footer>
<p class="clearfix"><?php the_tags('<span class="tags">' . __("Tags","bonestheme") . ': ', ', ', '</span>'); ?></p>
</footer>
</div>
<?php get_sidebar('sidebar2'); ?>
</article>
<?php else : ?>
<article id="post-not-found">
<header>
<h1><?php _e("Not Found", "bonestheme"); ?></h1>
</header>
<section class="post_content">
<p><?php _e("Apologies, but no results were found. Perhaps searching will help find a related post.", "bonestheme"); ?></p>
</section>
<footer>
</footer>
</article>
<?php endif; ?>
</div> <!-- end #main -->
<?php //get_sidebar(); // sidebar 1 ?>
<?php get_footer(); ?>
You're not in a WP loop. You should call e.g. the_post() to set up WP's slew of globals.
Beware of nested WP loops, too. There used to be a gazillion bugs related to them, and there might still be a few lying around just waiting to bite.

Custom blog page on Wordpress (PHP) - Pagination

I'm trying to display first 5 posts with custom thumbnails and titles on this page and I need to display only the titles for the next 5 posts and then the pagination. You can see an example of what I need by clicking here. (see the posts on the left)
Below is the custom template I'm using on the page.
<?php
get_header(); ?>
<div id="primary">
<div id="content" role="main">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts($args);
if( have_posts() ) :?>
<?php twentyeleven_content_nav( 'nav-above' );?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="post-thumb-title">
<?php the_post_thumbnail(array(632,305));?>
<p class="thumb-title2"><?php the_title(); ?></p>
<p class="news-date"><?php the_time('F jS, Y') ?></p>
<div id="post-excerpt">
<?php the_excerpt(); ?>
</div>
</div>
<?php endwhile; ?>
<?php twentyeleven_content_nav( 'nav-below' ); ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
<?php get_search_form(); ?>
</div>
<?php endif; ?>
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Thanks
You could try something like this
<?php
// amount of posts shown with thumbnail
// post 6 .. pagesize (wp-admin > settings > reading) will be displayed as link only
$withThumb = 5;
while ( have_posts() ) : the_post();
if ($withThumb-- > 0) { ?>
<div class="post-thumb-title">
<?php the_post_thumbnail(array(632,305));?>
<p class="thumb-title2"><?php the_title(); ?></p>
<p class="news-date"><?php the_time('F jS, Y') ?></p>
<div id="post-excerpt">
<?php the_excerpt(); ?>
</div>
</div>
<?php } else { ?>
<div class="post-title">
<p class="thumb-title2">
<?php the_title(); ?>
</p>
</div>
<?php } ?>
<?php endwhile; ?>

Categories