【问题标题】:WordPress theme not pulling through title text of imagesWordPress主题没有通过图像的标题文本
【发布时间】:2014-07-03 13:50:10
【问题描述】:

我正在尝试将我正在使用的主题 (DICE) 用于提取图像的标题文本。

我使用的代码如下;

if ( has_post_thumbnail() ) {
if ( $linking == 'lightbox' ) {
    $alt = esc_attr(get_the_title( $post->ID ) );
    $the_title = esc_attr(get_the_title( $post->ID ) );
    $img = get_the_post_thumbnail( $post->ID, $size, array( 'alt' => $alt, 'title' => $the_title ) ); 
}
else
        $img = get_the_post_thumbnail( $post->ID, $size );
}
elseif( $placeholder ) {
    $img = btp_render_placeholder( $size, '', false );
}
else {
    return;
}

我添加的唯一一行是

$the_title = esc_attr(get_the_title( $post->ID ) ); 

'title' => $the_title 

也在数组中。替代文字很好,所以我不确定为什么标题文字没有通过?

感谢任何帮助。谢谢。

【问题讨论】:

    标签: php arrays wordpress text title


    【解决方案1】:

    使用两个单独的变量来获取相同的信息是不好的编程习惯。 尝试只使用一个变量,如下所示:

    if ( $linking == 'lightbox' ) {
        $post_title = esc_attr(get_the_title( $post->ID ) );
        //The Image
        $img = get_the_post_thumbnail( $post->ID, $size, array( 'alt' => $post_title, 'title' => $post_title ) ); 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-10
      • 1970-01-01
      • 1970-01-01
      • 2013-11-05
      • 1970-01-01
      • 2010-12-09
      • 2013-08-18
      • 1970-01-01
      相关资源
      最近更新 更多