- This topic has 26 replies, 2 voices, and was last updated 4 years, 2 months ago by
Tom.
-
AuthorPosts
-
January 14, 2019 at 12:26 pm #781826
Jem
Hi
I’m struggling with displaying a CPT with custom fields on a music festival website (which I’m moving from Genesis to GeneratePress), having spent all day trawling the web and the GP forums I can’t see wood for trees. I have very limited experience dealing with CPTs, mainly from originally developing this site in Genesis several years ago, and only the most basic grasp of PHP (usually via snippets). At this stage it’s a local site so no URL, sorry.
I have created the CPT (‘artist’) and two taxonomies (‘stage’ and ‘when’*) using Custom Post Types UI and the custom fields using ACF.
I’m using a child theme so I’ve copied archive.php, single.php and content-single.php to the child theme directory and renamed them to archive-artist.php, single-artist.php and content-artist.php.
Initially I had the ACF fields in content-artist.php but they weren’t displaying at all so now I’ve got them in a hook (after_entry_header) for the CPT, which is now displaying them, of course before entry-content. I would prefer if I could have the fields inside entry-content, replacing what would be the default WP post content for a standard post. Is this possible? Would that be by using content-artist.php instead of a hook? If so, which part of it do I need to modify, and can I just insert the content of the hook directly?
Two other issues:
- Post navigation for the CPT – I’ve added the code from this post to my functions.php but nothing shows up on the front end (no other functions in there yet). Post nav is set to display in the customizer and I’ve disabled all but essential plugins for this page to display as it should.
- I need to display the custom taxonomies in the post footer, but as unlinked/text only as there is no need for taxonomy archives. How can I achieve this?
Any pointers much appreciated.
*’when’ is actually ‘day’, as in the day of the performance but ‘day’ is reserved for core WP so I had to name it ‘when’.
January 14, 2019 at 6:22 pm #782060Tom
Lead DeveloperLead DeveloperHi there,
For the first issue, make sure you’re changing this line your single.php file: https://github.com/tomusborne/generatepress/blob/2.2.1/single.php#L26
It should be:
get_template_part( 'content', 'artist' );
Let me know if that fixes it.
1. Did you update
project
in that code toartist
(if that’s your CPT name)?2. You could try something like this:
add_action( 'generate_after_content', function() { if ( is_singular( 'artist' ) ) { $terms = get_terms( array( 'taxonomy' => 'post_tag', // Update to your custom taxonomy 'hide_empty' => false, ) ); foreach( $terms as $term ) { echo '<span class="term-name">' . $term->name . '</span>'; } } } );
January 15, 2019 at 6:55 am #782592Jem
Hi
Thanks. Line 26 of content-artist.php is (and was):
get_template_part( 'content', 'artist' );
No joy, all I’m getting on the front end is the title and featured image. This is how I have inserted content between line 62 and line 65 of content-single.php (renamed to content-artist.php and copied to the child theme directory):
<?php the_content(); ?> ALL THE ACF FIELDS HERE IN VARIOUS DIVS <?php wp_link_pages( array(
Is that correct?
- Yes, project is changed to artist, nothing is showing up.
- I’ve added that code to functions.php but again, nothing is showing up, even when the artist post content is visible (via the hook).
January 15, 2019 at 8:26 am #782695Tom
Lead DeveloperLead DeveloperThat looks right. What happens if you just add plain text in that space? Does it display?
Any chance you can set it up on a live server so I can see one of the single artist pages?
January 15, 2019 at 10:55 am #782835Jem
Nothing shows up when I add text to content-artist.php in place of the ACF fields either. Something, probably very small, is missing from the set up.
The site is very bulky so it’ll take a while to get it on a staging server. I’m uploading it now, I’ll let you know when it’s up and I’m happy to set up admin access if needed, and also to email the relevant template files if you need to see them. Thanks.
January 15, 2019 at 11:19 am #782878Jem
Is there any way I can get the URL – once it’s uploaded – to you privately, and maybe login details too? It’s not ready at all for public viewing.
January 15, 2019 at 4:38 pm #783109Tom
Lead DeveloperLead DeveloperHmm ok, that means the templating isn’t working.
Are you sure the custom post type has
artists
as the ID/slug?You can send the details through our contact form: https://generatepress.com/contact
Just be sure to mention this topic.
January 16, 2019 at 11:04 am #783923Jem
Thank you, I appreciate your attentive support. I had a bunch of other things to attend to today but the site is now on a server and I’ve re-done all the steps to be sure everything is the way it should be, still no joy.
URL etc coming through the pre-sales contact form.
January 16, 2019 at 11:43 am #783973Jem
Just to say, not sure if you’ve got to it yet but it seems I’ve been an idiot. I was trialling a customised child-theme and forgot to switch back to the standard child theme, which was the one I’ve been editing templates in, it seems to be more or less working now.
January 16, 2019 at 12:08 pm #784003Jem
Just a couple more things – the taxonomy terms are all showing up below the post. I’ve set the function to display the ‘stage’ category and it’s showing all the stage names, where I actually only want the stage that a given artist will be appearing on, along with the day of their appearance. How would I edit that snippet to show both the stage and day (‘stage’ and ‘when’ taxonomies) relating to a given artist?
Also, is it possible to give a higher priority to the content? I have Shariff Wrapper set to display share icons below posts, but they’re appearing above the CPT content.
January 16, 2019 at 3:03 pm #784133Tom
Lead DeveloperLead DeveloperAh, let’s try this instead:
add_action( 'generate_after_content', function() { if ( is_singular( 'artist' ) ) { $terms = wp_get_post_terms( get_the_ID(), 'your-taxonomy-name' ); foreach( $terms as $term ) { echo '<span class="term-name">' . $term->name . '</span>'; } } } );
You’d have to set the sharing plugin to not automatically display the sharing icons. Then you could manually display them within the same hook as the terms.
Plugins that automatically add content to your content filter the actual content, so there’s no way a hook can appear above them.
January 16, 2019 at 4:46 pm #784178Jem
Thanks very much Tom, that works. 99% done.
How to reference multiple terms (stage and day)? So far I’ve just added the snippet twice, once for each. Is there a way to reference both in one function (an array?) and output them both in one div? I’ve been trying various things without success.
January 17, 2019 at 8:41 am #784785Tom
Lead DeveloperLead DeveloperAre those separate taxonomies?
If so, maybe this:
add_action( 'generate_after_content', function() { if ( is_singular( 'artist' ) ) { $stages = wp_get_post_terms( get_the_ID(), 'stage' ); $days = wp_get_post_terms( get_the_ID(), 'day' ); echo '<div class="term-names">'; foreach( $stages as $term ) { echo '<span class="term-name">' . $term->name . '</span>'; } foreach( $days as $term ) { echo '<span class="term-name">' . $term->name . '</span>'; } echo '</div>'; } } );
January 17, 2019 at 10:20 am #784871Jem
Thanks Tom, excellent. I just needed to put the right term names in. All good, many thanks for excellent support.
January 17, 2019 at 11:02 am #784906Tom
Lead DeveloperLead DeveloperGlad I could help 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.