2

I have a template page that is supposed to load all blog posts(posts stream) and I am working in child theme. For some reason I get index.php returned from parent theme instead of modified one that I have in child theme directory.

code:

<?php
/*
Template Name: Blog
*/

// Which page of the blog are we on?
$paged = get_query_var('paged');
query_posts('cat=-0&paged='.$paged);


//load index to show blog
load_template(TEMPLATEPATH . '/index.php');

?>

Any ideas how to solve this, so it loads child theme index.php instead of parent?

8
  • 1
    Try get_template_directory() instead for TEMPLATEPATH. Return the absolute path to the directory of the current theme (without the trailing slash) - not the child.
    – bueltge
    Sep 6, 2016 at 14:49
  • This also returns parent directory, however STYLESHEETPATH returns the child themes path. Problem solved! Thanks for suggestion. :)
    – Mindaugas
    Sep 6, 2016 at 14:55
  • 1
    Right. I have understand your question that you like the parent theme. You should not work with the constant, maybe it is changed, use the function get_stylesheet_directory().
    – bueltge
    Sep 6, 2016 at 14:59
  • get_stylesheet_directory() returns error for some reasone.
    – Mindaugas
    Sep 6, 2016 at 15:23
  • if that custom page template is attributed to the page set as 'posts page', it won't be used. really read codex.wordpress.org/Creating_a_Static_Front_Page - also, there are other ways of changing what the index page shows; see codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
    – Michael
    Sep 6, 2016 at 22:37

1 Answer 1

4

In your context you use the wrong constant. You must use the constant STYLESHEETPATH for the path to the active child theme. The constant TEMPLATEPATHget the path to the parent theme, that was referenced in the child theme.

But, a important hint. The constant is deprecated, see the ticket #18298 for more information. That's is the point that you should use the function get_stylesheet_directory() to get the right path.

Additional also the hint, also the constant TEMPLATEPATH is deprecated and also here the hint to use the associated function get_template_directory().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.