Community Forums › Forums › Archived Forums › General Discussion › Set up a blogroll with custom post types
Tagged: archive, Custom Post Type, page
- This topic has 1 reply, 2 voices, and was last updated 8 years, 7 months ago by
Victor Font.
-
AuthorPosts
-
July 17, 2016 at 7:28 am #189327
David Borrink
ParticipantI need a little help. I've set up a custom post type of "project" on my site, and I want to duplicate the blog roll from my site in order to just show this custom post type as the listings. This is my first attempt at creating a page template using Genesis, after doing this the normal WP way for years.
I set up a page template called "page_product.php" and below is the code for that template. Source of that code is here. It's a four year old post, so I question if it's up-to-date now. Actually, my first couple pages of Bing search results have a lot of sites with info that is three or four years old. So I'm now questioning if I'm getting good info at all.
I created two test "project" posts with featured images and text. I thought I would get this result: the page title, the page content, then I'd get a blog roll of the "project" posts below it. But I get an unformatted title for the page, no content, then immediately the two posts with only the featured image, meta, and short content, and the read more button.
<?php /** * Template Name: Project Archives * Description: Used as a page template to show page contents, followed by a loop through a CPT archive */ // Do the Custom Loop remove_action('genesis_loop', 'genesis_do_loop'); add_action( 'genesis_loop', 'ds_custom_loop' ); function ds_custom_loop() { echo '<h1 class="entry-title">' . get_the_title() . '</h1>'; the_content(); //WP Query Start $per_page = 12; $project_args = array( 'post_type' => 'project', 'posts_per_page' => $per_page, 'paged' => get_query_var( 'paged' ) ); $projects = genesis_custom_loop( $project_args ); } genesis();
I have the Genesis Grid Loop plug-in installed, and I've set it for the main blog roll to have two columns of posts. In the dashboard I went to the Grid Loop settings and made sure that "project archives" was ticked so that the Grid Loop would apply to that. But I'm getting single column results.
I assumed this was going to be a function that would would just create a duplicate two column grid on the "Portfolio" page that matched the look of the "Blog" page. See those links for reference.
So I'm asking for a few minutes of someone's time to help me know if I'm in the right direction or if I'm way off here. I want to learn this, but there must be something I'm not getting here. Thanks.
http://davidandsallie.com/portfolio/July 17, 2016 at 3:33 pm #189714Victor Font
ModeratorThe WordPress query executes before the Genesis Loop. The loop simply displays the results of the query. If you want to display a specific post_type, you have to use WordPress filters. This should work if you apply it to your page_template. If not, you have to add it to functions.php and place a conditional wrapper around the query->set so it only executes for the project page template.
function vmf_query_filter($query) { $query->set( 'post_type', array('project') ); return $query; }; add_filter('pre_get_posts', 'vmf_query_filter');
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet? -
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.