Learn with this tutorial how to display on the archive page only the entries of a CPT to which the subscriber has access with Restrict Content Pro and a little bit of code.
Following the tutorial in which you learned how to show the archive pages in grid format, one of the subscribers asked me if this layout could be applied, but showing only the entries that the Restrict Content Pro subscriber could access to.
In his case, the membership site has several membership levels and depending on which one they have, the subscriber can access or not to certain content. However, the problem is that Restrict Content Pro does not restrict the entries it displays on the archive page by membership level.
That is, even if the subscribers do not have access to “Course X”, this course will be displayed on the course archive page. However, when they click on it, they will get the message that they do not have access.
But it would be better if you could hide the content you don’t have access to and avoid frustration for your students, wouldn’t it?
This would be the final result:
Although these snippets are created for Genesis Sample, you can apply them to any other Genesis child theme after making small changes to the code.
Let’s see how to achieve this
Steps to display only the entries that the subscriber has access to on the archive page of a CPT
1. Restrict access to CPT entries by membership level
First, you must restrict access to Custom Post Type entries depending on the membership level.
To do this, just use the metabox that Restrict Content Pro creates at the end of the entries and select which membership level gives access to that content.
2. Create an archive-cpt.php file
Next, generate a specific template for the Custom Post Type archive page. The file name retains the following structure: archive-cpt.php.
In this case, since it is for the course CPT that is registered as ‘course’, you can call the file archive-course.php and place it in the root of the theme.
To see this and another 1097 code snippets of this website, login or subscribe here.
First you remove the default ticket loop and replace it with a custom one where you add the rcp_user_can_access
conditional to only show the post if the RCP subscriber has access to the content.
From the new custom loop you can modify from the arguments (type of CTP, number of entries…) to which elements of the entry you want to show.
In this case, the arguments are:
- input type > ‘course’ (replace it with the name you have registered the CPT with)
- order > will show oldest first (change to ‘DESC’ if you want to reverse it)
- number of entries > 12
- add pagination
And the elements of the inputs are:
- title
- image
- excerpt
On the other hand, in the second part of the block you generate an .entry-wrapper
class that allows you to apply the necessary styles to create the grid layout.
In addition, this code forces the design to be full width, and eliminates the metadata of the entries, so that the design is cleaner.
Do you already have a suitable size? Then remove this line.
But if you keep it, remember to regenerate all the thumbnails of the images that were already in your WordPress library with the Regenerate Thumbnails plugin.
3. Customize the CSS of the grid
Once you have made the changes in the child theme, you only need to assign the styles to display it in grid format.
To do this insert this snippet at the end of style.css:
To see this and another 1097 code snippets of this website, login or subscribe here.
With this snippet you also adjust the pagination element to look closer to the results.
Now you only need the last detail.
4. Make adjustments to the theme
To give it the final touch go to Genesis > Theme Settings > Content Files or to the same path from the WordPress customizer.
Choose the following features:
- In “Select one of the following options” choose the excerpt of the entry.
- If you opt for “Post content” I recommend limiting the number of characters (100 for example).
- Check the “Show featured image?” checkbox
- For “Featured image size” choose one that fits the design.
- For “Alignment of featured image” choose Centered.
Of course, this is a simple example that can serve as a guideline, but I encourage you to change the values to your liking
Also, if you do it from the WordPress customizer you will be able to see the changes in real time.
There you have it. The archive pages will be displayed in grid format and will only show the entries that the Restrict Content Pro subscriber has access to.
Conclusions
Now you know how to display only the entries that a Restrict Content Pro subscriber has access to on a Custom Post Type archive page. And, what’s more, you can display it in grid format.
Although this code is created for Genesis Sample (3.4), with a few adjustments it will work for any Genesis child theme.
If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.
Benefits of being a subscriber. 🙂