Overriding news.php in Child Theme for Future Scheduled News Posts
-
Hi everyone,
I'm currently working on creating a child theme for Laytheme. I have successfully set up my child theme with its own style.css, functions.php, and header.php. However, I'm encountering an issue with overriding the "news" functionality.
I use the news element as a kind of calendar to display events, and I need the events to be sorted by date, including future-scheduled posts (currently, only published posts are shown). I've modified the query in news.php to include future posts by changing the query parameter from:
'post_status' => 'publish',
to:
'post_status' => array('publish', 'future'),
and I also implemented a custom sorting function to order the events by date. However, despite copying the entire /news folder (with my modified news.php) into my child theme using the same folder structure, my changes don't seem to take effect—the parent theme’s version of news.php is still being loaded.
It appears that the parent theme includes the file using a direct require call like this:
require get_template_directory() . '/news/news.php';
I have read several times that Laytheme might not be fully designed with child themes in mind, which could be causing this issue. I’m looking for a method to override news.php in a child theme without modifying the parent theme’s files directly. Or maybe I am overcomplicating things and there is a much easier way to achieve what I am looking for.
Has anyone encountered this issue or found a solution to ensure that future-scheduled news posts are displayed and sorted by date while using a child theme? Any help or suggestions would be greatly appreciated.
Thanks in advance!
-
yea child themes are not really doable with lay theme
child themes work like this:
every page type has its own php file
every page can contain template parts. those are php files toowhen creating a custom child theme,
all created page templates and template part php files will take precedencehowever, what you're trying to override is not a page or template part file
actually lay theme only has index.php, page.php, header.php and footer.php as overridable filesmost of the logic is inside all kinds of php functions that are separated into different php files and folders that are not part of any overridable template file architecture
you have these options:
- modify lay theme directly. be unable to update lay theme without it overriding your changes
- suggest to me what kind of feature you want, and i may implement it into lay theme
- make modifications to the news.php file. based on these modifications, suggest what kind of filters or actions i should implement.
for example i could easily create a wordpress filter where you can use it to query array('publish', 'future'), instead of only 'publish'
once i implemented these filters, you create a wordpress plugin that hooks into these filters. this way you have your code in separate files, and it wont be overriden by lay theme updates
for example here, i would just need to add to my news.php code which would then be part of the standard lay theme:
$post_status_to_query = array('publish'); $post_status_to_query = apply_filters('lay_news_post_status_to_query', $post_status_to_query); …my other code 'post_status' => $post_status_to_query, ...my other code
and you would then in your plugin just write:
function my_query_post_status($post_status_to_query){ $post_status_to_query []= 'future'; return $post_status_to_query; } add_filter('lay_news_post_status_to_query', 'my_query_post_status', 10, 1);
(i think thats the correct code :DD)
- if you're trying to do quite a lot of heavy customizations and have a client who would pay, i could also like give you a cost estimate and code it myself
2/2
Before you post:
- When using a WordPress Cache plugin, disable it or clear your cache.
- Update Lay Theme and all Lay Theme Addons
- Disable all Plugins
- Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"
This often solves issues you might run into
When you post:
- Post a link to where the problem is
- Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
- If the problem is difficult to explain, post screenshots / link to a video to explain it