• I’d like to add the excerpt and a featured image to the listing output.

    I’ve had a play with the templates/a-z-listing.php file but haven’t found a way to do it.

    Can anyone help?

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • I see you haven’t done it yet, so this might be useful. I’m not sure if it’s the best way to do it, but it works for me.

    I copied the a-z-listing.example.php file from the templates folder to my child theme’s folder, changed the name to a-z-listing.php, then added the following lines to the while have_items() loop.

    while ( $a_z_query->have_items() ) :
       $a_z_query->the_item(); ?>
       <li>
       <a href="<?php $a_z_query->the_permalink(); ?>"><?php $a_z_query->the_title(); ?></a>
       // ============ START of new lines added  =============
       <?php 
          $a_z_query->query->the_post();
          echo "<br>" . wp_trim_words( get_the_content(), 15, ' ...' ); // 15 words, change to what you like
          wp_reset_postdata(); // Not sure if this is necessary here     
       ?>
       // ============ END of new lines added ================
       </li>
    <?php endwhile; ?>

    You can style it by wrapping it in a div and adding a css class.

    • This reply was modified 7 years, 5 months ago by dougfinn.
    • This reply was modified 7 years, 5 months ago by dougfinn.
    Thread Starter chisomosteve

    (@chisomosteve)

    Thanks a lot, that display some text with each entry.

    I’ve tried adding the following code to display the featured image but it doesn’t work:
    <?php $a_z_query->query->the_post_thumbnail(‘thumbnail’); ?>

    Any idea what would make this work?

    Thread Starter chisomosteve

    (@chisomosteve)

    UPDATE – I’ve had to revert the plugin to 1.9.2 because of this issue:
    https://wordpress.org/support/topic/links-to-a-z-listing-page-not-correctly-output-by-widget/

    Now the code to output the text on the listing isn’t working.

    Plugin Author Dani Llewellyn

    (@diddledani)

    The correct way to get more post information than the title and permalink is to use something similar to below in your a-z-listing.php template file (this is not a complete template):

    while ( $a_z_query->have_items() ) :
    	$a_z_query->the_item();
    	$a_z_query->get_the_item_object( 'I understand the issues!' );
    	?>
    	<li>
    		<h2><a href="<?php $a_z_query->the_permalink(); ?>">
    			<?php $a_z_query->the_title(); ?>
    		</a></h2>
    		<p><?php the_excerpt(); ?></p>
    	</li>
    <?php endwhile; ?>

    Please be aware that on a large list of posts this will cause slowness or hit your memory limit. You need to pass the text I understand the issues! to $a_z_listing->get_the_item_object() exactly as written above to confirm that you understand and accept this could be slow or break due to hitting a memory limit.

    Thread Starter chisomosteve

    (@chisomosteve)

    Ok thanks Daniel.
    Does that only work with version 2?

    Plugin Author Dani Llewellyn

    (@diddledani)

    yes, it only works since 2.0

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Adding Excerpt to listing’ is closed to new replies.