Forums

List category posts
[resolved] Comma separated list of post titles (5 posts)

  1. cosmicjellybaby
    Member
    Posted 3 months ago #

    Can I just say how much I love lcp. It is just awesome. I am trying to create a template that will show my post titles in a comma separated list, i.e.

    item1, item2, item3

    For stylistic reasons, it is important that there is no lead or trailing comma, so I don't want:

    , item1, item2, item3,

    Can anybody assist me in this endeavour?

    http://wordpress.org/extend/plugins/list-category-posts/

  2. cosmicjellybaby
    Member
    Posted 3 months ago #

    I have had a go at doing this and it looks like it might be ok, it's just that I am getting other pieces of code included within my 'ul' tags.

    Here's what is in my template:

    $lcp_display_output = '';
    
    $lcp_display_output .= $this->get_category_link('strong');
    
    $lcp_display_output .= '<ul class="comma_separated">';
    
    // Posts loop.
    
    	$lcp_display_output .= '';
    
        foreach ($this->catlist->get_categories_posts() as $single):
    
            $lcp_display_output .= $this->get_post_title($single);
    	$lcp_display_output .= ', ';
    
        endforeach;
    
    echo rtrim($lcp_display_output, ', ');
    
        $lcp_display_output .= '</ul>';

    Any thoughts? It can be viewed here: http://iwantfootball.co.uk/uncategorized/test-page-comma-separated-list-using-template

  3. cosmicjellybaby
    Member
    Posted 3 months ago #

    OK, so I've played some more and I can now get the output from the plugin to be contained within its ul tags. The only problem is now that the output is appearing at the top of the div which contains the text of my post, regardless of where I have laid it out in the wordpress edit post pane. This is my template info:

    $lcp_display_output = '';
    
    $lcp_display_output .= $this->get_category_link('strong');
    
    $lcp_display_output .= '<ul class="comma_separated">';
    
    // Posts loop.
    
    $lcp_display_output .= '';
    
    	foreach ($this->catlist->get_categories_posts() as $single):
    
            $lcp_display_output .= $this->get_post_title($single). ", ";
    
            endforeach;
    
    $lcp_display_output = rtrim($lcp_display_output , ', ');
    
        $lcp_display_output .= '</ul>';
    
    	echo $lcp_display_output ;

    Any thoughts?

  4. alchymyth
    The Sweeper
    Posted 3 months ago #

    the output is appearing at the top of the div which contains the text of my post, regardless of where I have laid it out in the wordpress edit post pane

    try to use return $lcp_display_output ;

    (I haven't checked the rest of the code)

  5. cosmicjellybaby
    Member
    Posted 3 months ago #

    Thanks for your input alchymyth. I tried it, but to no avail. However, I did reinstate the original output line of
    $this->lcp_output = $lcp_display_output;
    and bingo! It works perfectly! Not sure why I removed it in the first place... ;-)

Reply

You must log in to post.

About this Plugin

About this Topic