Adding link to post thumbnail - php

<div id="page" class="hfeed site">
<?php if ( has_post_thumbnail() && ! post_password_required() ) : ?>
<?php the_post_thumbnail('full');
else: ?>
<div id="headimg"><img class="ImageResize560" src="<?php header_image(); ?>"></div>
I need to use this code, so that I can link the image, same time
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail(); ?>
</a>
<?php endif; ?>
Basically I need to link the post thumbnail to homepage... I tried but I get error.. somewhere wrong with "else: ?>"

Here is the code
<div id="page" class="hfeed site">
<?php if ( has_post_thumbnail() && ! post_password_required() ) : ?>
<?php $image_url = home_url( ); ?>
<a href="<?php echo $image_url; ?>">
<?php the_post_thumbnail('full'); ?>
</a>
<?php else : ?>
<div id="headimg"><img class="ImageResize560" src="<?php header_image(); ?>"></div>

Related

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>

If/else to test for home in Wordpress

I have an image banner in the header of my custom WP theme, on pages only (not posts). I need this banner to be different on the home page. I've created a front-page template and have this:
<?php if (is_front_page()){ ?>
<div class="banner">
<?php if ( get_header_image() ) : ?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
<img src="<?php header_image(); ?>" width="<?php echo esc_attr( get_custom_header()->width ); ?>" height="<?php echo esc_attr( get_custom_header()->height ); ?>" alt="">
</a>
</div><!-- #banner -->
<?php else { ?>
<div class="banner">
<?php if ( get_header_image() ) : ?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
<img src="<?php header_image(); ?>" width="<?php echo esc_attr( get_custom_header()->width ); ?>" height="<?php echo esc_attr( get_custom_header()->height ); ?>" alt="">
</a>
<?php endif; // End header image check. ?>
</div><!-- #banner -->
I'm using the same image twice here just to test, but get a heap of errors. My php isn't great. Can anyone help?
Not much to say here, just replace you're code with this:
<?php if (is_front_page()){ ?>
<div class="banner">
<?php if ( get_header_image() ) : ?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
<img src="<?php header_image(); ?>" width="<?php echo esc_attr( get_custom_header()->width ); ?>" height="<?php echo esc_attr( get_custom_header()->height ); ?>" alt="">
</a>
<?php endif; ?>
</div><!-- #banner -->
<?php } else { ?>
<div class="banner">
<?php if ( get_header_image() ) : ?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
<img src="<?php header_image(); ?>" width="<?php echo esc_attr( get_custom_header()->width ); ?>" height="<?php echo esc_attr( get_custom_header()->height ); ?>" alt="">
</a>
<?php endif; // End header image check. ?>
</div><!-- #banner -->
<?php } ?>
To enlighten a bit:
You forgot a closing } before else {
You were missing an endif; before </div><!-- #banner -->

Advanced Custom field for each post in WordPress

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>

How do I move the logo in the left position before sitetile in WordPress?

I would like to know what do i need to add in css to make the logo move in the left position before site-title in WordPress?
// Display Site Title
add_action( 'smartline_site_title', 'smartline_display_site_title' );
function smartline_display_site_title() { ?>
<img src="<?php bloginfo('template_directory');?>/images/AA.gif">
<a href="<?php echo esc_url(home_url('/')); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
<h1 class="site-title"><?php bloginfo('name'); ?></h1>
</a>
<?php
}
This should do it :
Add #logo img{float:left;} code to your CSS and then check.
EDITED
#logo img{float:left;margin-top:-3%;}
#logo .site-title{margin-top:2%;}
<!--logo-floater-->
<div id="logo-floater">
<?php if ($logo): ?>
<a href="<?php print check_url($front_page); ?>" title="<?php print t('Home'); ?>">
<img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" />
</a>
<?php endif; ?>
<?php if ($site_name || $site_slogan): ?>
<div class="clearfix">
<?php if ($site_name): ?>
<span id="site-name"><?php print $site_name; ?></span>
<?php endif; ?>
<?php if ($site_slogan): ?>
<span id="slogan"><?php print $site_slogan; ?></span>
<?php endif; ?>
</div>
<?php endif; ?>
</div> <!--EOF:logo-floater-->
This displays the logo first, to switch them try,
<!--logo-floater-->
<div id="logo-floater">
<?php if ($site_name || $site_slogan): ?>
<div class="clearfix">
<?php if ($site_name): ?>
<span id="site-name"><?php print $site_name; ?></span>
<?php endif; ?>
<?php if ($site_slogan): ?>
<span id="slogan"><?php print $site_slogan; ?></span>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ($logo): ?>
<a href="<?php print check_url($front_page); ?>" title="<?php print t('Home'); ?>">
<img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" />
</a>
<?php endif; ?>
</div> <!--EOF:logo-floater-->

Display Conditional Content in Wordpress Template

Alright, so I have this block of code in my current theme:
<div class="content_block">
<?php the_content(); ?>
<div class="<?php echo $left_block; ?>">
<?php $project_photos = get_post_meta( get_the_ID(), 'project_photo_photo' );
if ( $project_photos ) : ?>
<div class="grid_gallery clearfix">
<?php foreach( $project_photos as $project_photo ) { ?>
<figure class="gallery_item featured-thumbnail thumbnail single-gallery-item">
<a href="/brv2/wp-content/files_mf/<?php echo $project_photo; ?>" class="image-wrap" rel="prettyPhoto[gallery]">
<img class="project_photo_photo" width="260" src="/brv2/wp-content/files_mf/<?php echo $project_photo; ?>" alt="<?php the_title(); ?>" />
<span class="zoom-icon"></span>
</a>
</figure>
<?php } ?>
<!--END .slider -->
</div>
<?php endif; ?>
What I need to do is to add a DIV wrap around "the_content" if and only if the $project_photos selector is active, not being a PHP developer this is what I've come up with but it doesn't work:
<div class="content_block">
<?php if ( $project_photos() ) {
echo '<div class="project_description">';
the_content();
echo '</div>';
} else {
the_content();
} ?>
<div class="<?php echo $left_block; ?>">
<?php $project_photos = get_post_meta( get_the_ID(), 'project_photo_photo' );
if ( $project_photos ) : ?>
<div class="grid_gallery clearfix">
<?php foreach( $project_photos as $project_photo ) { ?>
<figure class="gallery_item featured-thumbnail thumbnail single-gallery-item">
<a href="/brv2/wp-content/files_mf/<?php echo $project_photo; ?>" class="image-wrap" rel="prettyPhoto[gallery]">
<img class="project_photo_photo" width="260" src="/brv2/wp-content/files_mf/<?php echo $project_photo; ?>" alt="<?php the_title(); ?>" />
<span class="zoom-icon"></span>
</a>
</figure>
<?php } ?>
<!--END .slider -->
</div>
<?php endif; ?>
If anyone could provide some guidance on how I might accomplish this I would be very grateful.
Thanks in advance.
Can you give this a try?
<div class="content_block">
<?php
$project_photos = get_post_meta( get_the_ID(), 'project_photo_photo' );
if ( $project_photos ) {
echo '<div class="project_description">';
the_content();
echo '</div>';
} else {
the_content();
} ?>
<div class="<?php echo $left_block; ?>">
<?php
if ( $project_photos ) : ?>
<div class="grid_gallery clearfix">
<?php foreach( $project_photos as $project_photo ) { ?>
<figure class="gallery_item featured-thumbnail thumbnail single-gallery-item">
<a href="/brv2/wp-content/files_mf/<?php echo $project_photo; ?>" class="image-wrap" rel="prettyPhoto[gallery]">
<img class="project_photo_photo" width="260" src="/brv2/wp-content/files_mf/<?php echo $project_photo; ?>" alt="<?php the_title(); ?>" />
<span class="zoom-icon"></span>
</a>
</figure>
<?php } ?>
<!--END .slider -->
</div>
<?php endif; ?>

Categories