Beans icon indicating copy to clipboard operation
Beans copied to clipboard

Add Filters loop template part

Open ehababdo opened this issue 8 years ago • 1 comments

For Example - filter is set

function beans_loop_template( $id = false ) {
	// Set default loop id.
	if ( ! $id ) {
		$id = 'main';
	}
	// Only run new query if a filter is set.
	if ( $_has_filter = beans_has_filters( "beans_loop_query_args[_{$id}]" ) ) {

		global $wp_query;

		/**
		 * Filter the beans loop query. This can be used for custom queries.
		 *
		 * @since 1.0.0
		 */
		$args = beans_apply_filters( "beans_loop_query_args[_{$id}]", false );
		$wp_query = new WP_Query( $args );

	}
	//  beans template filter is set.
	$templates = beans_apply_filters( "beans_template", false );
	$templates = ($templates) ? $templates : BEANS_STRUCTURE_PATH . 'loop.php';
	$file = basename($templates);
	if ( '' == locate_template( $file, true, false ) ) {
		require( $templates );
	}
	// Only reset the query if a filter is set.
	if ( $_has_filter ) {
		wp_reset_query();
	}
}

add_filter

	beans_add_filter('beans_template', 'beans_post_template');
	function beans_post_template() {
		if (is_singular('post')) {
			$file = BEANS_STRUCTURE_PATH . 'post.php';
			return $file;
		} 
	}

ehababdo avatar Nov 29 '17 13:11 ehababdo

@ehababdo I owe you a big apology for such a huge delay in getting back to you on your filter request. I'm very sorry.

Let's talk about your filter request. You'd like the ability to filter the loop template in your child theme.

Tell me more.

A few questions I have are:

  • Do you have different loop structure files for different templates and purposes?
  • Could you use loop.php and then switch what you need?

hellofromtonya avatar Jun 21 '18 03:06 hellofromtonya