WordPress.org

Ready to get started?Download WordPress

Forums

Display Posts Shortcode
[resolved] Display Titles on Separate Lines (5 posts)

  1. gregcrowe
    Member
    Posted 1 year ago #

    Hi! Awesome plugin, BTW.

    I had a question about display formatting. Is there an easy way to get the titles of the posts to display on a separate line from the date and excerpt? I can find in the code in display-posts-shortcode.php that outputs the listing-item, but I know that isn't the best way to go about it. I didn't think there was any way to accomplish it with just CSS.

    What other options are there?

    Thanks,
    Greg

    http://wordpress.org/extend/plugins/display-posts-shortcode/

  2. slobizman
    Member
    Posted 11 months ago #

    I just had the same need and came up with this:

    Add this filter to your functions.php:

    //----------------------------------------------------------
    // Display Posts Shortcode plugin: add H2 to title
    //----------------------------------------------------------
    add_filter( 'display_posts_shortcode_output', 'format_dps_title', 10, 7 );
    function format_dps_title( $output, $atts, $image, $title, $date, $excerpt, $inner_wrapper ) {
    
    	// Make Title and H2
    	$title = ' <h2>'. $title .'</h2>';
    
    	// Now let's rebuild the output.
    	$output = '<' . $inner_wrapper . ' class="listing-item">' . $image . $title . $date . $excerpt . '</' . $inner_wrapper . '>';
    
    	// Finally we'll return the modified output
    	return $output;
    }

    Then, if you have an excerpt following that, you'll see a dash at the beginning of it. To remove the dash, add this to your CSS:

    .display-posts-listing .excerpt-dash {
            display:none;
    }
  3. gregcrowe
    Member
    Posted 11 months ago #

    Huh. I tried adding that to my child theme's functions.php, and sure enough it did put the title on a separate line. Unfortunately, it messed up the thumbnail graphic and it now displays above the title. But, since I didn't really need the title centered I just changed
    $title = ' <h2>'. $title .'</h2>';
    to
    $title = $title .'<br />';
    Now the thumbnail does what you'd expect.

    Thank you so much for getting me started on this!

  4. Elaine Griffin
    Member
    Posted 4 months ago #

    Hey guys,
    Thanks for this great info - it's helped a lot!
    My problem is I can't get my image and my title/excerpt to line up - my content is pushed down a bit, and I want it aligned with the top of the image. Any thoughts?
    Thanks!
    Elaine
    http://thelitkitchen.com/recipes/

  5. pamkaur14
    Member
    Posted 2 months ago #

    Bloody fantastic. Worked for me. I've been searching high and low for this solution.

    Thanks a million!

    Elaine - you could try the margin settings for the specific areas in your CSS file. That's what I used to adjust the margins around my image.

    Cheers.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.