WordPress.org

Ready to get started?Download WordPress

Forums

Custom Archive Display with Excerpts (2 posts)

  1. novice21
    Member
    Posted 7 years ago #

    I have a frustrating question to ask, it's taking me aaages to find an answer through Google. The concept is deceivingly simply yet the execution seems like a nightmare!! I’m sure someone who has more programming brains than I do figured out a solution…please share your brilliance with a poor soul.

    I'm working on a template page, archives.php, it's supposed to list my archives in this manner:

    October 2006
    excerpts of posts in that month
    January 2007
    excerpts of posts in that month
    March 2007
    excerpts of posts in that month

    I can't figure it out though. You definitely need multiple loops for this, right? I know wp_get_archives(); will list the title posts I need, but what do I need to combine it with to get the excerpts out instead of a list with title links? Is there a way at all?

    I can't even figure out how to get wp_list_categories(); to do the same for me to display excerpts in categories. I have a different template page that I’m using to display the archives like this;

    Category 1
    excerpts of posts in that category
    Category 2
    excerpts of posts in that category
    Category 3
    excerpts of posts in that category

    I know archive.php has the code to display only 1 category or a certain date range and I can get it to display excerpts there, but I need multiple listings with the excerpts and I cant seem to work off the code in there, help?!

    (I don’t know if this matters to whoever replies, but my excerpts don’t have text, they’re an image tag…I don’t think it matters though…just putting it out there in case it does)

    Thanks for taking the time to read this!!

  2. alakhnor
    Member
    Posted 7 years ago #

    Recently, I've done this for a friend of mine:

    <?php // List of post sort in ascending alphabetic
    
    			$first_letter = '';
    			$abc_title = '';   				// tag for letter title
    			$abc_title_before = '<h3>';			// before letter
    			$abc_title_after = '</h3>';			// after letter
    			$abc_before_list = '<ul>';			// between letter and list
    			$abc_after_list = '</ul>';			// end of a list
    			$abc_after_letter = '</div>';			// after end of a list, before next letter
    			$abc_before_letter_b = '<div id="alpha-';	// before list and letter: before
    			$abc_before_letter_a = '">';			// before list and letter: after
    			$nombre = array ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
    
    			// last post
     			$myposts = get_posts('numberposts=1&category=1');
    			foreach ($myposts as $post) :
    			setup_postdata($post);
    			// display post ?>
    				<div class="entry entry-<?php echo $post->ID ;?>">
    					<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?><span style="display : none;">(<?php foreach((get_the_category()) as $cat) { echo $cat->cat_name . ' | '; } ?>)</span></a></h2>
    
    					<div class="entrybody">
    						<?php the_content("...lire la suite de " . get_the_title('', '', false)); ?>
    					</div>
    
    					<div class="undertitle">
    						<div class="auteur">
                                                    	<?php if(function_exists('cmd_show_avatar')){ cmd_show_avatar(); } ?></div><small><?php the_time('l j F Y') ?> par <a href="http://www.le-hiboo.com/author/<?php the_author_login(); ?>" title="Voir tous les billets de <?php the_author() ?>"><?php the_author() ?></a></small> <small>Cat&eacute;gorie : <?php the_category(', ') ?></small><small>Cet billet a &eacute;t&eacute; <?php /* show_post_count($post->ID, $before="vu ", $after=""); */ ?> fois</small>
    						</div>
    					<div class="entrymeta">
    						<?php comments_popup_link('0 commentaire »', '1 commentaire »', '% Commentaires »', 'commentslink'); ?><?php edit_post_link('Modifier le billet', ' | ', ''); ?>
    					</div>
    				</div>
                            <?php endforeach; ?>
    <?php
    
    			// display list of all posts sorted alphabetic
     			$posts = get_posts('numberposts=100&order=asc&category=1&orderby=post_title');
     			echo '<h3>'.count($posts).' films chroniqu&eacute;s</h3>';
    			foreach ($posts as $post) :
    				setup_postdata($post);
      				$fl_post = strtoupper(substr($post->post_title, 0, 1));
      				if (in_array($fl_post, $nombre)) $fl_post = '0-9';
      				if ($fl_post != $first_letter)
      				{
            				if ($first_letter != '') echo $abc_after_list.$abc_after_letter;
            				echo $abc_before_letter_b.$fl_post.$abc_before_letter_a;
            				echo $abc_title_before.$abc_title.$fl_post.$abc_title_after;
    					echo $abc_before_list;
      				}
    				// display post ?>
    
    				<h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    <?php
    
    			// end display post
      				$first_letter = strtoupper(substr($post->post_title, 0, 1));
      				if (in_array($first_letter, $nombre)) $first_letter = '0-9';
                            endforeach;
                            echo $abc_after_list.$abc_after_letter;
    
    /* End of alphabetical sort */ ?>

    It displays the list of post by alphabetic order with latest post coming first, then the list (this is for a specific category here). You may use it for your needs.

Topic Closed

This topic has been closed to new replies.

About this Topic