【问题标题】:Wordpress wp_list_pages walker with featured image captions带有特色图片标题的 Wordpress wp_list_pages walker
【发布时间】:2014-08-07 07:40:27
【问题描述】:

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

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    通过使用解决了这个问题:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-23
      • 2015-04-05
      • 2014-09-28
      • 2014-11-02
      • 1970-01-01
      • 2012-10-12
      • 2014-02-16
      相关资源
      最近更新 更多