• Hi within my archives.php i’ve put the following code to display the first post and list the rest after. For some reason it’s always showing the last post and not the last post of the category. Any idea as to why? I’m clueless.

    All I want is for the first post of any category to be displayed and the rest to be displayed as lists.

    Any help would be appreciated.

    Thanks!

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

    <!-- First Post -->
    <?php $top_query = new WP_Query('showposts=1'); ?>

    <?php while($top_query->have_posts()) : $top_query->the_post(); $first_post = $this_category->ID; ?>
    <div class="post top" id="post-<?php the_ID(); ?>">
    <h2 class="first"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    <span class="postmetadata">&bull; <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?> <?php edit_post_link('Edit', '(', ')'); ?></span>

    <div class="entry">
    <?php the_content("<span class=\"continue\">" . __('Continue reading','') . " '" . the_title('', '', false) . "'</span>"); ?>
    </div>
    </div>

    <?php endwhile; ?>

    <!-- Next few posts -->
    <?php while(have_posts()) : the_post(); if(!($first_post == $post->ID)) : ?>

    <div class="post lastfive" id="post-<?php the_ID(); ?>">
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    <span class="postmetadata">&bull; <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?> <?php edit_post_link('Edit', '(', ')'); ?></span>

    <div class="entry">
    <?php the_excerpt(); ?>
    </div>
    </div>

    <?php endif; endwhile; ?>

Viewing 7 replies - 1 through 7 (of 7 total)
  • Are you trying it in the archive.php or archives.php file? It should be `archive.php – no S!

    Thread Starter effour

    (@effour)

    it’s in the archive.php file, my bad. have a look at the site and check a category to see what i mean.

    https://www.vancityriders.com

    thx!

    Hi effour
    I know this Blog is in German language, but Code is international ?? and if you have any question, please use my comments.
    This Code shows the first article full and the rest with the excerpt,

    First article in the archive.php

    regards
    Monika

    Thread Starter effour

    (@effour)

    thanks monika!! worked great!!

    Not sure where to post this. I’m a novice at wordpress but a programmer for 20+ years, proficient in php and mysql. Still having trouble learning the wordpress codex.

    Anyway, I want to list the First Entry, Previous 2 Entries, Current Entry with no link, Next 2 Entries, and Last Entry for EVERY SINGLE STORY and EVERY CATEGORY for that single story.

    This is how I want the links formatted in the sidebar on my single story page:

    <h5>Archive by Date<h5>

    <ul>
    <li><a href="whatever">First Entry</a></li>
    <li><a href="whatever">2006-10-03</a></li>
    <li><a href="whatever">2006-10-17</a></li>
    <li class="thisentry">2006-11-01</li>
    <li><a href="whatever">2006-11-17</a></li>
    <li><a href="whatever">2006-12-03</a></li>
    <li><a href="whatever">Latest Entry</a></li>
    </ul>

    <h5>This Archive's Categories</h5>

    <h6>Dreams</h6>

    <ul>
    <li><a href="whatever">First Entry</a></li>
    <li><a href="whatever">2006-10-01</a></li>
    <li><a href="whatever">2006-10-15</a></li>
    <li class="thisentry">2006-11-01</li>
    <li><a href="whatever">2006-11-15</a></li>
    <li><a href="whatever">2006-12-01</a></li>
    <li><a href="whatever">Latest Entry</a></li>
    </ul>

    <h6>Spirit Visitations</h6>

    <ul>
    <li><a href="whatever">First Entry</a></li>
    <li><a href="whatever">2006-10-02</a></li>
    <li><a href="whatever">2006-10-16</a></li>
    <li class="thisentry">2006-11-01</li>
    <li><a href="whatever">2006-11-16</a></li>
    <li><a href="whatever">2006-12-02</a></li>
    <li><a href="whatever">Latest Entry</a></li>
    </ul>

    Any ideas?

    1. Learn posting the code: the instructions are below the text input area = use backticks [`] and NO blank lines in the code.

    2. Define “last entry for single story” – what is an entry and what is a story.

    There is no last entry for a single story, per se. In the “archive by date” list, the Latest Entry would be the most recent entry, period. In the “this entry’s categories” list, the Latest Entry would be the most recent entry in that category.

    The purpose is to use Categories as threaded entries. It’s a multi-layered cohesive story.

    Make sense?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘display first post in category’ is closed to new replies.