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>
Related
I have coded as below for Recent post by same author. Code is working fine and giving me recent post by same author, but it show more than one post (but I need 1 post to show)
<div class="popular-post-wrapper">
<h4 class="blog-post-sub-title">Most Recent</h4>
<div class="col-md-3 popular-post-thumbnail">
<?php
$query_posts=array(
'orderby' => 'display_name',
'order' => 'ASC',
'who' => 'authors',
'posts_per_page' => '1' );
if (have_posts()) : while (have_posts()) : the_post();
?>
<?php //if ( has_post_thumbnail() ) : ?>
<a href="<?php //the_permalink(); ?>" title="<?php //the_title_attribute(); ?>">
<?php //the_post_thumbnail(); ?>
</a>
<?php //endif; ?>
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
} else { ?>
<img src="https://kubalubra.is/wp-content/uploads/2017/11/default-thumbnail.jpg" alt="<?php the_title(); ?>" />
<?php } ?>
</div>
<div class="col-md-9 post-title-wrapper">
<h3> <a href="<?php the_permalink(); ?>">
<?php the_title();?>
</a></h3>
</div>
<?php
endwhile; endif;
wp_reset_query();
?>
</div>
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>
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();
I need to fetch the featured images of posts in WordPress Currently, I am having the code for listing posts with images and text.
I am having a posts page that lists all posts I need to list the photos of the posts to another page
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( has_post_thumbnail() ) : ?>
<div class="entry-thumb">
<?php the_post_thumbnail( 'oblique-entry-thumb'); ?>
<a class="thumb-link" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><i class="fa fa-link"></i></a>
</div>
<?php else : ?>
<div class="entry-thumb">
<img src="http://placehold.it/500x500" />
<a class="thumb-link" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><i class="fa fa-link"></i></a>
</div>
<?php endif; ?>
<?php //if ( has_post_thumbnail() ) : ?>
<div class="post-inner post-inner-height">
<?php //else : ?>
<!-- <div class="post-inner no-thumb"> -->
<?php //endif; ?>
<header class="entry-header">
<?php the_title( sprintf( '<h1 class="entry-title entry-title-height">', esc_url( get_permalink() ) ), '</h1>' ); ?>
<?php if ( 'post'==g et_post_type() && !get_theme_mod( 'meta_index') ) : ?>
<!-- .entry-meta -->
<?php endif; ?>
</header>
<!-- .entry-header -->
<div class="entry-content entry-con-fixh">
<?php the_excerpt(); ?>
<?php wp_link_pages( array( 'before'=>'
<div class="page-links">' . __( 'Pages:', 'oblique' ), 'after' => '</div>', ) ); ?>
</div>
<!-- .entry-content -->
</div>
<?php if (!get_theme_mod( 'read_more')) : ?>
<div class="read-more">
<a href="<?php the_permalink(); ?>">
<?php echo __( 'Continue reading …', 'oblique'); ?>
</a>
</div>
<?php endif; ?>
</article>
<!-- #post-## -->
This is the code I am having. If I am having 50 posts how can I able to filter the images from that post
I tried using the following code
<?php if ( has_post_thumbnail() ) : ?>
<div class="entry-thumb">
<?php the_post_thumbnail( 'oblique-entry-thumb'); ?>
<a class="thumb-link" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><i class="fa fa-link"></i></a>
</div>
<?php else : ?>
<div class="entry-thumb">
<img src="http://placehold.it/500x500" />
<a class="thumb-link" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><i class="fa fa-link"></i></a>
</div>
<?php endif; ?>
but it wont display all images it shows only the dummy image that I placed
If you want all post then you need to iterate over them and fetch the post thumbnail.
<?php
// define query fields
$query = array(
// define post type to query
'post_type' => 'post',
// define posts count as -1, to fetch all
'posts_per_page' => -1
);
// query the post
$posts = query_posts($query);
// iterate over the posts
foreach ($posts as $post): ?>
<!-- echo the thumbnail -->
<?php echo get_the_post_thumbnail($post->ID); ?>
<!-- rest of the HTML -->
<?php endforeach; ?>
I'm working on a Wordpress site. I'm trying to make a category with the id 968 show up on the Wordpress site under the stories and successes div. However for some reason the stories and successes div is not having the content from the category inserted into it. Any information on how I can improve my query or PHP is much appreciated. If I need to update this post with more information please let me know. Below you will see the php template file I am using.
<?php
/**
* Template name: Random Template
*
*
*/
// Custom styles
wp_enqueue_style('stories-styles', get_bloginfo('stylesheet_directory') . '/assets/css/stories.css');
// TEMP -- Get the category from the slug
the_post();
$categorySlugs = array(
'religious-freedom' => 'religious-freedom',
'social-and-economic-justice' => 'social-and-economic-justice',
'civil-and-human-rights' => 'civil-and-human-rights'
);
// Get category
$categorySlugs = $categorySlugs[$post->post_name];
$storyQuery = new WP_Query(array(
'post_type' => array('stories', 'press-releases'),
'category_name' => $categorySlugs,
'posts_per_page' => 4,
'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1
));
$successesQuery = new WP_Query(array(
'post_type' => 'stories',
'cat' => 968,
'posts_per_page' => 1,
'offset' => 5
));
// Remove yarpp
remove_filter('the_content', array($yarpp, 'the_content'), 1200);
?>
<?php get_header(); ?>
<div class="category-title">
<div class="container">
<h2><?php the_title() ?></h2>
</div>
</div>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<div class="container">
<div class="row">
<div class="col-md-12">
<?php if ( function_exists('yoast_breadcrumb') ) {
yoast_breadcrumb('<p id="breadcrumbs">','</p>');
} ?>
<article class="featured-issue-article">
<?php if ( has_post_thumbnail() && ! post_password_required() ) : ?>
<div class="entry-thumbnail">
<?php the_post_thumbnail('full', array( 'class' => "img-responsive attachment-post-thumbnail")); ?>
</div>
<?php endif; ?>
<div class="content">
<?php the_content() ?>
</div>
</article>
</div>
</div>
<hr class="large blue" />
<div class="row">
<div class="col-md-8">
<ul class="section-list">
<?php while ($storyQuery->have_posts()) : $storyQuery->the_post(); ?>
<li>
<h3><?php the_title() ?></h3>
<?php if ( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail('post-thumbnail', array( 'class' => "img-responsive attachment-post-thumbnail")); ?>
<?php endif; ?>
<?php if( get_field('custom_excerpt', $values_id)): ?>
<p><?php echo the_field('custom_excerpt'); ?></p>
<?php endif; ?>
<a class="more" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">Read More...</a>
</li>
<?php endwhile; ?>
</ul>
<?php
set_query_var('category_slug', $categorySlug);
get_template_part('issues-nav', 'bottom')
?>
<hr class="small blue" />
<div class="success-stories">
<h2>Stories & Successes</h2>
<ul>
<?php while ($successesQuery->have_posts()) : $successesQuery->the_post(); ?>
<li>
<h4>
<?php the_title() ?>
</h4>
<?= strip_tags($post->post_excerpt) ?>
<a class="more" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">Read More...</a>
</li>
<?php endwhile; ?>
</ul>
</div>
</div>
<div class="col-md-4">
<?php get_sidebar(); ?>
</div>
</div>
</div>
</div>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>