WordPress.org

Ready to get started?Download WordPress

Forums

Only display first post full in category view (9 posts)

  1. Rinkweijs
    Member
    Posted 3 years ago #

    Is there a way to display the first post on a category view as full content? I already use astickypostorderer. I can make the post sticky, but then it shows up on my homepage, which I don't want. Rather only in the specific category it's filled under. Theme is Desire 1.0. How can I do this?

  2. stvwlf
    Member
    Posted 3 years ago #

    I downloaded Desire 1.0 and made a few changes to the archive.php file. You can grab the code here http://pastebin.com/WhzS0YKU

    Rename your theme's original archive.php file (to keep as backup). And save the code you'll see in the pastebin to filename archive.php - then FTP that to your theme folder.

    I think I got the code correctly. When its displaying a category page it uses the_content() on the 1st post to display its full content, and the_excerpt() on the rest to display the summary. Now, if you have some categories with enough posts to have more than one page, it will probably display the full post content on the 1st post on every page in the category. It can be adjusted to not do that but that hasn't been set up in what I posted.

    Hope its helpful

  3. Rinkweijs
    Member
    Posted 3 years ago #

    Thanks for your quick respons! It already a step closer than I was myself! I do have to be more specific because a friend did some html editting in the archive file before.

    Is it possible to show ONLY one specific category full post? You can see my website at http://www.bio-logicalsolutions.nl and there is the first post under 'Actualiteiten' which contains Google Reader stuff. I would like to show this post full/sticky. Is it possible to specify this in the archive.php file?

    Here's the code:

    [code moderated per forum rules - please use the pastebin]

    Hope this makes sense...

  4. Digital Raindrops
    Member
    Posted 3 years ago #

    Here is untested sample code but it should give you the right structure and ideas, this will show the first (latest) post content then the others as excerpts.

    <?php
    $counter = 0;
     if (have_posts()) :
    	while (have_posts()) : the_post(); ?>
    	 <div id="post-<?php the_ID(); ?>" <?php post_class() ?>>
    		 <h2 class="title">" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></h2>
    		 <div class="entry">
    		 <?php if( $counter ) : ?>
    			<?php the_excerpt(); ?>
    		 <? else : ?>
    			<?php the_content(); ?>
    		 <?php endif; ?>
    		 </div>
    	<?php $counter++; ?>
    	<?php endwhile; ?>
    <?php endif; ?>

    HTH

    David

  5. Rinkweijs
    Member
    Posted 3 years ago #

    Hi David,

    Does this code work for all categories or specific for the 'Actualiteiten' category (this is the only one I would like it to apply to)?

    Rink

  6. Digital Raindrops
    Member
    Posted 3 years ago #

    If you already know the Actualiteiten cat_ID as it is quite specific, lets say it was category 22!

    <?php
    global $cat;
    $counter = ($cat == 22) ? 0 : 1;

    or if you want to make it easy to read:

    <?php
    global $cat;
    $curr_cat = get_category($cat);
    $counter = ($curr_cat->slug == 'actualiteiten' ) ? 0 : 1;

    If the category is a match then the counter is ? 0 (false) else : it is 1 (true)

    If you make the post not sticky how are you going to make it the first post all the time, when you add new posts to the category?

    One way would be to set the date and time of the post you want first to be the latest.

    Also consider Template Hierarchy, you can copy category.php and name it category-{slug}.php so category-actualiteiten.php and add in code to return the main post first, no need for counters.

    HTH

    David

  7. Rinkweijs
    Member
    Posted 3 years ago #

    Hi David,

    It's ID is 14 I guess from this link (http://www.bio-logicalsolutions.nl/wp-admin/edit-tags.php?action=edit&taxonomy=category&tag_ID=14&post_type=post)

    So that would be:

    <?php
    global $cat;
    $counter = ($cat == 14) ? 0 : 1;

    But, where do I past it in the archive.php file??

    Or should I use this instead:
    <?php
    global $cat;
    $curr_cat = get_category($cat);
    $counter = ($curr_cat->slug == &#014;actualiteiten&#014; ) ? 0 : 1;

    Again: where should I add this? To me it's a bit abacadabra... And can you tell me what the difference is between these?

    Thanks,

    Rink (somewhat a html illiterate)

  8. Digital Raindrops
    Member
    Posted 3 years ago #

    You have to look at the structure above and match it to your file, and decide where it fits in, but the main part is before the start of the loop, the if( have_posts() ) and the other part is further down the file where the html is rendered.

    I am off now so someone else might pick this up, use the link to pastebin above from the moderator, paste in the archive page code, then paste the pastebin url back here!

    Note:
    The first is using the category id, the second is using the slug, in six months time you may forget what 14 is or does where the name will make a better read.

    HTH

    David

  9. Rinkweijs
    Member
    Posted 3 years ago #

    I'll experiment with it. Thanks David! I appreciate your effort!

Topic Closed

This topic has been closed to new replies.

About this Topic