Jump to content
Sign in to follow this  
jankowalski

template control

Recommended Posts

jankowalski

As @kastelic suggested in one of his posts, i am using this code to display custom post type on my homepage

	add_filter( 'pre_get_posts', 'my_get_posts' );
	
	function my_get_posts( $query ) {
	
	if ( is_page( 'not-here' ) )
	     return $query;
	
	if ( $query->is_home || is_feed && !isset($query->query_vars['post_type']))
	$query->set( 'post_type', array( 'post', 'book', 'games'  ) );
	
	return $query;
	}

Can i assign a template for this loop? At the moment template depends on the first post on the list, if it is book => book template, if game post is first on the list thangames template is loaded. how to set default template for query?

Share this post


Link to post
Share on other sites
Danny
Hi Jan, Could you not create a new template to be used only for your custom post types and then create the above code you added into a custom section and drag and drop this custom section on the newly created template for CPT ?

Please search our forums, before posting!

Share this post


Link to post
Share on other sites
jankowalski
I have template for each custom post, i guess it was created automaticly while creating custom post type. what do you mean by [quote]Could you not create a new template to be used only for your custom post types[/quote]Sorry but i didn t get it.

Share this post


Link to post
Share on other sites
jankowalski
Ok, i have created new section with diferent loop for each custom post type and assigned to diferent template. it works now. still need to figure out how to add more custom post types to this loop: [code]class PageLinesPostLoopOne extends PageLinesSection { function section_template() { query_posts( array( 'post_type' => 'video' 'paged' => get_query_var('paged')) ); //Included in theme root for easy editing. $theposts = new PageLinesPosts(); $theposts->load_loop(); } }[/code] i tried change the line query_posts( array( 'post_type' => 'video', 'paged' => get_query_var('paged')) ); to query_posts( array( 'post_type' => 'video', 'books', 'paged' => get_query_var('paged')) ); but books are not showing up, can you help?

Share this post


Link to post
Share on other sites
catrina
Where is books not showing up? As a post type in the post editor? Try taking the comma out between the video and paged post types.

Please read the docs before posting. Please do not private message me unless I ask you to.

Designer | Catrina Dulay

Founder | Catrina and Mouse

Share this post


Link to post
Share on other sites
jankowalski
no it is not showing in the post loop on the client side. taking the coma out cause [code]Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' [/code] just somebody please tell me how to construct array so i can add more custom post types to thi line. also, pagination is broken... thanks

Share this post


Link to post
Share on other sites
Simon
You need to use an array. [code] query_posts( array( 'post_type' => array( 'video', 'books' ), 'paged' => get_query_var( 'paged' ) ) ); [/code]

Share this post


Link to post
Share on other sites
jankowalski
great, it works, however pagination was still broken, so the final version would be: [code]query_posts( array( 'post_type' => array( 'video', 'books' ), 'paged' => get_query_var( 'page' ) ) );[/code] thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×