- This topic is empty.
-
AuthorPosts
-
November 25, 2014 at 12:18 pm #189203
Gary Pickles
ParticipantHi 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
November 25, 2014 at 1:30 pm #189209Alen
ParticipantAre 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.November 26, 2014 at 1:07 am #189243Gary Pickles
ParticipantHi 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
November 26, 2014 at 1:14 am #189244Ilan Firsov
ParticipantAccording to the documentation you should have a
setup_postdata( $post )
call at the start of the foreach loop and awp_reset_postdata()
after the loop.November 26, 2014 at 1:54 am #189246Shpend Berisha
Participantmaybe 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
November 26, 2014 at 1:59 pm #189295Gary Pickles
ParticipantThis 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(); ?>
`
November 26, 2014 at 2:31 pm #189297Shpend Berisha
Participanttry 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(); ?>
November 26, 2014 at 4:23 pm #189315Gary Pickles
ParticipantThank you Shpend Berisha, that worked a treat.
Thanks everyone for your help.Just one other thing how do i mark this a solved?
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.