Custom post type not respecting template hierarchy

From what you’ve told us, your single-case-study.php should be the correct file. To help troubleshoot, add this line to your header.php: <!– <?php global $template; print_r($template); ?> –> Then view the source of a single case study and see which template WP is outputting. Once you have identified the file, if the solution isn’t clear, … Read more

Display custom post types in wp_list_pages

To simplify things, first make your archives actual Archives – not Pages. That will help you later on in listing the correct content. unregister_post_type(‘blog’); unregister_post_type(‘event’); unregister_post_type(‘news’); Unregistering the post type won’t delete any content, it will just ensure that when you re-register them, the settings will take effect. Tweak your register_post_type calls which should look … Read more

Conditional: IF current user has NOT commented on current post (not including post author)

[EDIT] Here is the modified code: $post_id = get_the_ID(); // ID of the current post. $user_id = get_current_user_id(); // ID of the current user. $post_author_id = get_post_field( ‘post_author’, $post_id ); $is_post_author = ( $user_id && $post_author_id == $user_id ); $can_comment = $is_post_author; /* * If $can_comment is not yet TRUE, then it’s because either: * … Read more

Is it possible to customize the post according to post format in single.php?

Yes, it is possible. The easiest and very readable way would be to do this like TwentyX themes do – using get_post_format and get_template_part functions. Let’s say that your current single.php file looks something like this: <?php get_header(); ?> … <?php while ( have_posts() ) : the_post; ?> <article …> … </article> <?php endwhile; ?> … Read more

How to put single-***.php in a specific folder?

Changing how WordPress loads files can be very difficult and potentially destroy logic other plugins rely on. Instead, I usually make use of get_template_part() in this case like so single.php <?php get_template_part(‘singles/single’, get_post_type()); And your files like singles/single-foo.php (for CPT foo) singles/single-bar.php (for CPT bar) singles/single.php (this is the default)

Thumbnail Image to go in the post aswell

Use the post thumbnail for the single blog pages too. You can use the add_image_size() function to create an additional image size that is displayed on the blog posts. add_image_size(‘single-post-image’, 650, 250, true); // name, width, height, crop mode Then in single.php the_post_thumbnail(‘image-size’); Simply place the first function in your functions.php, and the second in … Read more

Adding comments to my custom theme

While much of comments implementation became simpler in modern WP versions, it still isn’t quite make-comments-happen button. You will need to put together this part of template, most of related functionality is handled by: wp_list_comments() comment_form() Check native WP themes for complete start to end implementation, although they tend to be a little bulky.