WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] More tag ignored when displaying sub pages

[Resolved] More tag ignored when displaying sub pages

  • I’m reposting this from another forum.

    I know other people have had a similar problem and I’ve browsed through the forum and Codex, but I haven’t been able to solve this problem.

    I’m showing sub pages on top level pages using get_pages:

    <?php
        $pages = get_pages('child_of='.$post->ID.'&sort_column=menu_order&sort_order=asc');
        $count = 0;
        foreach($pages as $page) {
            $content = $page->post_content;
            if(!$content)
                continue;
            $count++;
            $content = apply_filters('the_content', $content);
            $content = str_replace(']]>', ']]>', $content);
    ?>
            <div id="<?php echo $page->post_name ?>" class="page">
                <h3 class="post-title"><?php echo $page->post_title ?></h3>
                <div class="post-body">
                    <?php echo $content ?>
                </div>
            </div>
    <?php } ?>

    The problem is that <!--more--> gets ignored. I know of the proposed solution mentioned here, but it doesn’t work for me. I’ve tried to add the snippet in every part of the code, before the loop, inside the loop, you name it.

    The more tag is just displayed as paragraph: <p><!--more--></p>

    Many of the people that had similar problems weren’t using get_pages so I’m thinking the problem is somewhere there (or how the main content is defined inside a single page of loop).

    Any help? Deadline is approaching and I’ve hit a wall with this. Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Sorry, my post had messed up. The word “here” was supposed to contain a link to that exact Codex post.

    Is that solution supposed to work with get_pages? I’ve tried to put that snippet of code to pretty much every part of the loop, and it doesn’t work.

    This example works:

    <?php
    $args=array(
      'post_parent' => 93,
      'orderby'=> 'menu_order',
      'order'=>'ASC',
      'post_type' => 'page',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Posts';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
        global $more;
        $more = 0;
        the_content();
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Thank you!! I had thought if using WP_Querywould solve this, but get_pages is just somehow so much simpler to use that I always utilized it instead.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] More tag ignored when displaying sub pages’ is closed to new replies.
Skip to toolbar