Have you ever wanted an archive to display posts, but not wanted those posts to link through to the individual post pages? Well, you’re in luck because in this tutorial I’ll show you how to create a custom Genesis archive page template to display the thumbnail and post title, but without links to the individual post content.
Why a Genesis Custom Post Type Archive?
For this project, I wanted to display a list of employees with their name, photo, and some other details. While I could have easily created a static page with this info, I wanted content that a client could easily update without the need to manually add formatting.
To do that, I created a custom post type and a corresponding custom template to display the content.
You can use the steps below to help you customize an archive template that doesn’t link through to individual posts.
How to Remove the Link from the Thumbnail & Post Title on a Genesis Custom Archive Page Template
Step 1: Create the Custom Post Type
In this case, I named my custom post type “Team” since I wanted to display a list of employees, or team members.
You can manually create a custom post type (CPT) or use a plugin to help. While I typically go the former route (via a custom plugin to for non theme-specific code), I opted to use the WP-Types plugin for simpler maintenance.
While I was at it, I also used WP-Types to create a custom meta box to go with the “Team” post type so that I could store the team member’s job title and bio as a separate pieces of meta-data.
Step 2: Create a Custom Post Type Archive Template
According to the WordPress template hierarchy, the standard for naming a CPT archive is archive-$posttype.php, where $posttype equals the CPT’s slug.
Mine was team, so I named it archive-team.php.
Drop this in your child theme’s root directory.
Step 3: Drop in the code
For starters, I added a bit of code to functions.php that gets rid of the post meta (i.e. author, publish date, tags, etc.) for the “team” post type. (Note that you need to have Genesis 2.2 to use this code)
<?php | |
add_action( 'init', 'team_remove_entry_meta', 12 ); | |
/** | |
* Remove entry meta for the 'team' post type | |
* | |
* @link https://gist.github.com/cdils/61b8a0720fe828acb467/ | |
*/ | |
function team_remove_entry_meta() { | |
remove_post_type_support( 'team', 'genesis-entry-meta-before-content' ); | |
remove_post_type_support( 'team', 'genesis-entry-meta-after-content' ); | |
} |
Next, I added my custom code to archive-team.php.
<? | |
/** | |
* Team Archive template | |
*/ | |
// Remove default post title (with link) | |
remove_action( 'genesis_entry_header','genesis_do_post_title' ); | |
add_action( 'genesis_entry_header','cd_archive_title' ); | |
/** | |
* Display the post title (without link). | |
* | |
*/ | |
function cd_archive_title() { | |
echo '<h2 class="title">' . get_the_title() . '</h2> '; | |
} | |
add_action( 'genesis_entry_content', 'cd_archive_featured_image', 8 ); | |
/** | |
* Display featured image (without a link). | |
* | |
* Check to see if the post has a thumbnail and, if so, display the thumbnail. | |
* | |
*/ | |
function cd_archive_featured_image() { | |
if ( ! has_post_thumbnail() ) { | |
return; | |
} | |
$attr = array ( | |
'class' => 'alignleft', | |
'context' => 'archive', | |
'alt' => get_the_title(), | |
); | |
echo '<span class="featured-image">'; | |
the_post_thumbnail( 'thumbnail', $attr ); | |
echo '</span>'; | |
} | |
add_action ( 'genesis_entry_content', 'cd_team_member_details', 9 ); | |
/** | |
* Display team member title and bio. | |
* | |
* Uses WP Types & Views to return two custom fields. | |
* https://wp-types.com/documentation/user-guides/displaying-wordpress-custom-fields/ | |
* | |
*/ | |
function cd_team_member_details() { | |
echo '<strong>' . types_render_field( 'team-member-title', array("output"=>"html") ) . '</strong>'; | |
echo '<p>' . types_render_field( 'bio', array("output"=>"html") ) . '</p>'; | |
} | |
genesis(); |
You could change the CSS classes or other markup as needed, but this should get you headed in the right direction.
Step 4: Adjust Genesis Theme Settings for Content Archives
Under your Genesis theme settings, make sure you have don’t have the “Include the Featured Image” option checked.
If you want to leave this checked (for use on other archive pages, say), then add this to your CPT archive:
remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
The finished CPT archive
What I end up with is an archive page listing every team member, along with their photo, title, and bio. The post title (the team member’s name) is not linked and neither is the featured image (the team member’s photo).
Tada!
Great post Carrie. To remove the title link, it’s probably better to just do `add_filter( ‘genesis_link_post_title’, ‘__return_false’ );`
Also just learned you can remove the image link simply with “`// Remove featured image link
add_filter( ‘genesis_markup_entry-image-link_open’, ‘__return_empty_string’ );
add_filter( ‘genesis_markup_entry-image-link_close’, ‘__return_empty_string’ );“`
Well that’s certainly more consise!!!
Thank you Mike for sharing that snippet!
No prob Jill 😉
Great article and loads of good information Carrie Dils! I’m using a Genesis Child them (News Pro) and wanted to know if there is anyway to completely hide the posts from the category archive?
This is fantastic, I just struggled to make my own page like this, I wish I would have found this sooner! Your way is much easier. Typically if you don’t link to the individual pages, what happens to them do they become ‘zombie’ pages?
If you don’t really want visitors ending up on those pages or in the sitemap are you noindexing them then? In my case I really don’t need the actual single pages that each post makes. When I made my page I was struggling with just what to do with those individual pages – seems like they would eventually just add up and dilute your site’s SEO with pages that don’t provide a lot of good relevant content to the site?? I did almost exactly what you did here but was wondering your thoughts on those individual pages?? THANK YOU you rock!
Hey Amy, do you mind sharing your use case for wanting to have individual posts but no links to them (vs just having a static page and manually creating/listing content)? I’m just curious. 🙂 You could certainly leave out the link part and no-index the individual posts (or the entire post type if it’s a custom post type) if you wanted.
Thank you Carrie, i’m sorry if I was confusing so I JUST made a page which is made from a custom post type of ‘review’ & ACF, but don’t need them linking to single pages-don’t even need the single page (just like this tutorial except you used the archive page and I pulled them into a regular page). So it’s just a page that ends up pulling in the formatted ‘review’ list.
I did make my page without links (I did my page before I found this post of course ) I was just concerned about what happens to those single pages, since we are not using them – to me the page that lists them all in my situation is the most important. I did no-index the individual posts.
So (sorry ) my original question I was trying to ask is: what is the typical thing one would do with all of these single pages that get generated each time you say add another ‘review’ ? Just like in your case with this tutorial what happens to each single post that gets made when a new ’employee’ is added? I really hope that makes sense lol! Appreciate your time !!!
Yep – that makes sense! In my example, I don’t mind the individual posts being indexed as they would “make sense” as a standalone page if a visitor hit that page. For your case, look at the
public
parameter for theregister_post_type()
function. If the CPT is being registered by a plugin you don’t control, you can use a filter to modify the CPT after it’s been created.Thank you for being so helpful! Ok great I will check that out!
I did not use a plugin, so I can control / add parameters.
Ok so is this CPT paramater what you are talking about?
‘exclude_from_search’
(bool) Whether to exclude posts with this post type from front end search results. Default is the opposite value of $public.
* If I add change that to true won’t that affect the whole post type?
OR since mine are getting pulled into a page it shouldn’t affect search results for that particular page… do I have that correct?