用缩略图列出WordPress子页面

时间:2011-09-13 00:08:32

标签: php wordpress function children

我正在尝试列出WordPress页面的子项 - 这很容易并且由他们的文档提供。但是,我似乎无法找到如何在每个页面名称上方包含设置页面缩略图。

此处提供的代码列出了每个名称:

<ul>
  <?php
  global $id;
  wp_list_pages("title_li=&child_of=$id&show_date=modified
  &date_format=$date_format"); ?>
</ul>

,该功能的文档在此处:http://codex.wordpress.org/Function_Reference/wp_list_pages

非常感谢

1 个答案:

答案 0 :(得分:1)

打开你的functions.php文件,如果它还没有那么就粘贴在那里..

add_theme_support( 'post-thumbnails' );

然后访问您的每个页面,在右侧,您将有一个新的元框, 称为“特色图片”,您可以点击该链接打开您的媒体库,从那里选择您要用作特色图片的图片,(页面 - 缩略图)

为要显示缩略图的每个页面执行此操作。

然后可能会创建一个新的页面模板?

添加以下代码以遍历页面并为每个页面提取图像。

$args = array('post_type'=>'page','post_status'=>'publish')
// The Query
query_posts( $args );

// The Loop
while ( have_posts() ) : the_post();
    if ( has_post_thumbnail()) :
           the_post_thumbnail();
        else:
           echo the_title();
        endif;
endwhile;

// Reset Query
wp_reset_query();

非常粗略的指南,但你得到它的正义..? 更多关于the_post_thumbnail

Marty