Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Benjamin Fitzgerald
Benjamin Fitzgerald
7,988 Points

Is there a way of utilizing get_template_part in wordpress to load different layouts of posts using ajax? i.e grid/list

I'm trying to get custom posts to display in the optional view of grid/list (template-1 / template-2) however, the catch is that one of the views, (template-1) runs a shortcode to a contact form which means I need to alter the html including the classes for columns i'm using in bootstrap.

Kevin McAloon
Kevin McAloon
15,528 Points

If anyone is looking for an answer to this, I found a solution over at https://wordpress.org/support/topic/using-get_template_part-with-ajax?replies=2#post-6386489. Although it is working, I'm not sure if my solution is definitely the most efficient. The most important parts are utilizing WP's native ajax functionality and hooking into it. Here are some articles:

http://codex.wordpress.org/AJAX_in_Plugins http://code.tutsplus.com/tutorials/a-primer-on-ajax-in-the-wordpress-frontend-understanding-the-process--wp-27052

1 Answer

Justin Estrada
Justin Estrada
34,995 Points

Hello I actually have this going on my Photography website. You can load the photos in a gallery view or a list view by changing the URL Query: http://jarphotos.me/gallery/?view=grid http://jarphotos.me/gallery/?view=list

I can show you the code that did it.