Url link to feature image in the portfolio wordpress - php

I am new to Wordpress. i have issue with Feature image. just i need to add URL to feature image(when we click on that feature image , it should redirect to that particular URL).
also is it possible to give URL to Title of the Portfolio categories page which i used in normal page.

You need to add this code in your php file :
<?php if ( has_post_thumbnail()) {
echo '<a href="' . get_permalink($post->ID) . '" >';
the_post_thumbnail();
echo '</a>';
}?>

<?php the_title(); ?>
<?php the_post_thumbnail( 'large' ); ?>
instead of this <?php the_permalink(); ?> you can assign your own url

use <?php the_permalink(); ?> for add Url link to feature image in portfolio in wordpress.

This worked finally.
<a href="<?php echo get_post_meta($post->ID, $sr_prefix.'_portfolio_externalurl', true); ?>"><?php } the_post_thumbnail('portfolio-crop-thumb');

Related

Using Post Thumbnail with Fancybox

I'm trying to set my page so that when a user clicks the thumbnail of the current post, it expands in a Fancybox popup.
<?php
$featured_img_url = get_the_post_thumbnail_url($post->ID);
?>
<?php if ( has_post_thumbnail() ) { ?>
<div class="featured-image" data-fancybox="gallery" href="<?php $featured_img_url ?>"
<?php the_post_thumbnail(); ?>
</div>
<?php } ?>
This works, in that the image opens as expected when it's clicked. But when I click off the overlay, the thumbnail has disappeared. display: none has been added to it inline.
I have also tried wrapping the div in an <a> tag and using that, but this has the same outcome.
<?php
$featured_img_url = get_the_post_thumbnail_url($post->ID);
?>
<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php $featured_img_url ?>" class="fancybox" data-fancybox="gallery">
<div class="featured-image bShadow">
<?php the_post_thumbnail(); ?>
</div>
</a>
<?php } ?>
I have other images on the page assigned with Advanced Custom Fields that work fine with Fancybox, so I'm assuming the issue is with how I'm trying to get the thumbnail image using php.
Edit: Here's a video of the current outcome: https://www.useloom.com/share/f525f4f0e4c642c8800e82532a99e326
It looks like you have not correct url for your featured link and it is treated as "inline" content instead of "image".
Anyway, you could follow this demo - https://codepen.io/fancyapps/pen/VGoRqO?editors=1010 - and use "trigger element" feature by adding data-fancybox-trigger attribute for featured link.

Replace Button in woocommerce by a clickable Image in PhP

I sell online Gift Cards using Woocommerce on Wordpress. On the thank you page it displays the download image (containing the Gift Card Key) as a button.
I would like it to display the image itself to be downloaded in full size above the the download link.
Screenshot of the Thank You Page
Here's the part that displays the download section in PHP:
<?php break;
case 'download-file' : ?>
<a href="<?php echo esc_url( $download['download_url'] ); ?>" class="woocommerce-MyAccount-downloads-file">
<?php echo esc_html( $download['file']['name'] ); ?>
</a>
Can you help me out plz?
Try this code. you have to download attribute to <a> tag
<?php
break;
case 'download-file' : ?>
<a href="<?php echo esc_url( $download['download_url'] ); ?>"
class="woocommerce-MyAccount-downloads-file" download>
<?php echo esc_html( $download['file']['name'] ); ?>
</a>

prettyPhoto on a Wordpress featured image

I am pretty new at this and tried to search a lot about this, breaking my site down numerous times because of wrong PHP code, so here is the deal.
I have a Wordpress page with portfolio posts. In those posts the only image displayed is the featured image. Due to that my prettyPhoto plugin won't show the lightbox when I click on that featured photo.
First I had this code ...
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
... which showed the featured image but didn't show the lightbox so it was not clickable. Then I played around and created this:
<?php if ( has_post_thumbnail()) : ?>
<a class="lightbox_single_portfolio" title="<?php echo esc_attr($title); ?>"
href="<?php echo esc_url($image_src); ?>" data-
rel="prettyPhoto[single_pretty_photo]">
<?php the_post_thumbnail(); ?>
</a>
<?php endif; ?>
So the featured image got clickable, the lightbox started opening but there is an error that states "Image cannot be loaded. Make sure the path is correct and image exists". Due to that I said to myself that the problem could be that lightbox isn't loading the right image source.
I tried playing a bit more and tried to do this ...
<?php
if ( has_post_thumbnail()) {
$featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full');
echo '<a class="lightbox_single_portfolio" href="'.esc_url($image_src).'" data-rel="prettyPhoto[single_pretty_photo]">';
the_post_thumbnail('thumbnail');
echo '</a>';
endif;?>
... aaaand it breaks my site.
What could be the problem?
You are not closing the If statement,
change endif; to }
Well, I'm gonna post an answer as I found out something on the internet and it made my code work. Although the above answer (change endif; to }) did make my code work, it still showed the same error that the path couldn't be found.
I played around again a little bit, and this did the trick:
<?php
if ( has_post_thumbnail()) {
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full');
echo '<a rel="prettyPhoto" href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" >';
the_post_thumbnail();
echo '</a>';
}
?>
So the PHP calls a $large_image_url instead of the post thumbnail url.
This did the trick, and it works! It shows my featured image in a lightbox :)

WordPress Default Featured Image

I’ve got a WordPress site and have added the following code to the Single.php file, which means if I publish a blog post without selecting a ‘Featured Image’, it will display a default ‘Featuered Image’ instead (tellymedia-temporary-image.jpg).
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
} else { ?>
<img src="<?php bloginfo('template_directory'); ?>/branding/tellymedia-temporary-image.jpg" alt="<?php the_title(); ?>" />
This works fine on the actual page displaying the individual blog post (which shows the default image), but I’m also using the following code in my Functions.php file, to display a ‘Featured Image’ thumbnail for each post in the Sidebar:
<span class="widget-listing-thumbnail"><?php the_post_thumbnail(); ?></span><?php get_the_title() ? the_title()+the_subtitle('<span class="widget-subtitle">', '</span class="widget-subtitle">') : the_ID(); ?>
While this works for all other posts it doesn’t work for any where I haven’t selected a ‘Featued Image’. Is there a way to tweak the code in my Functions.php file please, so it will also display a thumbnail of the default ‘Featuered Image’ in the Sidebar for posts where I haven’t selected one please?
Thanks!
try this one.
<a href="<?php the_permalink(get_the_id()); ?>">
<span class="widget-listing-thumbnail">
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
} else { ?>
<img src="<?php bloginfo('template_directory'); ?>/branding/tellymedia-temporary-image.jpg" alt="<?php the_title(); ?>" />
?>
</span>
<?php get_the_title() ? the_title() + the_subtitle('<span class="widget-subtitle">', '</span class="widget-subtitle">') : the_ID(); ?>
</a>

on click post thumb nail redirect to another site

This is the code
<?php if ( has_post_thumbnail() ) { the_post_thumbnail('thumbnail'); }?>
On Clicking The Post Thumbnail I want to redirect to another site
I have given link in content as well as in link of the content I cannot figure it out
So, Can anyone help?? Thank You!!
Try this one
<a href="<?php echo the_content(); ?>" title="<?php echo the_title();?>">
<?php if ( has_post_thumbnail() ) { echo the_post_thumbnail('thumbnail'); }?>
</a>

Categories