Join my tribe!

Sign up to learn how to keep your skills up to date on the tech that matters most and confidently sell your skills to a growing customer base.
I will never spam you. You can unsubscribe at any time.

Reader Interactions

Comments

  1. Great tut Carrie,

    I was in need of creating a dedicated page for testimonials and this worked great.

    Although… after following the link to Bill Erickson’s website for the custom meta boxes. I then followed a link from his website to Justin Tadlock’s tutorials where he covered “must use” plugins. In total I spent 6 hours building a new framework for all new Genesis projects going forward. Now the ability to create custom post types with customized admin screens is much easier!

    Thanks again for the tutorial and for making reference to other people’s code. It has made my coding more efficient.

    -rick

    • Rick, I’m intrigued! Is it a new base child theme of sorts or more some custom functions to re-use? Would love to read a post with your own findings. I LOVE the custom metabox functionality…slick.

      • Hey Carrie,

        It’s code base that can be used with any Genesis child theme. In a nutshell… WordPress functions/customizations go into the MU plugin, Genesis functions/customizations go into custom_functions.php and theme specific go into the functions.php file. Keeping everything separated makes it easier when building the next website thanks to code re-usability and makes changing themes on an existing site easier when some customizations that aren’t theme dependent but are Genesis dependent need to survive the changeover.

        -rd

  2. I’ve been using this pluign and I absolutely love it. The one change I think could be useful, would have a “custom code” section, where I could easily add code above or beneath. I went around this by adding an action on the page and hooking into Genesis instead.

  3. Hi Carrie, very nice work. The only trouble I have is I upgraded to Genesis 1.9 and now this doesn’t work. Can you help me? Thanks a lot

    • Hi Thierry,
      I’m running it on Genesis 1.9 with no problem, so there might be a conflict somewhere else. Can you tell me more about how/where you’re using the code and what specific problem you’re having?

      Cheers,
      Carrie

      • Hi Carrie,

        In my child theme I created an file called page_listing.php and copied the codes from above. I also use the AgentPress plugin. The only modification is the following:

        echo ‘‘ . genesis_get_custom_field( ‘_listing_price’ ) . ‘‘; //retrieve custom field
        echo ” . genesis_get_custom_field( ‘_listing_sqft’ ); //retrieve custom field

        But nothing from the page_listing.php is displayed but the default loop. Can you think of anything wrong I’m doing here?

        Thanks

  4. Just a little thank you for sharing. I looked all over for instructions on this and finally found yours, which were perfect and easy to follow. Used it to create a Brewers List for a beer distributor website. Thanks Carrie!

    –Sara

  5. Hi Carrie,

    Thanks for this tutorial. One odd thing I ran into was that get_the_content() was not returning the content of the page for me for some reason. I changed

    echo ” . get_the_content() ;

    to

    echo ”;
    $page_object = get_page( get_the_id() );
    echo $page_object->post_content;

    and it outputs the content as expected. I noticed on your testimonials page that you did not include any text, just a title, before the testimonials. Have you tested adding content to your page?

    Thanks again for the great tut!

    • I did at one point and then got rid of it. I think the code here could definitely be improved – just hadn’t had a chance to update it yet. Glad you got it to work!

    • Hi Matthew & Carrie-

      I was having the same problem, and have been scouring the web for a solution to the Content not appearing on the archive page..

      Matthew – I used the coding you pasted above, and it works great β€” however, the initial ” keeps showing up on the page, and I am not sure how to eliminate it.. Or if you are using that in place of other coding, etc.

      I had:

      function custom_do_loop() {

      // Intro Text (from page content)
      echo ”;
      echo ”. get_the_title() .”;
      echo ” . get_the_content() ;

      and switched to:

      // Intro Text (from page content)
      echo ”;
      echo ”. get_the_title() .”;
      echo ”;
      $page_object = get_page( get_the_id() );
      echo $page_object->post_content;

      but the quote keeps coming in at the top.

      Here’s one of the custom post type pages: http://74.53.25.211/~explore/beauty-fitness/

      If someone would provide some insight into what I am doing wrong, I’d greatly appreciate it!
      Thank you for your help!!

      Sarah

      • just going to ping you both… i’ve tried the coding so many different ways, and read many online articles and forums to no avail.. would really appreciate some help πŸ™‚ thank you!

        • Hi Sarah,

          I don’t get notified about new comments on here so I did not see your post until today. Just happened to be coming back to this great tut once again!

          Anyway I suspect your problem is a cut & paste related issue. The ” is 2 single quotes together. Try typing it in that way and hopefully you will be good to go!

          I have subscribed to future responses so if you have any problems, post back.

          Thanks!

  6. Hi Carrie, Since a created my page_listing.php (see post from April 2 above) which works great. When I use the Search of AgentPress it returns all posts and the layout is different. Which template the Search is using and why do you thing that the query is not working? Thanks

    • Hoops did not fix everything. The search result is not using my custom loop layout. Which template the Search use to return the result? How can I tell the search to use a different template? Thanks

  7. I’m a slight bit confused. Is this what I would need to create post templates? Such as, I have a certain type of posts formatted a certain way, but different from the usual post style?

    I want to be able to choose a certain blog post template (that would include sorta like a signature or bit of text that would be at the end of every post of that type) from a drop down menu within the “add new post” editor.

    Or am I looking for something else?

    • Nah, I think you’re looking to create a custom page template and then set a particular post to use that template. Depending on how crazy you’re going with formatting, you may be able to just use a custom post class.

  8. Dear wonderful Carrie

    how can i use this for custom post type taxonomies?

    i have a CPT of ‘product’

    and custom taxonomy of ‘product-category’

    and a custom template called ‘taxonomy-product-category.php’ where i’ll drop in the code.

    can’t seem to get my head around displaying taxonomies πŸ™

    i need to have the custom loop as you have done, that way i can tweak as needed.

    i know it is something simple that needs to be changed in the ‘$args = array’

    i’m using genesis 2.0 beta

    really hope you can help, it would be greatly appreciated.

  9. Hi great tut,
    This has been such a help, however I’d like to link the thumbnails and post titles to the original posts. I’m sure this should be simple but I’m new to php.
    Appreciate any help.
    Cheers,

  10. Hi Carrie! This post was exactly what I was looking for. Couple of quick questions… What template would you create for a category in a custom post type? For example, if I have a custom post type of “Products” with a category named “eBooks” what would the archive file name be? Would it be archive-products-ebooks.php or would I need to setup a taxonomy template file for that like taxonomy-products-ebooks.php? Thanks for your help!

    • Hey Daniel,

      If you want an archive of all Products in the eBook taxonomy, you’d want to structure your template name as taxonomy-ebooks.php (assuming ‘ebooks’ is the name of your taxonomy). Not sure what your site organization/structure is, but it might make more sense to have a taxonomy called “type” and then “ebooks” is a term within that taxonomy… In that case your template could be taxonomy-type-ebooks.php.

      On the other hand, if you want an archive of ALL products, regardless of taxonomy, then you’d use archive-products.php.

      When in doubt, I always refer back to the template hierarchy in the codex: http://codex.wordpress.org/Template_Hierarchy

      Carrie

      • Hi Carrie,

        Thanks for taking the time and replying. I’m basically trying to setup an ecommerce section to my site. So I wanted to create a custom post type of “products” (to keep separate from regular posts and give the products a unique page template), categorize those products and have a template for each product category if that makes sense. : ) I haven’t done anything like this with WordPress so I might be making things harder for myself I don’t know.

        It may just take me a lot of messing around with and a lot of caffeine. : )

        Thanks again Carrie!

        • Sounds like you’re on the right page! What you’re technically after is a “taxonomy archive template”. The naming structure (according to the Template Hierarchy) is really the #1 factor to make sure your theme picks up the page where you want it to. After that, you’re just tweaking the loop to get your output as you wish.

          To start, create your taxonomy archive template and just build it out with the standard genesis loop to see what it outputs. πŸ™‚

          Carrie

  11. Hi Carrie,

    Can I still use this tut with Genesis 2.0 if I move to HTML 5 (by adding that HTML 5 switch to the functions.php file)? I am using minimum and it has a Bill Erickson style loop built into it but it only has one type of featured thumbnail in the grid and I wanted to have 2 types (which is similar to the way that Bill does it in his tut). I was going to just dive into it but I thought that you may have played Genesis 2.0’s loop functionality a bit and could tell me whether it has changed much.

    As always, thanks for the great tutorials!

    • Hey Chris,

      Here’s a list of loop changes with HTML5: http://www.briangardner.com/code/genesis-html5-loop-hooks/

      So for this tutorial, you’d need to change:

      /** Remove Post Info */
      remove_action(‘genesis_before_post_content’,’genesis_post_info’);
      remove_action(‘genesis_after_post_content’,’genesis_post_meta’);

      To be:

      /** Remove Post Info */
      remove_action(‘genesis_entry_header’,’genesis_post_info’);
      remove_action(‘genesis_entry_footer’,’genesis_post_meta’);

      I’m on the seat of my pants here, so test this.:)

      Honestly, I’d like to re-write this tutorial as there are better ways to “skin the cat” so to speak. This works, but I think there’s a better way to code it.

      One of these days!

      Cheers,
      Carrie

      • Thanks for the super fast reply Carrie. I guess we’re all figuring out the changes in Genesis 2.0 so I will definitely keep an eye out for your next tutorial. Again, thanks for all of your contributions to the Genesis community.

        — Christopher

  12. I have a problem with the archives of the custom post type.

    Changes to the file archive and the new post-customPost.php are only visible to admin mode while the normal user does not see the new posts and the changes made ​​to the code.

    Could you help me?

      • Thanks a lot for your prompt reply.

        I am not sure if I can move to Genesis 2.0 at this stage as we already advanced by 2years in that code. I have to do a lot of testing and key things I already implemented through other plugins.

        I created post type using following way:
        register_post_type(‘discuss’,
        array(
        ‘labels’ => array(‘name’ => __(‘Discussion Forum’),
        ‘singular_name’ => __(‘Discussion Forum’)),
        ‘public’ => true,
        ‘has_archive’ => true,
        ‘hierarchical’ => true,
        ‘publicly_queryable’ => true,
        ‘capability_type’ => ‘page’,
        ‘show_in_menu’ => true,
        ‘supports’ => array(
        ‘title’,
        ‘editor’,
        ‘author’,
        ‘thumbnail’,
        ‘excerpt’,
        ‘comments’,
        ‘page-attributes’,
        ‘post-formats’,
        ),
        ));

        Then when I visit http://site.com/discuss.. It takes content from archive-discuss.php.

        Now when I access it as admin, it opens perfectly fine but when I access it as guest it shows blank page.

        Any idea what is causing this error?

        thanks in advance.

        • Hmm… Can’t think of any reason why that would happen. Sounds like a permissions issue more than anything related to your CPT. Try disabling all your plugins and see if that fixes the problem. If so, re-enable one at a time until you find the culprit.

          You might try searching the forums at wordpress.org to see if anyone’s had a similar issue.

  13. I am using the Genesis theme template and I am curious where I go to create the .php file? And a bit more of the 1-2-3 prior to actually creating the code. Thanks so much for your help.

    • Hi Scott,
      Thanks for stopping by. This tutorial requires some “prep-requisites”, if you will. The resources mentioned at the end of the post are a good starting point understanding the loop better and how it’s being modified in this case.

      Check out the WP Codex on Template Hierarchy for a starting point on why/where for .php template files.

      http://codex.wordpress.org/Template_Hierarchy

      Cheers,
      Carrie

  14. Hi Carrie, thanks for sharing!

    As others pointed in the comments, for some reason get_the_content() was not returning the content of the page. Maybe because it’s a function that, as the codex says, needs to be executed inside the/a loop.
    Please, could you please edit the tutorial code, in order to fix it?

    If it helps, in my case, this solve the problem:


    // Intro Text (from page content)
    echo '';
    echo ''. get_the_title() .'';
    echo ''
    if ( have_posts() ) : while( have_posts() ) : the_post();
    the_content();
    endwhile;
    endif;

    Cheers!

  15. Thanks a ton for this Carrie, your tuts are great and easy to follow and I’ve found your code examples to be the easiest to digest. I’m used to creating WordPress templates more in front end HTML mode with each wp php snippet in it’s own tag. Typical front ender I know.

    One thing I struggle with when using a more PHP orientated approach is syntax so for example I’m using your template as an example and adding new echo lines in to add additional parts to the loop.

    I can’t for the life of me get the permalink in there with the title. It keeps jumping out of the a tag.

    Here’s the segment I’m having issues with – http://pastebin.com/AEF0c0ez

    Anyone have any ideas?

  16. Why do we need our loop in the code above to specify the post type (since the file we’re using is archive-testimonials, shouldn’t “testimonials” actually be the default value there anyway?)

    Just wondered.

  17. Hi There, thanks for this tutorial, I’ve added the code above and now have the custom post type. I’ve added some posts to it, but when I click the archive page from within the archive setting, I simply get a 404 error. I’m sure Its something simple I’ve done wrong. Any help would be greatly appreciated.

    • Hey Francisco, there’s no change to where to put the code in terms of 2.0. If you’re comfortable editing your theme’s functions.php file, that’s the simplest place. Otherwise, I suggest a plugin like Genesis Extender that allows you to insert custom functions in a little safer way through their interface instead of your functions file (eliminating the chance you could accidentally kill your site with a syntax error or such). πŸ™‚

      • I messed up in more than one way, Carrie – I was intending to make this comment in the other post.
        Thank you very much for your help! I’m getting the hang of this πŸ™‚

  18. Hi

    Great tutorial. I have found it really useful.

    One question. I was wondering how I might introduce a ‘View Older Testimonials’ link after the 12th Post – i.e. to allow the visitor to view testimonials 13, 14, 15 etc

    Thanks
    Pete

  19. Carrie, Thank you for showing us how to use WP_Query with the custom post type page templates. My approach is a little bit different. It doesn’t involve using a page template. I’m using the add_filter(‘the_content’, ‘callback_function’) to modify the content. My function checks for a certain custom post type and then adds content, and returns the modified content. If it’s a regular post or page, it simply returns the unmodified content. Here’s the article I wrote about it.

    http://uly.me/custom-content-in-wordpress/

    • Hey Ulysses,

      Thanks for sharing! You’re right – there are a variety of ways to accomplish a similar outcome. My suggestion for your code snippet would be to throw a conditional in to determine whether you’re dealing with a post type – that way you won’t run unnecessary code on posts/pages.\

      Cheers,
      Carrie

  20. This is great, Carrie. I just created a custom blog page template. The Genesis framework is only bringing in the Post type, and I want it to bring in both ‘post’ and ‘podcast’.

    What should I add to the page_blog.php to bring both types in?

    If you can help- thanks!

    -Dan

  21. Oh man, this just saved me such a headache. I’m new to the Genesis Framework and can’t quite wrap my head around it yet… How do I add a sidebar to the provided code? Just looking to add the default ‘sidebar’

    Thanks! – Daniel

  22. I’m setting up a custom post type template and also pull in ACF fields. This appears to work fine for text fields but has issues with image and oEmbed fields (and probably other field types I haven’t tested yet). Should your example work fine with Genesis+CPT+ACF?

  23. Ack, I’m stumped again. I’m trying to get the comment form to display on the single CPT. I’ve added ‘comments’ to the CPT “supports” array and the comments pane displays on the back-end. If I leave a comment there it does then display the comment on the front-end. I just cannot get the “Leave a reply” form to display on the front-end. I confirmed that the comment form displays fine for normal blog posts.

  24. I removed the manual CPT setup in my functions and installed the Types plugin and it’s displaying now. I thought I had the functions setup correctly, but maybe I was missing something.

  25. Wow. Several hours later, I come across this little bit of wisdom. Might want to move it into the main article under “In case you get a 404 error after implementing this setting…”. πŸ™‚

  26. Not sure what happened, but these are supposed to be replies to the 404 error comment.

    Anyway, I had the same problem and spent hours trying to figure out what I had done wrong. I even read your article as part off my trouble shooting. It wasn’t until a Google search brought me to the comment and then your reply that i found the answer. As you suggested, a simple visit to the permalink settings fixed it right up.

    So, first, thanks! Second, it might be a great tip to move into the main article.

Trackbacks

Leave a Reply