Comments (3)
@quentin-th Thanks for your input. I've copied the idea of your code and simplified it a bit. I've also changes the filter hook name to ajax_filter_posts_template_name
so it's more consistent with the other hook names. See https://github.com/Robbertdk/wordpress-ajax-filter-posts/tree/feature/overwrite-template-file#overwriting-template-files
from wordpress-ajax-filter-posts.
Hi,
This is indeed not implemented, but that wouldn't be hard, because the plugin uses a custom template loader.
You'll be able to overwrite the template with an apply_filter
function before returning the template in that function.
I'm quite busy the upcoming weeks. Can you write a PR for that?
from wordpress-ajax-filter-posts.
Hi,
Thanks for the informations !
I'm not sure if and how I could write a PR directly from Giuthub, I didn't clone the repo (sorry I don't use git much).
However I managed to create the filter, so here the code I wrote :
/**
* Locate template.
*
* Locate the called template.
* Search Order:
* 1. /themes/theme/ajax-posts-filters/$template_name
* 2. /3rd-party-plugin-dir-path/ajax-posts-filters/templates/$template_name
* 3. /plugins/ajax-filter-posts/templates/$template_name.
*
* @since 0.3.0
*
* @param string $template_name Template to load.
* @return string Path to the template file.
*/
public function get_local_template($template_name, $template = '') {
if (empty($template_name)) return false;
$template = locate_template('ajax-filter-posts/' . $template_name);
// Allow 3rd party plugin filter template file from their plugin.
$filter_template = apply_filters( 'get_local_template', $template_name, $template );
// if path is from a 3rd party plugin
if ( $filter_template !== $template ) {
if ( !file_exists( $filter_template ) ) {
_doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $filter_template ), '4.6.0' );
return;
}
$template = $filter_template;
}
// If template not in theme and or not in 3rd party plugin, get plugins template file.
if ( !$template && !$filter_template ) {
$template = plugin_dir_path( __FILE__ ) . 'templates/' . $template_name;
}
if ( !file_exists( $template ) ) {
_doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $template ), '4.6.0' );
return;
}
return $template;
}
and if it can help someone, here the add_filter
function :
add_filter( 'get_local_template', 'intercept_afp_template', 10, 3 );
/**
* Filter ajax filter posts templates.
*
* @param string $template_name Template file name.
* @param string $template Template file path.
*
* @return string The new Template file path.
*/
function intercept_afp_template( $template_name, $template ) {
$template_directory = trailingslashit( plugin_dir_path( __FILE__ ) ) . 'ajax-posts-filters/templates/';
$path = $template_directory . $template_name;
return file_exists( $path ) ? $path : $template;
}
from wordpress-ajax-filter-posts.
Related Issues (20)
- Make string 'toon meer' en 'toon minder' translatable
- Remove opinionated styling: more focus on the core concept of this plugin AJAX fetching and filtering
- Create a way to add this plugin as a composer package
- Initiate the plugin without the use of a shortcode
- Add the ability set a WordPress filter on the posts query arguments HOT 8
- There is an option to sort order and order by? HOT 3
- Issue loading posts HOT 9
- Don't allow users to set different post types in the AJAX call
- Target a specific instance of the shortcode in the filter hooks HOT 1
- Post status HOT 2
- Clear button HOT 2
- Trigger filter selection with hash url HOT 1
- Load more HOT 2
- meta key HOT 1
- JSON Parse error HOT 1
- See all terms even if there is no product linked to one of them HOT 2
- It is not possible to set specific styling for a taxonomy filter list
- It is not possible to have a filter that selects just one and deselect other options on select
- Accessibillity could be better
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wordpress-ajax-filter-posts.