Forums

[Plugin: List category posts] How to get Excerpt to show underneath link? (8 posts)

  1. aminalcwakerz
    Member
    Posted 5 months ago #

    I got the excerpt to show up using in list-cat-posts.php (line 64):

    if( $single->post_excerpt ) {
    $bodycontent=$single->post_excerpt;
    } else {
    $bodycontent=$single->post_content;
    }

    $output.="";
    $output.=$bodycontent;
    $output.="";

    You can see it at: http://forthmagazine.com/upcoming-events/
    Problem is, it won't line break. I've tried using "\n"; but it won't work.

  2. janecraft
    Member
    Posted 5 months ago #

    Thanks for the excerpt functionality! Did you solve the line-break/formatting issue?

  3. tgebauer
    Member
    Posted 4 months ago #

    To fix the line breaks after the author, change the query (starting on line 61, at least in my editor) to this :

    if($atts['author']=='yes'){
    $lcp_userdata = get_userdata($single->post_author);
    $output.=" - ".$lcp_userdata->user_nicename."<br />";
    }

    the real change is in the ".$lcd_userdata->user_nicename."<br />";

    Works for me at least...

  4. tgebauer
    Member
    Posted 4 months ago #

    Also changed the default output from "list" to "paragraph" by making the following changes:

    //Build the query for get_posts()
    $catposts=get_posts($category.'&numberposts='.$atts['numberposts'].'&orderby='.$atts['orderby'].'&order='.$atts['order']);
    foreach($catposts as $single):
    $output .= "<p><a href='".get_permalink($single->ID)."'>".$single->post_title."</a>";
    if($atts['date']=='yes'){
    $output.=" - ".$single->post_date;
    }

    and the correpsonding closing tag to: (again from ) to

    $output.="</p>";
    endforeach;
    $output .= "</ul>";
    return $output;
    }

    I left the UL there - will work with that later I guess.

  5. janecraft
    Member
    Posted 3 months ago #

    Thanks for all the tips. I thought I'd post my solution as well in case it's helpful.

    For the excerpt, I inserted a single line at line 66 (before endforeach;) in list_cat_posts.php (v0.4.1):

    $output .= "<p>$single->post_excerpt</p>";

    I used div, h2, and p tags rather than ul and li. It worked better with my theme and it also fixed the break issue with the excerpt. So, the complete code from line 43 to line 70 (was 69!) looks like this:

    function list_category_posts($atts){
      $output .= "<div class='custom-style'>";
      if($atts['name']!='default' && $atts['id']!='0'){
        $category='category_name='.$atts['name'];
      }else{
        $category='category='.$atts['id'];
      }
      /*I should check this for the next version: ('category__in' => array(2,6))
        to allow posts from many categories.
        http://codex.wordpress.org/Template_Tags/get_posts#Parameters:_WordPress_2.6.2B */
    
      //Build the query for get_posts()
      $catposts=get_posts($category.'&numberposts='.$atts['numberposts'].'&orderby='.$atts['orderby'].'&order='.$atts['order']);
    foreach($catposts as $single):
      $output .= "<h2><a href='".get_permalink($single->ID)."'>".$single->post_title."</a>";
      if($atts['date']=='yes'){
        $output.=" - ".$single->post_date;
      }
      if($atts['author']=='yes'){
        $lcp_userdata = get_userdata($single->post_author);
        $output.=" - ".$lcp_userdata->user_nicename;
      }
      $output.="</h2>";
      $output .= "<p>$single->post_excerpt</p>";
      endforeach;
      $output .= "</div>";
      return $output;
    }
  6. davidmaguire
    Member
    Posted 2 months ago #

    Just spent some time digging through this one for the widget and wanted to list the post title with the excerpt for context.

    Here's my solution, in case anyone needs it @line 20-25 in list_cat_posts_widget.php

    foreach($lcp_catposts as $lcp_single):
      $lcp_result.='<li><a href="'.get_permalink($lcp_single->ID).'">'.$lcp_single->post_title.'</a></li><li><p>'.$lcp_single->post_excerpt.'</p>';
      endforeach;
      $lcp_result .= "</ul>";
      echo $lcp_result;
    }

    hth,

    David

  7. fernandobt
    Member
    Posted 1 month ago #

    Since List Category Posts 0.5, you may show the excerpt using the plugin. You just need to add "excerpt=yes" to the shortcode, and if there's an excerpt for the post, it'll be displayed.

    There's also a new templates system for you to use ul, h3 or whatever style you need. Check it out:
    List Category Posts

  8. netviper
    Member
    Posted 5 days ago #

    I can't seem to get it to work using your "excerpt=yes"

Reply

You must log in to post.

About this Topic