Tag Info

Hot answers tagged

16

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 ...


10

Always flush the rewrite rules when you register a new public post type or taxonomy. Otherwise the internal rewrite rules will not take that into account when an URL is mapped to a query. You can automate that process by hooking into registered_post_type and registered_taxonomy. Below is the updated code, based on feedback from comments and other people. ...


5

The front-page.php file is the site front page template. It will always be used on your site front page, regardless of whether get_option( 'show_on_front' ) is set to page or posts. The home.php template file is the blog posts index template. It will always be used to display your blog posts index, regardless of whether the blog posts index is displayed on ...


4

A category page is an archive page. So is_archive() will return true on a category page. Try to push down is_category() further, or use is_category() before is_archive(). Like This if ( is_search() ) { // Search Result content } elseif( is_category() ) { // Category archive content } // check for tag, taxonomy, date before elseif ( is_archive() ) ...


4

WordPress uses a Template Hierarchy to determine which template file to load based on the current context: This diagram is a visual representation of \wp-includes\template-loader.php, that contains the context-based template-selection logic. As to your specific questions: For example, suppose I have two posts by the same author. How do I make WP use ...


4

There is no specifica template for child pages, but you can do this pretty easily with the get_template_part() function. First create a file called "content-child.php". Second create a file called "content.php". Next, inside of page.php, place this: if( $post->post_parent !== 0 ) { get_template_part('content', 'child'); } else { ...


3

Following the Template Hierarchy image, I don't see such an option. So heres how i'd go about it: Solution 1 (Best in my opinion) Make a template file and associate it to the review <?php /* Template Name: My Great Review */ ?> Adding the template php file in your theme directory, it would appear as a template option in your post's edit ...


3

wp-includes/template-loader.php is the file which is the template hierarchy. However, by the time that file executes, all the template decisions are already made since all that file does is check for boolean flags (defined in wp-includes/query.php function init_query_flags). So all the heavy-lifting and interesting code happens before that at ...


3

I'm pretty sure you could also do what you want by filtering template_include. This is super-untested, but maybe this can get you headed in the right direction: function wpse53871( $template ) { global $post; // check if is a Post and in the 'scott' category if( is_single( $post->ID ) && has_category( 'scott', $post ) ) { ...


3

Create a file front-page.php with the following content: locate_template( 'category-image-gallery.php', TRUE, TRUE ); That’s all. For the theme’s functions.php If you want to restrict the front page content to posts from that category, filter the front page query: add_action( 'pre_get_posts', 'wpse_74225_frontpage_categories' ); function ...


3

Remove the cat parameter from your query and name your template file category.php From the WordPress Codex on Template Hierarchy; 1. category-{slug}.php - If the category's slug were news, WordPress would look for category-news.php 2. category-{id}.php - If the category's ID were 6, WordPress would look for category-6.php 3. category.php 4. ...


3

index.php is shown whenever wordpress doesn't find an appropriate page template. Generally people use it as the template for their site's blog. If you are absolutely sure that it will never be reached, you can leave it empty. Just make sure you have that file present, otherwise the theme will not work As a personal preference, when coming across this kind ...


3

In short: index.php is a fallback template only, in case no appropriate template was found home.php is used for the blog (a listing of recent posts) front-page.php is used for the landing-page The universal index.php template The index.php template file is a fallback template. It is used as a last resort when no other more appropriate template is ...


3

get_header() accepts an argument, using it you can call a different headers. The only thing that get_header() does, is to include in the template where is called the file 'header.php' from child theme (if present) or from theme. If you use the argument $name, like so: get_header( $name), the function will look for a file named 'header-{$name}.php'. An ...


2

First check that there isn't a page set as a front page in "Reading Setting". If that is set, index.php is not used as the home page, but the template of the page you set as front page. In that case, you need to find that template and add you conditional is there. <?php if(is_user_logged_in()) { get_header(); ?> <div id="primary" ...


2

So what's the best practice here? I would say a combination of letting the theme handle it and providing a default with your plugin. You can use the single_template filter to switch out the template. In your callback, see if the theme provided a template for the post type, if it did, do nothing. <?php add_filter('single_template', ...


2

All this comes from a thorough reading of the Template Hierarchy. home.php is used if: Your site's front page is set to display a list of posts, or A static front page is set, and A visitor goes to the page that you've defined as your "list of posts" (eg, http://example.com/blog/) And the theme has a home.php file If the last condition isn't met -- ...


2

When you make a page the page for posts, it's no longer a "page" in the conventional sense. Refer to the Template Hierarchy for home page display- the quickest fix is to rename your blog template home.php, and WordPress will load that before index.php.


2

Take a look at the Codex: taxonomy-{taxonomy}-{term}.php - If the taxonomy were sometax, and taxonomy's term were someterm WordPress would look for taxonomy-sometax-someterm.php. In the case of Post Formats, the taxonomy is 'post_format' and the terms are post-format-{format}. i.e. taxonomy-post_format-post-format-link.php ...


2

the_content() does not grab the PHP file content.php, it simply displays a Post's content. Likewise, the_excerpt() grabs the excerpt of a post. get_template_part simply finds a file within your theme named whatever you put in, with an optional suffix. get_template_part( 'content' ); // content.php get_template_part( 'content', 'my_page' ); // ...


2

I suggest creating 3 files 1) regiontemplate-country.php 2) regiontemplate-city.php These 2 will contain the templates for country & city, then 3) taxonomy-region.php In this file, add the code to load the appropriate template <?php $term = get_term_by('slug', get_query_var('term'), 'region'); if((int)$term->parent) ...


2

I'm going to answer my own question for the sake of people who might run in the same issue as me in my setup I had a plugin handling taxonomies; one of these had the rewrite slug set to "year" - well, it turns out this conflicts probably with date based archives (?) and caused my posts and pages not loading but rather redirecting the user to the blog home - ...


1

I faced the same problem and just solved the issue after spending close to an hour figuring out the issue. So if your CPT (custom post type) single pages are using the index.php and not the single-post_type template, make sure you're not using query_posts improperly. For me, it turned out that I forgot to call wp_reset_query on one of the sidebar pages ...


1

This is all fixed. I still had a template assigned to the page in question (press), so it was taking priority. The page you're now seeing is correct in that it is pulling in content from a custom post type (Recent Stories) after the standard page content from the loop. Thanks for the help. Brett


1

Template hierarchy consist of templates, but not every template file is necessarily in hierarchy. Essentially hierarchy determines entry points (one of matching templates with pre-defined name structure), but from there template can further load additional arbitrary files. page-templates directory holds custom templates for pages (is_page() branch in ...


1

WordPress has a template hierarchy which will look for particular template files in a specific order. If it exists, WordPress will use that template file to render your output. For taxonomies, the specific hierarchy is as follows; 1. taxonomy-{taxonomy}-{slug}.php //e.g. taxonomy-region-milan.php 2. taxonomy-{taxonomy}.php //e.g. taxonomy-region.php 3. ...


1

If you are simply registering a custom post type called 'services" then your register code should look like register_post_type( 'services', $args ); Make sure the word "services" is exact in register_post_type. And Your post_type word should be max. 20 characters, can not contain capital letters or spaces Also make sure your has_archive parameter is set ...


1

First of all, enable WP_DEBUG in wp-config.php. Maybe you're changing the default query. Are you running query_posts somewhere? Take a look at the global $wp_query object. If so, you might want to try WP_Query class or running wp_reset_query() instead.


1

I think your settings in the WP-config can still be wrong - it could be your ABSPATH is returning the wrong value. The lines you need to check and change are --- (I've taken this from Mark Jaquith skeleton local WordPress install) // Custom Content Directory define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/content' ); define( 'WP_CONTENT_URL', ...


1

Pages are generally speaking rather inflexible, you would be better off using a custom post type. Also hooking into the actual page template dropdown would very likely be problematic (I doubt it would work without some serious hacking around). You're better off just writing your own meta box dropdown. I think your on the the right track with ...



Only top voted, non community-wiki answers of a minimum length are eligible