single-{$post_type}-{slug}.php for custom post types

A) The Base in Core As you can see in the Codex Template Hierarchy explanation, single-{$post_type}.php is already supported. B) Extending the core Hierarchy Now there’re gladly some filters and hooks inside /wp-includes/template-loader.php. do_action(‘template_redirect’); apply_filters( ‘template_include’, $template ) AND: a specific filter inside get_query_template( $type, … ) named: “$type}_template” B.1) How it works Inside the … Read more

Get page id by template

When a page is created, the assigned template to that page is saved as custom post meta in the same way as custom fields. The meta_key is _wp_page_template and the meta_value will be the page template You can simply make use of get_pages to retrieve all pages which have a meta_value of the specified template … Read more

Custom templates not showing up in template dropdown

Just in WordPress 4.9 there’s this bug: https://core.trac.wordpress.org/ticket/42573 causing the template files to only be rescanned once every hour. To fix (until they release a new WP version with this changed), download the patch on that bug ticket and make the changes from the patch to wp-includes/class-wp-theme.php. Hope this saves someone the 2 hours I … Read more

Get custom post_type’s archive URL

Hi @Silent: Turns out there is a function in WordPress 3.1 that does exactly what you want and it is named get_post_type_archive_link(); here’s how you’d call it (assuming a custom post type named ‘product’): <a href=”https://wordpress.stackexchange.com/questions/11531/<?php echo get_post_type_archive_link(“product’); ?>”>Products</a> Below is my prior answer before I discovered that WordPress did indeed have a function built-in … Read more

Is there any way to use get_template_part() with folders?

In fact you can, I have a folder in my theme directory called /partials/ in in that folder I have files such as latest-articles.php, latest-news.php and latest-statements.php and I load these files using get_template_part() like: get_template_part(‘partials/latest’, ‘news’); get_template_part(‘partials/latest’, ‘articles’); get_template_part(‘partials/latest’, ‘statements’); Just dont forget to omit the .php from the file name.

Opinions and recommendations on the best barebones base theme [closed]

Bare bone themes are great, personally I prefer them over frameworks. I have noticed that ‘liking’ one over another comes down to how it feels, so I would suggest trying several out until you find one. For instance a lot people like WordPress boilerplate but I could not get the hang of it. My current … Read more