Skip to content
This repository was archived by the owner on May 6, 2025. It is now read-only.

Commit c82b921

Browse files
committed
added the possibility to call a partial and pass it arguments
1 parent b2cc42d commit c82b921

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

configure/utilities.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
if ( ! function_exists( 'get_partial' ) ) :
4+
5+
/**
6+
* Load given template with arguments as array.
7+
* arguments.
8+
* @see get_template_part().
9+
* @see http://wordpress.stackexchange.com/a/103257
10+
* @author Julien Vasseur julien@poigneedemainvirile.com
11+
*/
12+
function get_partial( $slug = null, $name = null, array $params = array(), $prefix = null ) {
13+
global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID;
14+
15+
/**
16+
* Fires before the specified template part file is loaded.
17+
*
18+
* The dynamic portion of the hook name, `$slug`, refers to the slug name
19+
* for the generic template part.
20+
*
21+
* @param string $slug The slug name for the generic template.
22+
* @param string $name The name of the specialized template.
23+
*/
24+
do_action( "get_partial_{$slug}", $slug, $name );
25+
do_action( "get_template_part_{$slug}", $slug, $name );
26+
27+
$templates = array();
28+
$name = (string) $name;
29+
if ( '' !== $name ) {
30+
$templates[] = "{$slug}-{$name}.php";
31+
}
32+
33+
$templates[] = "{$slug}.php";
34+
35+
$_template_file = locate_template( $templates, false, false );
36+
37+
if ( is_array( $wp_query->query_vars ) ) {
38+
extract( $wp_query->query_vars, EXTR_SKIP );
39+
}
40+
41+
if ( isset( $s ) ) {
42+
$s = esc_attr( $s );
43+
}
44+
45+
if ( ! is_null( $prefix ) ) {
46+
$flags = EXTR_PREFIX_ALL;
47+
// ensure prefix doesn't end with an underscore, it is automatically added by extract()
48+
if ( '_' === $prefix[ strlen( $prefix ) - 1 ] ) {
49+
$prefix = substr( $prefix, 0, -1 );
50+
}
51+
} else {
52+
$flags = EXTR_PREFIX_SAME;
53+
$prefix = '';
54+
}
55+
56+
extract( $params, $flags, $prefix );
57+
58+
require( $_template_file );
59+
}
60+
61+
endif;

readme.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,23 @@
55
- [ES6](https://babeljs.io/learn-es2015/) for JavaScript
66
- [SASS](http://sass-lang.com/) preprocessor for CSS
77
- [Breakpoint slicer](https://github.com/lolmaus/breakpoint-slicer/) for faster media queries
8-
- [Bootstrap 4](https://github.com/lolmaus/breakpoint-slicer/) as your css framework
8+
- [Bootstrap 4](https://getbootstrap.com/docs/4.0/getting-started/introduction/) as CSS framework
99
- [Gulp](https://gulpjs.com/) & [Webpack](https://webpack.js.org/) for managing, compiling and optimizing theme's asset files
1010

1111
## Requirements
1212

1313
* Node
1414
* Gulp
1515

16-
1716
## Usage
1817

19-
First, clone this repository.
18+
First, clone this repository in your WordPress theme directory.
2019

2120
On your local machine, run the following commands IN THE THEME :
2221

2322
npm install
2423

25-
Launch your watch for assets with this command :
24+
Launch your watch for assets with :
2625

2726
npm run start
2827

0 commit comments

Comments
 (0)