Wordpress List子页面就像一个类别

时间:2015-06-03 21:15:29

标签: wordpress loops codex

我正在尝试在Wordpress中创建一个页面,其作用类似于列出子页面的类别页面。 (就像在类别页面上一样)。我想添加一个自定义字段作为摘录,因为页面没有摘录(除非有一个简单的插件建议)

我一直试图合并一些例子,但没有得到正确的最终结果。

<?php if ( is_page( 777 ) ) : ?>
<?php
    $mypages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'desc' ) );

    foreach( $mypages as $page ) {      
        $content = $page->post_content;
        if ( ! $content ) // Check for empty page
            continue;

        $content = apply_filters( 'the_content', $content );
    ?>
<div class="entry-header"><h2 class="entry-title"><a href="<?php echo get_page_link( $page->ID ); ?>"><?php echo $page->post_title; ?></a></h2></div>
<?
$child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY menu_order", 'OBJECT');

if ( $child_pages ) :
    foreach ( $child_pages as $pageChild ) :
        setup_postdata( $pageChild );
        $thumbnail = get_the_post_thumbnail($pageChild->ID, 'thumbnail', array( 'class' => 'alignleft' ));
?>
        <div class="child-thumb">
          <a href="<?= get_permalink($pageChild->ID) ?>" rel="bookmark" title="<?= $pageChild->post_title ?>">
            <?= $thumbnail ?>
          </a>
        </div>

<div class="entry-summary"><?php the_excerpt(); ?></div>
<? endforeach; endif; ?>
<?php } ?>
<?php endif; ?>

1 个答案:

答案 0 :(得分:0)