【问题标题】:How to show caption in Gallery images in wordpress如何在wordpress的图库图片中显示标题
【发布时间】:2016-10-09 22:09:39
【问题描述】:

您好,我有投资组合博客,在投资组合页面下,我将我的图像显示为图像提要并通过图库添加它的显示只是没有超链接没有标题没有标题

我想在每张图片上显示唯一的标题

这是用于在我的主题中显示图像的代码

    <?php 
    global $post;
    $header_images = get_post_meta($post->ID, '_ebor_gallery_images', 1); 

    if( is_array($header_images) ) :
?>

<ul class="basic-gallery text-center">
    <?php 
        foreach( $header_images as $id => $content ){
            echo '<li>'. wp_get_attachment_image($id, 'large') .'</li> ';

        }
    ?>
</ul>

如何添加标题帮助我解决这个问题

谢谢!

【问题讨论】:

标签: php wordpress image


【解决方案1】:

试试这个...

<ul class="basic-gallery text-center">
    <?php 
        $output = '';
        foreach( $header_images as $id => $content ){
            $output .= '<li>'. wp_get_attachment_image($id, 'large');
            $image = get_post($id);
            $output .= '<span class="caption>'.$image->post_excerpt.'</span>';
            $output .= .'</li> ';
        }
        echo $output;
        $output = '';
    ?>
</ul>

在你想要的任何容器中输出你的标题,我只是以跨度为例。

【讨论】:

  • 仅供参考,除了图片是标题
  • 但是这里的那些标题是我们通过图库选项添加的,所以对于每张图片都有不同的标题,所以我在输出中使用的是 @Simon Pollard
  • the_excerpt();这项工作摘录并显示标题@Simon Pollard
  • 图片的摘录和标题是相同的 - 除非您的图片库以不同的方式工作
  • nope 它在此摘录中的作品集用于发布内容,我们在其中添加图像,因此在每张图像中都需要添加标题,这是无法添加标题的关键,请参阅 finch WordPress 主题的演示希望您能理解我的观点@Simon Pollard
【解决方案2】:

在你的foreach

$attachment_title = get_the_title($id)

应该给你标题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 2019-12-11
    • 1970-01-01
    相关资源
    最近更新 更多