WordPress.org

Ready to get started?Download WordPress

Forums

How to post an excerpt ONLY from each category on the home page? (7 posts)

  1. gayeta
    Member
    Posted 6 years ago #

    Provided there are only 3 post categories (Profiles, Knowledge Bank, Features) is there a way to display the excerpt of latest article of each category on the homepage? So at any given time, there are only 3 posts shoing on the home page, 1 Profile excerpt, 1 Knowledge Bank excerpt and 1 Feature excerpt.

    At the moment it will dispay the latest posts, regardless of the category.

    The page I I working on is located here: http://www.newenergyworldnetwork.com/index.php

    I'd appreciate your help!

    Cheers
    gayeta

  2. moshu
    Member
    Posted 6 years ago #

    You will, probably, need 3 custom Loops

  3. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Or one Loop with three passes... ;)

    $mycats = array(1,2,3); // the category ID numbers
    foreach ($mycats as $catid) :
    query_posts(array('cat'=>$catid,'showposts'=>1));
    while (have_posts()): the_post();
    the_title();
    the_excerpt();
    // whatever you are displaying here
    endwhile;
    endforeach;
  4. moshu
    Member
    Posted 6 years ago #

    OK, listen to Otto... he's the PHP wizard :)

  5. gayeta
    Member
    Posted 6 years ago #

    fabulous guys, I will give it ago, thanks a million! :-)

  6. gayeta
    Member
    Posted 6 years ago #

    Hi again,

    I was trying to incorporate Otto42's code but I am getting some errors:

    Parse error: syntax error, unexpected T_ELSE in /home/fhlinux147/n/newenergyworldnetwork.com/user/htdocs/wp-content/themes/tomodachi/index.php on line 34

    I have added it to index.php. Unfortunately I am very far away from being a php whizz, I must have messed something up. Please help!

    Below I pasted the idex.php code:

    <?php get_header(); ?>
    <div id="left">
    
    <?php
    
    $mycats = array(1,2,3); // the category ID numbers
    foreach ($mycats as $catid) :
    query_posts(array('cat'=>$catid,'showposts'=>1));
    while (have_posts()): the_post();
    the_title();
    the_excerpt();
    // whatever you are displaying here
    
    ?>
    
    <div class="post">
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <p class="postinfo"><img src="<?php bloginfo('template_url'); ?>/images/ico_auth.jpg" alt="Author" /> <?php the_author() ?> on <?php the_time('F jS, Y') ?></p>
    
    	<?php the_excerpt('Read the rest of this entry &raquo;'); ?>
    
    <div class="post_end"><?php the_tags('Tags: ', ', ', '<br />'); ?><img src="<?php bloginfo('template_url'); ?>/images/ico_link.jpg" alt="permalink" /><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">Read More</a> <img src="<?php bloginfo('template_url'); ?>/images/ico_com.jpg" alt="Comment" width="18" height="13" /><a href="<?php comments_link(); ?>">Comments (<?php comments_number('0','1','%'); ?>)</a> <img src="<?php bloginfo('template_url'); ?>/images/ico_cat.jpg" alt="Cat" width="15" height="13" /><?php the_category(', ') ?><?php edit_post_link('Edit', ' | ', ''); ?>
    </div>
    </div>
    
    <?php endwhile; ?>
    <?php endforeach; ?>
    
    <div class="page_nav">
    			<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    			<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
    </div>
    	<?php else : ?>
    
    		<h2>Not Found</h2>
    		<p>Sorry, but you are looking for something that isn't here.</p>
    
    	<?php endif; ?>
    
      </div>
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
  7. moshu
    Member
    Posted 6 years ago #

    When you need to post long code, use a pastebin service like http://wordpress.pastebin.ca

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags