Dev oriented plugin to add silo feature :
- It will use
wp_localize_script
to localize (javascript), depending on some conditions, terms from wanted taxonomies against wanted post type. - You can overwrite default term's object to add/remove some values.
- By default a custom REST Api route is created to ease matching post type and taxonomy silo content.
- These matching content will be displayed using a _s template located by default into
silo/templates/
folder. But they can be overwrited into theme or child-theme. - The silo is displayed with an action from the
silo/blocks/
folder. But it can be overwrited into theme or child-theme. - By default, plugin generate a default silo view into
silo-{taxonomy_name}.php
template.
- Download and install using the built-in WordPress plugin installer.
- Site Activate in the "Plugins" area of the admin.
- Optionally drop the entire
bea-silo
directory intoplugins
. - Add into your theme's functions.php file or through a plugin, the expected Steps.
- Add repository source : { "type": "vcs", "url": "https://github.com/BeAPI/bea-silo" }.
- Include "bea/bea-silo": "dev-master" in your composer file for last master's commits or a tag released.
If using the default taxonomy's silo view. Watch out about SEO with duplicate content.
While waiting ticket/40413 merge into core, add post type support like this :
<?php add_post_type_support( {post_type}, 'silo', {taxonomy_1}, {taxonomy_2}, {etc} );
After merge, you could do :
<?php register_post_type( {post_type}, [ 'supports' => [ 'silo' => [ {taxonomy_1}, {taxonomy_2}, {etc} ] ] ] );
On the hook bea\silo\localize_terms
you specify where to localize your terms taxonomy for a post type.
<?php
/**
* Check custom conditions to check if to work on current taxonomy against current post type.
*
* @author Maxime CULEA
*
* @since 1.0.0
*
* @param bool $localize_taxonomy Whatever to localize terms against given taxonomy.
* @param string $taxonomy The taxonomy name as context.
* @param string $post_type The Post Type name as context.
*/
apply_filters( 'bea\silo\localize_terms', false, $taxonomy, $post_type )
<?php
/**
* Depending on context, add the thematic silo
*
* @author Maxime CULEA
*
* @param $hide_or_display
* @param $taxonomy
* @param $post_type
*
* @return bool
*/
function bea_where_to_localize_thematic( $hide_or_display, $taxonomy, $post_type ) {
return BEA_TAX_THEMATIC_NAME === $taxonomy && BEA_CPT_POST_NAME === $post_type && is_home() ? true : $hide_or_display;
}
add_filter( 'bea\silo\localize_terms', 'bea_where_to_localize_thematic', 10, 3 );
By default the plugin is generating a default template view for your silos located on : silo-{taxonomy_name}.php
.
You Can overwrite this default template by playing withe the following filter :
<?php
/**
* Change the default taxonomy silo slug
*
* @author Maxime CULEA
*
* @since 1.1.0
*
* @param string $slug The taxonomy's default silo slug.
* @param string $$taxonomy The taxonomy name working on.
*/
return apply_filters( 'BEA\Helpers\taxonomy_silo_slug', sprintf( 'silo-%s', $taxonomy ), $taxonomy );
It is most useful when displaying a silo on homepage - you will be able to come back into deep silo chosen hierarchy. In this case your homepage template and the default one could be the same. So watch out about duplicate content.
On the hook bea\silo\term_query\args
you filter the args in order to retrieve the taxonomy's terms. By default $args
has only 'hide_empty' => false
.
<?php
/**
* Filter the arguments to retrieve given taxonomy's terms.
*
* @author Maxime CULEA
*
* @since 1.0.0
*
* @param array $args Arguments for the WP_Term_Query or the get_terms();
* @param string $taxonomy The taxonomy name as context.
*/
$args = apply_filters( 'bea\silo\term_query\args', $args, $taxonomy );
On the hook bea\silo\term_object
you filter the given array to add or remove some values from the current term for the given taxonomy and post type.
<?php
/**
* Filter term object to add / delete some attributes.
*
* @author Maxime CULEA
*
* @since 1.0.0
*
* @param array $new_item The formatted term object for response.
* @param \WP_Term $_term The term object.
* @param string $taxonomy The taxonomy name as context.
*/
return apply_filters( 'bea\silo\term_object', $new_item, $_term, $_term->taxonomy );
<?php
/**
* Add the term's color
*
* @author Maxime CULEA
*
* @param $new_item
* @param \WP_Term $_term
* @param $_taxonomy
*
* @return mixed
*/
function bea_silo_add_color( $new_item, \WP_Term $_term, $_taxonomy ) {
if ( 0 == $new_item['level'] ) {
$new_item['color'] = sprintf( '#%s', get_field( 'color', $_term, true ) );
}
return $new_item;
}
add_filter( 'bea\silo\term_object', 'bea_silo_add_color', 10, 3 );
On the action bea\silo\display
you display the wanted silo for the given post types and the taxonomy.
<?php
/**
* Action in purpose to display silo's underscores and html templates depending on the given post types and taxonomy.
* Underscore templates :
* - button
* - results
* - no results
*
* @author Maxime CULEA
*
* @since 1.0.0
*
* @param array $post_types : array of wanted post type names
* @param string $taxonomy : the taxonomy name
*/
do_action( 'bea\silo\display', [ {post_type_1}, {post_type_2} ], [ {taxonomy} ] );
With the matching args, custom templates (_s) and views (html) can be made and they are loaded in the below order :
- Child theme
- Theme
- Silo plugin
- _S templates are conditionally loaded :
- silo/templates/{taxonomy}-{template}-tpl.js (1 & 2)
- silo/templates/{template}-tpl.js (1 & 2)
- templates/{template}-tpl.js (3)
- View :
- silo/blocks/{taxonomy}-silo.php (1 & 2)
- silo/blocks/silo.php (1 & 2)
- blocks/silo.php (3)
A REST Api route is automaclly registered to get contents depending on post types and a taxonomy term.
REST Api route looks like {ndd}/wp-json/bea/silo?post_types[0]=post&term_id=4
, where :
- post_types is an array of post type names to retrieve the content for
- a silotable taxonomy's term id for the given post types to retrieve the contents for
- Fix compatibility bug on REST_REQUEST
- Handle empty taxonomy silo case
- Add new filter on args for register_rest_route in controller
- Add errors on function get_contents_check
- Fix items response with childrens
- Update items response with childrens
- Load JS/Script Data on wp_enqueue_script hook
- Add composer json file
- Add some filters.
- Handle a default silo slug and view for a taxonomy.
- For hierarchical taxonomies, construct full term link with ancestors.
- Refactoring.
- Fix REST Api class.
- Add display "Blocks" class for _s and view display.
- Refactoring & reformatting.
- Update readme with usage & example.
- Add plugin's .pot.
- Init with boilerplate 2.1.6.