Wordpress Exclude Data From Category - php

I want to hide the date and time from specific categorys on wordress. I have the code below which is what every page displays and automatically applied to every category. How can i exclude certain categorys from showing this information.
Thanks in advance
if (have_posts()):
while(have_posts() ): the_post(); ?>
<div align="center" class="blogimage"> <?php the_post_thumbnail( 'shop_single' ); ?>
<h3><?php the_title(); ?></h3>
<?php the_date(); ?>
<p> By </p>
<?php the_author();?>
</div>
<p><?php the_content(); ?></p>

if (have_posts()):
while(have_posts() ): the_post(); ?>
<div align="center" class="blogimage"> <?php the_post_thumbnail( 'shop_single' ); ?>
<h3><?php the_title(); ?></h3>
<?php if(!in_category(10)):?>
<?php the_date(); ?>
<?php endif;?>
<p> By </p>
<?php the_author();?>
</div>
<p><?php the_content(); ?></p>
!in_category(10) 10 is category id. docs

Related

How to show thumbnails of posts in a category at the end of a single post?

I posted this yesterday but then when I signed up after I couldn't see the question anymore, so apologies if it is now on here twice!
I'm trying to show a grid of thumbnails at the end of a single page. I have the grid working fine on my "work" page which is a category page. They are displayed as a thumbnail grid using the code below. And you can see on the site Here.
<?php
get_header(); ?>
<div class="grid work thumb-wrap clearfix">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
<a class="thumb" href="<?php the_permalink(); ?>">
<img src="http://www.nathanspence.com/wp-content/uploads/<?php echo get_post_meta($post->ID, 'thumb', true); ?>"/>
<div class="post-excerpt">
<h2><?php echo get_the_title($ID); ?></h2>
<div class="sub-title"><?php echo get_post_meta($post->ID, 'project-name', true); ?></div>
</div>
</a>
<?php endwhile; ?>
<?php endif; ?>
</div><!--end of "thumb-wrap"-->
<div class="push"></div>
</div><!--end of "page-wrap"-->
<?php get_footer(); ?>
I want to duplicate this at the end of each single post. Here.
<?php get_header(); ?>
<div class="page-content">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<article class="work post-content ready-to-column clearfix">
<header class="post-header column-left">
<h1><?php echo get_the_title($ID); ?></h1>
<h2><?php echo get_post_meta($post->ID, 'project-name', true); ?></h2>
<div class="project-info"><?php echo get_post_meta($post->ID, 'project-info', true); ?></div>
</header>
<div class="column-right">
<?php the_content(); ?>
</div><!---end of "right-column flex-column"--->
</article>
<?php endwhile; else: ?>
<p>Sorry, this post does not exist</p>
<?php endif; ?>
<div class="grid work thumb-wrap clearfix">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
<a class="thumb" href="<?php the_permalink(); ?>">
<img src="http://www.nathanspence.com/wp-content/uploads/<?php echo get_post_meta($post->ID, 'thumb', true); ?>"/>
<div class="post-excerpt">
<h2><?php echo get_the_title($ID); ?></h2>
<div class="sub-title"><?php echo get_post_meta($post->ID, 'project-name', true); ?></div>
</div>
</a>
<?php endwhile; ?>
<?php endif; ?>
</div><!--end of "thumb-wrap"-->
<div class="push"></div>
</div><!--end of "page-wrap"-->
<?php get_footer(); ?>
I want to have this grid show at the end of a single post. I have tried just pasting the same loop in but as you can see, simply pasting it in just shows the current posts thumbnail. Any idea how I can do this? I'm a designer who is just learning to be able to maintain my own site, so I'm a bit lost reading about loops etc. Thanks!
Edit: So to make it clearer. How do I get this code below to output all posts in that category at the end of the single post?
<a class="thumb" href="<?php the_permalink(); ?>">
<img src="http://www.nathanspence.com/wp-content/uploads/<?php echo get_post_meta($post->ID, 'thumb', true); ?>"/>
<div class="post-excerpt">
<h2><?php echo get_the_title($ID); ?></h2>
<div class="sub-title"><?php echo get_post_meta($post->ID, 'project-name', true); ?></div>
</div>
</a>
Try adding this where you want all post
<?php
$wpb_all_query = new WP_Query(array('post_type'=>'post', 'post_status'=>'publish', 'posts_per_page'=>-1)); ?>
<?php if ( $wpb_all_query->have_posts() ) : ?>
<ul>
<!-- the loop -->
<?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>
<li><?php the_title(); ?></li>
<?php endwhile; ?>
<!-- end of the loop -->
</ul>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

Wordpress - Hide blog meta data if in specific category

I have a standard wordpress blog here: http://webserver-meetandengage-com.m11e.net/insights/ and I've created a new category called clients.
The clients posts on this archive page will have different meta data that the standard blog post, so I want to get rid of the excerpt, date and author etc.
To achieve this I tried adding a conditional bit of code that said, IF the category of this post area is 'client' then echo style="display:none;" inside the div.
Here's the line of code I'm trying:
<p<?php if ( in_category( 'client' )) { echo 'style="display:none;"' }?>>This is not client</p>
Here's the loop it appears in:
<div class="container blog-card-container">
<div class="row">
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="col-md-4">
<a href="<?php the_permalink(); ?>">
<div class="card">
<div class="blog-thumb-container">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?>
</div>
<div class="blog-clients-card-block">
<?php if( get_field('quote_name') ): ?><p class="client-name" style="color:<?php the_field('client_brand_colour'); ?>;"><?php the_field('quote_name'); ?></p><?php endif; ?>
<p<?php if ( in_category( 'client' )) { echo 'style="display:none;"' }?>>This is not client</p>
<p class="blog-cat-label"><?php the_category(', '); ?></p>
<h2 class="blog-card-title"><?php the_title(); ?></h2>
<p class="card-text"><?php the_excerpt(__('(more…)')); ?></p>
<p><strong><?php the_author(); ?></strong> | <?php the_date(); ?> </p>
</div>
</div>
</a>
</div>
<?php understrap_pagination(); ?>
<?php endwhile; wp_reset_postdata(); endif; ?>
</div>
</div>
But including it here breaks the loop and the page doesn't load... I'm not sure what I'm doing wrong, or even if there might be a better solution?
I essentially want to show one set of meta for post thumbnails with the category 'client' and then another set for all other categories in the blog.
I guess it could be IF category of container is client then show META1 else show META2.
Any help would be massively appreciated :)
Managed to achieve this with two IF ELSE statements:
<div class="container blog-card-container">
<div class="card-columns">
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<a href="<?php the_permalink(); ?>">
<div class="card">
<!-- Image if loop =========================================== -->
<?php if ( in_category('14') ) : ?>
<div class="client-header-logo-card" style="background-color: <?php the_field('client_brand_colour'); ?>;">
<?php
$image = get_field('client_logo');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
</div>
<?php else: ?>
<div class="blog-thumb-container">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?>
</div>
<?php endif ?>
<!-- Meta Data if loop =========================================== -->
<div class="blog-clients-card-block">
<?php if ( in_category('14') ) : ?>
<p class="blog-cat-label"><?php the_category(', '); ?></p>
<h2><?php the_title(); ?></h2>
<?php if( get_field('quote') ): ?><p class="client-quote"><?php echo custom_field_excerpt(); ?></p><?php endif; ?>
<?php if( get_field('quote_name') ): ?><p class="client-name" style="color:<?php the_field('client_brand_colour'); ?>;"><?php the_field('quote_name'); ?></p><?php endif; ?>
<?php if( get_field('quote_position') ): ?><p class="client-position" style="color:<?php the_field('client_brand_colour'); ?>;"><?php the_field('quote_position'); ?></p><?php endif; ?>
<?php if( get_field('button_text') ): ?>
<a class="btn btn-sm btn-client-archive" href="<?php the_permalink(); ?>" style="background-color:<?php the_field('client_brand_colour'); ?>;" role="button"><?php the_field('button_text'); ?></a>
<?php endif; ?>
<?php if( get_field('video_url') ): ?>
<div class="embed-container">
<?php the_field('video_url'); ?>
</div>
<?php endif; ?>
<?php else: ?>
<p class="blog-cat-label"><?php the_category(', '); ?></p>
<h2 class="blog-card-title"><?php the_title(); ?></h2>
<p class="card-text"><?php the_excerpt(__('(more…)')); ?></p>
<p><strong><?php the_author(); ?></strong> | <?php the_date(); ?> </p>
<?php endif ?>
</div>
</a>
</div>
You need to set it up in a Variable and echo the variable. For instance if client display:none is stored in the $style var if not then it doesn't place a style
<?php
if(in_category('client')){$style = 'display:none;';} else {$style = '';}
?>
<p style="<?php echo $style; ?>">This is not client</p>

Wordpress search results multiple loops by category

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>

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 -->

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