Archived topic
Custom CPT Archive Template – Content Truncating
11 replies · Started by Pete on January 26, 2022
I am attempting to create a custom archive page template for a CPT called 'Players' – and there will be others to follow.
Having created the archive-players.php file, the content is being truncated and turned into an excerpt – when I want to display all of the content written for that particular page. Looking at the base archive.php file, I can't figure out what is causing this to happen or where needs editing within the custom template file.
Does it have any relation to the steps in this article?
I have successfully created a single-players.php template file that looks like it'll do what I want it to (early days yet). But I must admit I haven't followed Step 3 in that article because it was truncating the copy too, so I left generate_do_template_part( 'single' ); untouched.
Hi Pete,
Assuming your archive-players.php copied exactly what the default archive does, then the truncation may be related to the excerpt behavior.
Truncation may be coming from the use of "More block" within the content.
Displaying a manual except in place of the default full content display may also be perceived as "truncation".
As for having a single-xxxxx.php, it shouldn't have anything to do w/ the archives as archive-xxxx.php templates and single-xxxxx.php templates are completely independent from each other.
To be sure, we can help you out in checking the back-end of the site to verify a few things.
You can provide us temporary backend access through the private information text field - https://docs.generatepress.com/article/using-the-premium-support-forum/#private-information
Thanks Elvin - have provided temporary backend access in the private text field.
Hi there,
question - are you going to be using the Block Element - Content Template to design the post article ?
Hi David,
If I've understood the question right, the answer is yes. The 'Player Archive' you see at /players/ is set up as a Page, created with block elements and setting the page template as Archive (Player) (or archive-player.php).
So this is what i mean:
https://docs.generatepress.com/article/block-element-content-template/
You can use a Block Element - Content Template to design the player post to be displayed in that archive.
If thats the case then you have the GP Dynamic Content block that can be used to display the full content of the individual post
Ooh, this is an interesting feature – thanks for sharing.
I'm not sure, however, if it'd solve my specific problem? On my Player Archive, I want to display all of the text – not just an excerpt and Read More link, which is what is currently happening because the archive-players.php template is applied.
If I delete the archive-players.php file, it reverts back to the page.php template – and the copy is shown in full. And I can't (yet) figure out what difference is making that happen.
If your solution will solve my specific problem, apologies for not realising it immediately. Would it be a case of deleting the archive-players.php file, using page.php, and then use a conditional Block Element to display the list of players?
If your archive-players is the same as the themes archive.php - and it still uses this function:
Then you should be able to select the Players Archives in the Block Element Display Rules to display that content template.
Sorry David, I thought I'd replied to you – but clearly I didn't.
I've been exploring what I can make happen with the Block Elements to create this Archive page. I can see the benefits of doing so, although I do have three remaining questions (if they fall under your support remit):
- 1. This may have been a source of confusion previously, but the Players Archive had previously been set up as a Page - albeit using the
archive-players.phptemplate. So, the content that was truncating was actually Page content – not a post. I did it that way as I found it easier to optimise using the Yoast plugin. Is it possible to call through the page content within thearchive-players.phptemplate file to act as an 'introduction'. Or would it need to be hard-coded? (Hopefully that all made sense?) - 2. Using Block Elements, I was exploring the option of introducing a search bar for that particular archive. But doing so meant it repeated after every post entry (and there are a lot). Is the only way to avoid this to hard-code the search functionality into the template file by either code or shortcode?
- 3. Related to the search element, is there functionality anywhere within the theme for the search bar to filter and show posts as a person types? Or is that something I'd need to look to another plugin/developer for?
For #1:
If it is an actual archive page now then you can create a custom field for the introduction and have it displayed by a Block Element - hook, hooked to any hooks before the loop of the archive page. See this for hook reference - https://docs.generatepress.com/article/hooks-visual-guide/#archives
Or you can skip the custom field and write the introduction content directly on a Block element - Hook if the introduction is going to be for this specific archive page only. :)
For #2 (and #3, they seem related): You should create a separate block hooked to a hook outside of the loop so it doesn't get repeated for every post item.
For #3: Are you pertaining to Gutenberg's search block? https://wordpress.com/support/wordpress-editor/blocks/search-block
If yes, the theme stays clear of WordPress default blocks. If you wish for a search feature w/ more functionality, you may have to consider a separate plugin and then hook it in.
Thanks Elvin (and David).
The more I understand of Block Elements and hooks, the more I see what's possible.
With the search bar query, I am looking for that extra functionality that'll need a separate plugin – but I now at least know how to hook it in. Thanks.
No problem. Let us know if you need further help. :D