• Hello,
    i’m trying to customise my index page with ‘the loop’,
    what i want is to display 5 full posts and then only 5 resumes of posts (and then on the next pages, only resumes ; i’m not sure that this last idea is possible btw)

    i know i need to use the the_excerpt() instead of the the_content(), but what gives me problems is the loop,

    i tried to find examples on Rhymed code ( https://rhymedcode.net/1001-wordpression-loops/ ) or the codex, but it’s a bit too hard for my codec skills, can someone help me with the loop ?

    thanks!

Viewing 11 replies - 1 through 11 (of 11 total)
  • 1. Go to “Options” -> “Reading” and set “Show at most” to “10 posts.”

    2. Copy “index.php” as “paged.php”

    In “index.php”
    3. Before the following line,

    if( have_posts() ) :

    …add the following.

    <?php $wp_query->set( 'showposts', '5' ); ?>
    <?php query_posts( '' ); ?>

    4. Inside the Loop, make sure to call the template tag “the_content()”

    5. Still in “index.php,” add another Loop after the first one.

    <?php $posts = get_posts( "numberposts=5&offset=5″ ); ?>
    <?php if( $posts ) : ?>

    <div class="section" id="theRest">
    <h2>The rest...</h2>
    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
    <div>
    // call "the_excerpt" and whatever you need
    </div>

    <?php endforeach; ?>;

    </div>

    <?php endif; ?>

    6. to be continued…

    Thread Starter david67

    (@david67)

    thanks for the help,

    in fact i changed the code to display 1 post then some contest and then 4 else posts (5 posts in total)

    i suceeded to do the first part : display 1 post and after i got a wierd error, here is my code :

    <?php $wp_query->set( ‘showposts’, ‘1’ ); ?>
    <?php query_posts( ” ); ?>

    <?php if (have_posts()) : ?>

    <?php while (have_posts()) : the_post(); ?>

    <div class=”post” id=”post-<?php the_ID(); ?>”>
    <h2>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”><?php the_title(); ?></h2>
    <div id=”postmetadata”><?php the_time(‘F jS, Y’) ?>. Posted by <?php the_author() ?> <?php edit_post_link(‘Edit’,'[‘,’]’); ?>
    Read more about : <?php the_category(‘,’) ?></div>

    <div class=”entry”>
    <?php the_content(‘Read the rest of this entry »’); ?>
    </div>

    <div id=”metadata_bas”>“>permanent link <?php comments_popup_link(‘Post a Comment’, ‘1 Comment’, ‘% Comments’); ?></div>
    </div>

    <?php endwhile; ?>

    <div class=”navigation”>
    <div class=”alignleft”><?php next_posts_link(‘« Previous Entries’) ?></div>
    <div class=”alignright”><?php previous_posts_link(‘Next Entries »’) ?></div>
    </div>

    <?php else : ?>

    <h2 class=”center”>Not Found</h2>
    <p class=”center”>Sorry, but you are looking for something that isn’t here.
    <?php include (TEMPLATEPATH . “/searchform.php”); ?>

    <?php endif; ?>

    <?php $posts = get_posts( “numberposts=4&offset=1? ); ?>
    <?php if( $posts ) : ?>
    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>

    <div class=”post” id=”post-<?php the_ID(); ?>”>
    <h2>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”><?php the_title(); ?></h2>
    <div id=”postmetadata”><?php the_time(‘F jS, Y’) ?>. Posted by <?php the_author() ?> <?php edit_post_link(‘Edit’,'[‘,’]’); ?>
    Read more about : <?php the_category(‘,’) ?></div>

    <div class=”entry”>
    <?php the_content(‘Read the rest of this entry »’); ?>
    </div>

    <div id=”metadata_bas”>“>permanent link <?php comments_popup_link(‘Post a Comment’, ‘1 Comment’, ‘% Comments’); ?></div>
    </div>

    <?php endforeach; ?>;
    <?php endif; ?>

    </div>

    <?php get_sidebar(); ?>

    <?php get_footer(); ?>

    Thread Starter david67

    (@david67)

    btw what are backticks ?
    //Put code in between backticks.

    backtick = backward facing tick. On most full keyboards, it is up next to the left of the “1” key.

    Thread Starter david67

    (@david67)

    are backticks those : ‘
    i’m using an azerty keyboard ??

    on the left of the one key i got this : 2

    This critter: `

    For large blocks of code the better option is to paste your code at a pastebin site and link to it here:

    https://pastebin.co.uk
    https://pastebin.com
    https://paste.uni.cc

    Thread Starter david67

    (@david67)

    thanks for the links !

    i tried this :
    https://pastebin.co.uk/602

    in fact i have 5 posts per page, i display one post some links and then 4 posts

    the display of the 1 post is ok, but i have a problem to display the 4 others,

    i tried to start the 4posts_loop but it don’t work,
    <?php $posts = get_posts( “numberposts=4&offset=1? ); ?>
    <?php if( $posts ) : ?>

    i got this error :
    Parse error: parse error, unexpected $ in /home/rollerne/public_html/v3/wp-content/themes/rn/index.php on line 102

    and 102 is an empty line !

    help ??

    thanks!

    Thread Starter david67

    (@david67)

    anyone ? :/

    Thread Starter david67

    (@david67)

    hi have a little question, thanks.

    is the <?php $posts = get_posts( “numberposts=5&offset=5″ ); ?> request correct ? i get a parse error using it :/

    David.

    Try without the $posts=
    I use get_posts and don’t have that anywhere…

    EDIT: hang on thats not true at all! I will have a look at my index for you..

    try putting the get_posts section before your <?php else : ?> and <?php endif; ?>

    I’ve put my code up at https://pastebin.co.uk/619
    not sure it will help as it is a bit of a mess but it definitly works!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘playing with ‘the loop’’ is closed to new replies.