Jump to content
Sign in to follow this  
cdoolittle

Custom Post Type, Custom Query

Recommended Posts

cdoolittle

Hi. I should be able to figure this out but I can't. I'm converting from a standard wp installation with custom post types. For each letter of the alphabet there is a custom post of type 'definition' that contains a body of text. (Just for practical editing reasons, this is the best way of tracking thousands of definitions.) The use case is: Default page loads. It includes the main menu in the page header. User selects "glossary" from the menu. Menu link calls a page using the glossary template. Glossary template loads all posts of type 'definition'. User sees a page with zillions of definitions organized alphabetically. In the existing site, I have a custom post type. It currently loads a template that selects all of the custom posts of that type in ascending order, then iterates through them and displays all of them. Currently I simply copy the default blog template and change the query to: query_posts("post_type=definitions&orderby=title&order=ASC&posts_per_page=100"); and then run the loop. And I get what I want. The user can search within his browser for a definition. Or I can pass the page a term as an anchor and it will show the user the term. Now, there are also a number of filters at play in there for tagging and all sorts of other things, but that part is easy. What I can't figure out is how to make a page that calls a custom query and presents it. I should be able to. But I can't figure it out. Thanks

Share this post


Link to post
Share on other sites
cdoolittle

Do I hack template.postloop.php by testing to see if the user is requesting a specific page? That seems like a horrible way to to it.... must be something else I can do.

Share this post


Link to post
Share on other sites
cdoolittle

Is there a way to assign a custom override section to a specific page? This has to be possible somehow...

Share this post


Link to post
Share on other sites
cdoolittle

OK. So I have found a thread on creating a template. So in platformbase, I've created page.glossary.php. It contains: /*Template Name: glossary*/ setup_pagelines_template(); I've also edited functions.php, registering the new template. And the template now shows up in the Template Setup dropdown. Now, how do I actually make it call the right kind of loop? Do I copy it from some existing bit of code? (I bet.. but where?)..

Share this post


Link to post
Share on other sites
cdoolittle

Soooo... No.. I can't hack postloop. That's lame. That would invalidate the entire purpose of using the platform base so that I could easily keep the software updated.... Do I create a new section? And copy one of the other sections over? Do I create a new section, and copy postloop into it somehow?

Share this post


Link to post
Share on other sites
kastelic

You could create a new section, that might be the easiest. You could also use a hook in functions.php and a conditional tag to choose which page it goes on. For a new loop you should use WP_Query rather that query_posts which is for modifying the main loop. A simple example: <?php //The Query $playingargs = array( 'meta_key' => 'featured', 'meta_value' => 'featured', 'post_type' => 'shows', 'posts_per_page' => 10 ); //The Loop $playing_query = new WP_Query( $playingargs ); while ( $playing_query->have_posts() ) : $playing_query->the_post(); ?> <h2><?php the_title(); ?></h2> <?php endwhile; wp_reset_postdata(); ?> After you put this in a section, drag that section to your new page template and make a page with that template. To go the hook route, you can use a hook like pagelines_before_maincontent or pagelines_before_theloop to make this loop happen at the top of your page. For example, in functions.php: add_action('pagelines_before_theloop','customFunction'); function customFunction(){ if (is_page(345)){ //put your custom loop here. It will only appear on page with id 345. } }

Share this post


Link to post
Share on other sites
cdoolittle

Thanks Jimmy, I think I have to use query_posts because I'm definitely replacing the main loop, right? And are there some example sections that I can refer to for specifically this kind of purpose? I can't really figure out which section to work from... Thanks

Share this post


Link to post
Share on other sites
cdoolittle

Or could I just do something like this, and redefine the query before it calls the template, and just let it call the normal default pagelines loop? add_action('pagelines_before_theloop','customFunction'); function customFunction(){ if (is_page(345)){ query_posts("post_type=definitions&orderby=title&order=ASC&posts_per_page=100"); } }

Share this post


Link to post
Share on other sites
kastelic

Well query_posts is for modifying the main loop. The example i gave you is for a completely new loop. You can have the new loop come before or after the main loop, you can even have multiple new loops on the same page. If you have a new loop come before the main loop on a page, and then make a page and just leave the content area blank, you will just see the output of the custom loop, since there is nothing to output in the main loop. But yes, your last post example using query_posts is an option too, maybe even the better option. I'm not sure but 'pagelines_inside_top_theloop' might be the hook you want to use, but I could be wrong.

Share this post


Link to post
Share on other sites
cdoolittle

Thanks Jimmy, at least I have somewhere to start know. :)

Share this post


Link to post
Share on other sites
cdoolittle

OK, so this works to override the main query. I've also figured out how to do it the other way, but it's messy. add_action('pagelines_before_theloop','customFunction'); function customFunction(){ if (is_page('my-page-slug')){ query_posts("post_type=definitions&orderby=title&order=ASC&posts_per_page=100"); } } The problem is that I cannot seem to get the layout that I want.... The way that the magazine layout logic is written into the system is too assumptive. I can't turn it OFF on a custom page. I don't even know how to ask the question. I either get the magazine layout EVERYWHERE or NOWHERE.

Share this post


Link to post
Share on other sites
cdoolittle

Nope. DOesn't work. I need more control over the loop than I can get out of the default template loop. How do I create my own loop? Do I just edit .... No.. I can't put it in page.glossary.php, because the default loop still gets executed ... what is that page supposed to do anyway? What is the point of having a page if you can't control the loop? Frustrating....

Share this post


Link to post
Share on other sites
cdoolittle

OK. Figured it out. Documentation or tutorial would be very helpful since creating a custom page requires a series of symbolic links that are not intuitive in the code. But I got it.

Share this post


Link to post
Share on other sites
jankowalski
where can i find documentation? i d like to learn how to create custom sections in pagelines framework

Share this post


Link to post
Share on other sites
Rob
A new update is forthcoming with added documentation, some of which covers custom sections.

Former PageLines Moderator, Food Expert and Raconteur

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  

×