- This topic has 13 replies, 2 voices, and was last updated 8 years, 8 months ago by
Tom.
-
AuthorPosts
-
January 7, 2015 at 9:09 am #62575
Pedro
Hello Tom,
I created a custom post type named ‘restaurante’. For some reason, when I access the corresponding archive page (check it here), feature images don’t appear.
I think I’ve customized the theme properly, also enabling “Show” feature images on the Blog add-on.
Any hints? Thanks in advance (and happy 2015)!
Pedro
PS – Also, is there a way to have this custom post archive page as an editable main page for the custom post? E.g. in this case I’d write a some text about restaurants, add some images, etc.
January 7, 2015 at 1:19 pm #62630Tom
Lead DeveloperLead DeveloperHi Pedro,
It doesn’t look like you’re using GeneratePress for this site? The add-ons will only work when using GP.
Let me know π
January 7, 2015 at 1:37 pm #62632Pedro
Sorry, I momentarily switched to try stuff out… it’s back on now!
January 7, 2015 at 1:56 pm #62636Tom
Lead DeveloperLead DeveloperAh – I see the issue.
By default, GP only looks for posts in the “post” post type to include the post image.
I think I’ve made a change that should fix this in the next update – need to do some testing.
Here’s what you can do for now..
/** * Prints the Post Image to post excerpts * Use a custom post type */ if ( ! function_exists( 'generate_custom_post_type_post_image' ) ) : add_action( 'generate_after_entry_header', 'generate_custom_post_type_post_image' ); function generate_custom_post_type_post_image() { // If there's no featured image, return if ( ! has_post_thumbnail() ) return; // If the post type is "restaurante", and we're not on a single template if ( 'restaurante' == get_post_type() && !is_single() ) { ?> <div class="post-image"> <a href="<?php the_permalink();?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a> </div> <?php } } endif;
You can add that snippet of code using a plugin like this: https://wordpress.org/plugins/code-snippets/
Note: If you update to the newest version and you end up with duplicate post images, it means I fixed this issue, and you can remove the above snippet.
Let me know π
January 7, 2015 at 3:09 pm #62639Pedro
It works like a charm, Tom! Thank you so much.
January 7, 2015 at 3:18 pm #62641Tom
Lead DeveloperLead DeveloperGlad I could help.
I’ve fixed this in 1.2.5, so you may experience double featured images when you update.
If that happens, simply remove the snippet I just gave you.
Thanks!
January 7, 2015 at 5:50 pm #62648Pedro
Thanks, I will.
It seems like the same thing is happening to the sidebars, however. Compare: custom post type vs normal post.
I have the theme customized with sidebar-content. Also, the sidebar appearing at the bottom of the custom post isn’t the correct one (using inspect element, it’s identified as a “right sidebar”). I suppose it’s the same issue?
January 7, 2015 at 6:40 pm #62684Tom
Lead DeveloperLead DeveloperAre you using a custom page template for this post type?
The HTML structure is missing a major component which holds the content:
<div id="primary"...
You can see it (inspect element) on the normal post, but it’s not there for the post type.
January 7, 2015 at 7:11 pm #62697Pedro
Sorry, I can’t code at all, just go by intuition (but with enough precaution…).
I think I’ve got it working! Basically copied your single.php to my custom post’s php, only replacing what seems to be the content part of the code.
Note: I’m using the WP Editor to do this and it seems to be identifying an error at:
</main><!-- #main --> </div><!-- #primary -->
That is, </main> and </div> are colored red.
January 7, 2015 at 9:25 pm #62740Tom
Lead DeveloperLead DeveloperThat usually means the opening to those tags have been stripped.
This is what your file should look like:
<?php /** * Your custom page template * * @package Generate */ get_header(); ?> <div id="primary" <?php generate_content_class();?>> <main id="main" <?php generate_main_class(); ?> itemtype="http://schema.org/Blog" itemscope="itemscope" itemprop="mainContentOfPage" role="main"> <?php do_action('generate_before_main_content'); ?> <?php while ( have_posts() ) : the_post(); ?> YOUR CUSTOM STUFF IN HERE <?php endwhile; // end of the loop. ?> <?php do_action('generate_after_main_content'); ?> </main><!-- #main --> </div><!-- #primary --> <?php do_action('generate_sidebars'); get_footer();
January 8, 2015 at 9:12 am #62836Pedro
Yeah, that’s what I have except this last part before the end of the loop:
<?php // If comments are open or we have at least one comment, load up the comment template if ( comments_open() || '0' != get_comments_number() ) : ?> <div class="comments-area"> <?php comments_template(); ?> </div> <?php endif; ?>
But yeah, that’s pretty much what I did π thanks again, Tom!
January 8, 2015 at 10:12 am #62844Tom
Lead DeveloperLead DeveloperAnd it’s still not working?
In that case, you have some broken HTML that you’re adding into the middle section.
Make sure you close every
<div>
you open.January 8, 2015 at 10:20 am #62846Pedro
No no, everything is working π thank you
January 8, 2015 at 10:23 am #62847Tom
Lead DeveloperLead DeveloperAwesome! You’re welcome π
-
AuthorPosts
- You must be logged in to reply to this topic.