繁体   English   中英

带有特色图片说明的Wordpress wp_list_pages walker

[英]Wordpress wp_list_pages walker with featured image captions

我已经在Wordpress中为wp_list_pages()创建了一个自定义沃克。 该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>';
    }
}

通过使用以下方法解决了这个问题:

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>';
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM