• Resolved trevolutionary

    (@jkdsouljah)


    Hi Bill

    I’ve tried following the instructions you laid out here:

    https://displayposts.com/2019/01/04/use-template-parts-to-match-your-themes-styling/

    But I can’t get it to work. These are the steps I’ve taken so far:

    1. I created a partials subdirectory in my theme folder.

    2. I created a new partial and added it to the partials subdirectory (for following your example in your docs, this was dps-small.php)

    3. I added the following snippet to Code Snippets:

    <?php
    
    /**
     * Template Parts with Display Posts Shortcode
     * @author Bill Erickson
     * @see https://www.billerickson.net/template-parts-with-display-posts-shortcode
     *
     * @param string $output, current output of post
     * @param array $original_atts, original attributes passed to shortcode
     * @return string $output
     */
    function be_dps_template_part( $output, $original_atts ) {
    
    	// Return early if our "layout" attribute is not specified
    	if( empty( $original_atts['layout'] ) )
    		return $output;
    	ob_start();
    	get_template_part( 'partials/dps', $original_atts['layout'] );
    	$new_output = ob_get_clean();
    	if( !empty( $new_output ) )
    		$output = $new_output;
    	return $output;
    }
    add_action( 'display_posts_shortcode_output', 'be_dps_template_part', 10, 2 );

    4. I updated my shortcode to [display-posts layout="small"]

    And nothing happens. I’m missing something…

    Appreciate your attention.

Viewing 1 replies (of 1 total)
  • Thread Starter trevolutionary

    (@jkdsouljah)

    As always, if I just spend a bit more time with it before jumping the gun to ask for advice, I would have figured it out, like I just did. Everything was correct, except in using your dps-small.php partial to try and replicate your instructions, it was making a call to something that didn’t exist in my site. Replaced the contents of dps-small.php with my own code suitable for my site, and voila.

    Many thanks
    Trevor

Viewing 1 replies (of 1 total)
  • The topic ‘Template Parts’ is closed to new replies.