子页面摘录

时间:2013-11-20 07:18:22

标签: wordpress

我有这个代码,用他们的缩略图和标题显示我的子页面。 我添加了另一行显示摘录的行,但是当我点击“查看更多”时它没有链接到页面。 这是我使用的代码:

     <?php
    //list of all sub pages with thumbmails//
    $child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY menu_order", 'OBJECT'); ?>
      <?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild ); ?>
      <li>
        <div class="child-thumb">
        <div class="child-thumbFrame"><?php if ( has_post_thumbnail($pageChild->ID) ) { echo get_the_post_thumbnail($pageChild->ID, 'planesThumb'); }
else {
    echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/thumbnail-default.jpg" />';}?></div>
        <div class="child-thumb-titels">
        <a href="<?php echo get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>"><?php echo $pageChild->post_title; ?> </a>
        <div class="child-thumb-excerpt"><?php $customLength=20; echo get_the_excerpt($post->ID); ?></div>

         </div></li>

      <?php endforeach; endif;?>
      <?php endwhile; ?>
      <?php endif; ?>

非常感谢!

1 个答案:

答案 0 :(得分:0)

首先,在给定的代码中没有更多的观点 以下代码将完成所需的工作

$child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = 13 ", 'OBJECT');

?>
<?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild ); ?>
  <li>
    <div class="child-thumb">
    <div class="child-thumbFrame">
  <?php if ( has_post_thumbnail($pageChild->ID) ) 
  { echo get_the_post_thumbnail($pageChild->ID, 'planesThumb'); }
    else { echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/thumbnail-default.jpg" />';}?>
    </div>
    <div class="child-thumb-titels">
    <a href="<?php echo get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>"><?php echo $pageChild->post_title; ?> </a>
    <div class="child-thumb-excerpt">
        <?php $customLength=20; echo get_the_excerpt($post->ID); ?>
        <a href="<?php echo get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>">View more</a>
    </div>

     </div></li>

  <?php endforeach; endif;?>

将此代码放在查询循环中,您的代码没有任何问题。