【问题标题】:wordpress multiple page content as postswordpress 多页内容作为帖子
【发布时间】:2015-05-19 17:56:32
【问题描述】:

我正在尝试将多个页面显示为一个类别的帖子页面。

<?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 );

              ?>
                <h2><a href="<?php echo get_page_link( $page->ID ); ?>"><?php echo $page->post_title; ?></a></h2>
                <div class="entry">
                  <?php echo $content; ?>
                  <?php echo $page->post_title; ?> 
                  <?php if(has_post_thumbnail()){ ?>
                      <?php the_post_thumbnail('featured');?>
                  <?php } ?>
                </div>
              <?php
              } 
            ?>

我有这个,但这段代码向我展示了每个页面的全部内容,我需要像帖子一样显示“阅读更多”链接和小内容。任何想法?谢谢

【问题讨论】:

  • 查看the_excerpt() 的小内容和the_permalink() 的阅读更多链接。

标签: php wordpress


【解决方案1】:

使用下面的代码:

<?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 );

           ?>
            <h2><a href="<?php echo get_page_link( $page->ID ); ?>"><?php echo $page->post_title; ?></a></h2>
            <div class="entry">

              <?php echo $page->post_title; ?> 
              <a href="<?php echo get_page_link( $page->ID ); ?>">read more</a>
              <?php if(has_post_thumbnail()){ ?>
                  <?php the_post_thumbnail('featured');?>
              <?php } ?>
            </div>
          <?php
          } 
        ?>

【讨论】:

    猜你喜欢
    • 2021-08-19
    • 1970-01-01
    • 1970-01-01
    • 2017-12-04
    • 2018-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多