dqw7121 2018-01-14 22:49
浏览 33
已采纳

WordPress上的prettyPhoto特色图片

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?

  • 写回答

2条回答 默认 最新

  • dsc6517 2018-01-14 22:51
    关注

    You are not closing the If statement,

    change endif; to }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler