WordPress.org

Forums

How might I list an excerpt of a Page? (10 posts)

  1. estevancarlos
    Member
    Posted 5 years ago #

    I want to have a link to a page in a sidebar but have it show an excerpt. I'm not sure if I should use the list pages thing or query posts. Any suggestions? Is there some easy way to perform this?

  2. Jonas Grumby
    Member
    Posted 5 years ago #

    You probably need to have something like this in the sidebar:

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    <div class="whateveryouwant">
    <?php the_excerpt('Read the rest of this entry &raquo;'); ?>
    </div>
    </div>
    <?php endwhile; ?>
    <?php endif; ?>
  3. Jonas Grumby
    Member
    Posted 5 years ago #

    or maybe just

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class="whateveryouwant">
    <?php the_excerpt('Read the rest of this entry &raquo;'); ?>
    </div>
    <?php endwhile; ?>
    <?php endif; ?>
  4. Jonas Grumby
    Member
    Posted 5 years ago #

    p.s that would (maybe) turn your sidebar into sort of a blog homepage.

    Anyway, I have to hang it up for the night.

  5. estevancarlos
    Member
    Posted 5 years ago #

    Thanks for the push in a clearer direction. The only catch is I want it to load an excerpt of a specific page. I'm actually using this now:

    <?php global $post; $myposts = get_posts('numberposts=1&post_type=page&name=about'); ?>

    After that I have some code to show an excerpt. However the "name=about" does not work. When I remove the name part, it's fine. I don't understand that component. I just need it to load one specific page.

  6. nouveller
    Member
    Posted 5 years ago #

  7. estevancarlos
    Member
    Posted 5 years ago #

    Actually, also, this excerpt thing isn't really working properly. I want an excerpt in a sidebar. I want only an excerpt in all instances. For some reason, if you click on an unrelated post in the main area, it will reload the sidebar and show the entire content in the sidebar instead of the excerpt. I would assume the content only shows when you click on the specific item to read it. I don't follow why it would show the full content even when I'm reading something else.

  8. estevancarlos
    Member
    Posted 5 years ago #

    Yeah, I later noticed my mistake but I'm using get_posts instead of query_posts.

  9. Jonas Grumby
    Member
    Posted 5 years ago #

    I was just going to send you the same link that @nouveller already posted.

  10. estevancarlos
    Member
    Posted 5 years ago #

    to my understanding "get_posts" doesn't support pagename:

    http://codex.wordpress.org/Template_Tags/get_posts

    and I used "name" incorrectly earlier. that was for ordering.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags