Community Forums › Forums › Archived Forums › General Discussion › Setting up a blogroll with custom post types – sort of right, but…
- This topic has 11 replies, 2 voices, and was last updated 8 years, 8 months ago by
Brad Dalton.
-
AuthorPosts
-
July 12, 2016 at 5:35 pm #189348
David Borrink
ParticipantI have set up a custom post type of "projects" on my site, and I want it's archive page to be the same look as my regular blog roll. I'm using the Genesis Grid Loop, so I get a two-column display of posts on my blog. I created an archive template called "page_project.php". I've set up the archive page to be called "Portfolio", have an introduction paragraph, then show the loop of posts.
I found a set of codes (source link here) to create a template for it. It is supposed to allow a page's title and description to show up, then the loop begins to call up the posts of the new post type.
Here is the code after I modified it to my post type...
<?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();
The result? I get the page title, but the page description doesn't show. Then the loop begins, but it's not two column like my blog page. I get the featured image, the meta info, then no post title, but then I get the text with limited characters (correct), then the read more button. The overall result is sort of correct. It appears that I'm getting some of the results the same as the main blog display, but there are missing items. Not sure why it's not the same.
I checked my Genesis Grid Loop settings and saw that I needed to tick the "project archives" under grid enabling. But that didn't change anything. The fact that that choice was there must mean I've got my custom post type set up properly (using Meta Box and MP Custom Post Type plugins, if that's informative for you to know).
Here's my link to my Portfolio page, and my link to my http://davidandsallie.com/blog/ page for reference.
This is my first attempt at a template using Genesis. I've been a TwentyTwelve template creator for years, so the "Genesis way" is new to me. As I understand it, all I'm doing here is changing the query. And the Genesis process is supposed to switch out the content, and I assume the Grid Loop should be displaying my content the same way. I would think I should get an identical display as my main blog page.
My concern is that the source for this code is four years old. I did have to correct some characters for the < and > from the GitHub paste-up. Strangely, the first couple of pages of search results I got had posts that were 3 to 4 years old. That seems "ancient". Very surprised that I could not find any 2015 or 2016 posts in the first couple pages.
Could I ask for a couple tips from someone? I know I'm heading in the right direction. My results are part-way there.
http://davidandsallie.com/portfolio/July 12, 2016 at 6:58 pm #189351Brad Dalton
ParticipantJuly 12, 2016 at 7:34 pm #189354David Borrink
ParticipantIn a word... Yes.
I'm not understanding if my CPT plug-ins don't talk with the Genesis Grid Loop plug-in, or what.
July 12, 2016 at 7:48 pm #189357Brad Dalton
ParticipantHow many CPT's do you have?
There's at least 3 ways to display CPT's or posts in columns.
You can use CSS or PHP code which provides at least 2 different methods.
July 12, 2016 at 8:17 pm #189359David Borrink
ParticipantI have one CPT. It's called "project". My theme comes with a nice style for the columns in the main blog. The Genesis Grid Loop plug-in does a nice job. I just want the CPT posts to match it. Figuring I had to check "project archives" in the Grid Enabling section of the dashboard would be enough.
July 12, 2016 at 8:21 pm #189361Brad Dalton
ParticipantI think you can use the Genesis grid loop plugin for your CPT archive page as well however its not the best solution in my opinion.
I would use the Genesis Column Classes function you linked to with a conditional tag for your CPT archive.
if ( is_post_type_archive('project'))
July 12, 2016 at 8:35 pm #189362David Borrink
ParticipantHow would that function be used? Do I put that in my template (see first post for the complete template)? Where and how would I use that? I don't recall having a Genesis Column Classes function in my code.
July 12, 2016 at 9:07 pm #189365Brad Dalton
ParticipantYou can add it directly to your archive-project.php file without the conditional tag or in your functions file with the conditional tag.
July 13, 2016 at 5:53 am #189392David Borrink
ParticipantFirst, you mention "archive-project.php", is this a new file I create? My template file is "page-project.php". Do I use "archive.php" from the lib/structure folder, copying it into my child theme? Or did you mean the "page-project.php" I have? (My rookie-ness with Genesis is clearly showing here.)
Or if I'm to put it in my functions file, are you saying I just do this:
<?php if ( is_post_type_archive('project')); // 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 ); } endif;
July 13, 2016 at 12:37 pm #189409Brad Dalton
ParticipantJuly 13, 2016 at 8:24 pm #189433David Borrink
ParticipantOkay, I just gave myself an education.
Thanks to your using "archive-project.php" I was able to re-read something I found and was not aware that WP and Genesis had built-in template support via archive-[post-type].php templates. I found Carrie Dils' post on registering a custom post type and she explained the newer system.
I removed my MB Custom Post type plug-in, wrote up a function to register the "project" post type, it picked up on my sample projects posts that were written with the plug-in, and gave me all the support I needed to set up the page simply by using the slug.
Fascinating. And because it used the template hierarchy which I didn't understand until tonight, it fell back to the index.php template to make the display I needed to match my blog page. Perfect.
I'm less of a Genesis rookie tonight. Problem solved.
July 13, 2016 at 9:06 pm #189436Brad Dalton
ParticipantYou've learn't a lot from that!
Now you can use CSS or PHP code to display your CPT entries in columns.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.