Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End the_excerpt

  • This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #189203
    Gary Pickles
    Participant

    Hi All,
    running a loop in wordpress which displays a list of all the posts, showing time, title and the_except from each post.

     <ul>
                <?php
                $myposts = get_posts('numberposts=-1&offset=$debut');
                foreach($myposts as $post) :
                ?>
                <li><?php the_time('d/m/y') ?>: <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><?php the_excerpt(); ?</li>
                <?php endforeach; ?>
            </ul>

    The time and title show fine but the_excerpt on each is the same, It’s first part of the page that its running on.

    Could you tell me what i’m doing wrong or point me in the right direction.

    Thanks

    #189209
    Alen
    Participant

    Are you running multiple loops within the template?

    What do you mean when you say:

    It’s first part of the page that its running on.

    We need little bit more info, you might need to rest metadata, or the issue could be with get_posts which is just a wrapper for WP_Query object.

    #189243
    Gary Pickles
    Participant

    Hi Alen,

    Thanks for getting back to me
    what I’m getting is the Title and the Date from the posts listed down the page, and the text from the page its self, not the text that is assosiated with the posts in the excerpt, there all the same are the excerpts.

    I’ve got rid of everything else on the page and the out put is still the same.

    I’ll read up on reset metadata and try that

    Thought it we straight forward to add the excerpt to this loop as it was already outputting the title and date.

    as you’ve probably guested I’m new to wordpress.

    Gary

    #189244
    Ilan Firsov
    Participant

    According to the documentation you should have a setup_postdata( $post ) call at the start of the foreach loop and a wp_reset_postdata() after the loop.

    #189246
    Shpend Berisha
    Participant

    maybe li element has a height property in css and exerpt is hidden
    try this

    <li><?php the_time('d/m/y') ?>: <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <li><?php the_excerpt(); ?</li>

    or as Alen said give here more info all the tmplate

    #189295
    Gary Pickles
    Participant

    This is my complete template, Sorry to repeat myself, Date and Title display different for each, the excerpt is the text from the homepage which this template is used on, not the text form the posts.

    `
    <?php
    /*
    Template Name: Homepage
    */

    get_header(); ?>

    <?php $debut = 0; //The first article to be displayed ?>

    <?php while(have_posts()) : the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <ul>
    <?php
    $myposts = get_posts(‘numberposts=-1&offset=$debut’);
    foreach($myposts as $post) :
    ?>
    <li><?php the_time(‘d/m/y’) ?>: <a href=”<?php the_permalink(); ?>”>
    <?php the_title(); ?></a><?php the_excerpt(); ?></li>
    <?php endforeach; ?>
    </ul>
    <?php endwhile; ?>

    <?php get_footer(); ?>

    `

    #189297
    Shpend Berisha
    Participant

    try like this

    <?php
    /*
    Template Name: Homepage
    */
    get_header();
    $page_num = $paged;
    if ($pagenum='') $pagenum =1;
    query_posts('showposts=-1&paged='.$page_num); ?>
    <h2><?php the_title(); ?></h2>
    <?php if ( have_posts() ) : ?>
    <ul>
    <?php while ( have_posts() ) : the_post(); ?>
    <li><?php the_time( get_option( 'date_format' ) ); ?>: <a href=”<?php the_permalink(); ?>”>
    <?php the_title(); ?></a><?php the_excerpt(); ?></li>
    <?php endwhile; ?>
    </ul>
    <?php endif; ?>
    <?php get_footer(); ?>
    #189315
    Gary Pickles
    Participant

    Thank you Shpend Berisha, that worked a treat.
    Thanks everyone for your help.

    Just one other thing how do i mark this a solved?

Viewing 8 posts - 1 through 8 (of 8 total)
  • The forum ‘Back End’ is closed to new topics and replies.