dongzhang5006 2014-06-17 10:22
浏览 37

Wordpress wp_list_pages walker带有精选图片标题

I have created a custom walker for wp_list_pages() in Wordpress. This walker displays the featured images of the pages in question. My problem is that I need to also show the caption of these featured images. At the moment this is just showing the title of the page, I don't know how to get the featured image caption instead.

Here is my walker:

class SlideshowPics_walker extends Walker_page {
    function start_el( &$output, $page, $depth, $args, $current_page = 0 ) {
        if(has_post_thumbnail($page->ID)){
            $image = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), 'main-featured-thumbnail' );
            $link_title = $link_before . '<img src="'.$image[0].'" alt="'.esc_attr( wp_strip_all_tags( apply_filters( 'the_title', $page->post_title, $page->ID ) ) ).'"/><div class="caption">'.apply_filters( 'the_title', $page->post_title, $page->ID ). $link_after.'</div>';
        } else
        $link_title= $link_before . apply_filters( 'the_title', $page->post_title, $page->ID ) . $link_after;
        $output .= $indent . '<li class="' . $css_class . '"><a href="' . get_permalink($page->ID) . '">' . $link_title . '</a>'
        .'</li>';
    }
}
  • 写回答

1条回答 默认 最新

  • dsdv76767671 2014-06-17 10:41
    关注

    Solved this by using:

    class SlideshowPics_walker extends Walker_page {
        function start_el( &$output, $page, $depth, $args, $current_page = 0 ) {
            if(has_post_thumbnail($page->ID)){
                $image = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), 'main-featured-thumbnail');
                $imageCap = get_post(get_post_thumbnail_id($page->ID))->post_excerpt;
                $link_title = $link_before . '<img src="'.$image[0].'" alt="'.esc_attr( wp_strip_all_tags( apply_filters( 'the_title', $page->post_title, $page->ID ) ) ).'"/><div class="caption">'.$imageCap. $link_after.'</div>';
            } else
            $link_title= $link_before . apply_filters( 'the_title', $page->post_title, $page->ID ) . $link_after;
            $output .= $indent . '<li class="' . $css_class . '"><a href="' . get_permalink($page->ID) . '">' . $link_title . '</a>'
            .'</li>';
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据