• I’m modifying a plugin (http://code.tutsplus.com/tutorials/create-a-shortcode-to-list-posts-with-multiple-parameters–wp-32199) to list posts using a shortcode and am having trouble merging the theme design into the plugin’s loop.

    This is the the plugin’s loop part:

    // create shortcode with parameters so that the user can define what's queried - default is to list all blog posts
    add_shortcode( 'list-posts', 'rmcc_post_listing_parameters_shortcode' );
    function rmcc_post_listing_parameters_shortcode( $atts ) {
    	ob_start();
    	extract( shortcode_atts( array (
    		'type' => 'post',
    		'order' => 'date',
    		'orderby' => 'title',
    		'posts' => -1,
    		'color' => '',
    		'fabric' => '',
    		'category' => '',
    	), $atts ) );
    	$options = array(
    		'post_type' => $type,
    		'order' => $order,
    		'orderby' => $orderby,
    		'posts_per_page' => $posts,
    		'color' => $color,
    		'fabric' => $fabric,
    		'category_name' => $category,
    	);
    	$query = new WP_Query( $options );
    	if ( $query->have_posts() ) { ?>
    		<ul class="clothes-listing ">
    			<?php while ( $query->have_posts() ) : $query->the_post(); ?>
    			<li id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    				<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    			</li>
    			<?php endwhile;
    			wp_reset_postdata(); ?>
    		</ul>
    	<?php $myvariable = ob_get_clean();
    	return $myvariable;
    	}
    }

    And this is what I have in category.php that determins the post list layout:

    <?php if( have_posts() ) : ?>
    	<?php
    
    		$posts_list = array();
    		$posts_list[] = '<ul class="list posts-list">';
    
    		while( have_posts() )
    		{
    			the_post();
    
    			array_push($posts_list,
    				sprintf(
    					'<li class="item item-%s">
    						<h2 class="title"><a href="%s">%s</a></h2>
    						%s
    						<p class="meta">%s</p>
    						<p class="excerpt">%s</p>
    					</li>',
    
    					get_the_ID(),
    					get_permalink(),
    					get_the_title(),
    					has_post_thumbnail() ? '<p class="featured-image"><a href="'.get_permalink().'">'.get_the_post_thumbnail($post_id, "small-thumbnail").'</a></p>' : '',
    					get_the_date('j. F Y'),
    					get_the_excerpt()
    				)
    			);
    		}
    
    		$posts_list[] =  '</ul>';
    
    		echo implode("\n", $posts_list );
    
    		if(function_exists('wp_paginate'))
    		{
    			wp_paginate();
    		}
    		?>
    		<?php else : ?>
    		<p><?php _e('No posts found.', 'theme'); ?></p>
    		<?php endif; ?>

    As a novice, I cannot seem to succeed in applying the latter to the former, so that the post list would include title, date, excerpt and thumbnail. Managed to get everything else working though (custom post types, taxonomies, filtering with shortcode), but that last part has been a headache for hours…

The topic ‘Help with nested loop layout’ is closed to new replies.