• Stars
    star
    114
  • Rank 307,117 (Top 7 %)
  • Language
    PHP
  • License
    GNU General Publi...
  • Created almost 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A library which provides extended functionality to WordPress template parts, including template variables and caching.

Stable Release License PHP 7

Extended Template Parts

Extended Template Parts is a library which provides extended functionality to WordPress template parts, including template variables and fragment caching.

Features

  • Pass variables into your template parts and access them via the $this->vars array. No polluting of globals!
  • Easy optional caching of template parts using transients.

Minimum Requirements

PHP: 7.0
WordPress: 4.4

Installation

Extended Template Parts is a developer library, not a plugin, which means you need to include it somewhere in your own project. You can use Composer:

composer require johnbillion/extended-template-parts

Or you can download the library and include it manually:

require_once 'extended-template-parts/extended-template-parts.php';

Basic Usage

The get_extended_template_part() function behaves exactly like WordPress' get_template_part() function, except it loads the template part from the template-parts subdirectory of the theme for better file organisation. The usual parent/child theme hierarchy is respected.

get_extended_template_part( 'foo', 'bar' );

Use the $vars parameter to pass in an associative array of variables to the template part:

get_extended_template_part( 'foo', 'bar', [
	'my_variable' => 'Hello, world!',
] );

In your template-parts/foo-bar.php template part file, you can access the variables that you passed in by using $this->vars:

echo esc_html( $this->vars['my_variable'] );

Advanced Usage

The get_extended_template_part() function also accepts a second optional parameter that controls the directory name and caching.

The following code will load foo-bar.php from the my-directory subdirectory and automatically cache its output in a transient for one hour:

get_extended_template_part( 'foo', 'bar', [
	'my_variable' => 'Hello, world!',
], [
	'dir'   => 'my-directory',
	'cache' => 1 * HOUR_IN_SECONDS,
] );

License: GPLv2 or later

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

More Repositories

1

query-monitor

The developer tools panel for WordPress
PHP
1,580
star
2

extended-cpts

A library which provides extended functionality to WordPress custom post types and taxonomies.
PHP
971
star
3

wp_mail

Documentation for all the situations where WordPress core sends an email, how and when they happen, and how to filter or disable each one.
344
star
4

wp-crontrol

Take control of the cron events on your WordPress website
PHP
208
star
5

user-switching

WordPress plugin that provides instant switching between user accounts.
PHP
185
star
6

wp-json-schemas

JSON schemas for WordPress PHP objects and REST API responses
TypeScript
139
star
7

args

Array arguments made bearable
PHP
107
star
8

extended-taxos

PHP
100
star
9

ext

WP-CLI command which checks the existence of PHP extensions needed to run WordPress.
PHP
71
star
10

wp-types

TypeScript definitions for WordPress PHP objects and REST API responses
27
star
11

php-docs-standards

PHPUnit tests for documentation standards of PHP functions and methods.
PHP
24
star
12

wordpress-keyboard-shortcuts

A WordPress plugin which adds keyboard shortcuts for navigation and actions
PHP
23
star
13

wordpress-x

The most powerful and smartest admin toolbar ever in a CMS.
PHP
18
star
14

probot-semver

A GitHub app that provides automatic semantic versioning support
JavaScript
15
star
15

plugin-infrastructure

Reusable infrastructure relating to testing, building, and deploying my WordPress plugins
Shell
13
star
16

user-switching-for-regular-admins

Adds support to the User Switching plugin for regular admins on multisite
PHP
11
star
17

vip-go-indicator

Adds an admin toolbar indicator which identifies the current WordPress.com VIP Go environment
PHP
9
star
18

ideas

Ideas for things that I'll build just as soon as I find the time
8
star
19

global-post-password

WordPress plugin to globally set a password for all password protected posts and pages
PHP
8
star
20

revisions-digest

A WordPress plugin which generates digests of changes to content via their revisions.
PHP
7
star
21

plugin-info

Provides a simple way of displaying up-to-date information about specific WordPress Plugin Directory hosted plugins in your blog posts and pages.
PHP
7
star
22

falsey-assertequals-detector

Marks a PHPUnit test as risky if it tests a falsey value with assertEquals()
PHP
7
star
23

wp-git-status

WordPress plugin that shows the Git branch and current status in the admin toolbar
PHP
6
star
24

extended-widgets

PHP
5
star
25

wctrn-login-lockdown

Login Lockdown plugin for the WordCamp Torino 2018 WP-CLI workshop
PHP
4
star
26

wp-stats

HTML
4
star
27

https-indicator

PHP
3
star
28

php-errors

PHP error handling tests
PHP
3
star
29

slurpetta

Slurps down the most popular plugins and themes from WordPress.org
PHP
3
star
30

wp-contributors-map

A Node.js server for generating a GeoJSON file of contributors to WordPress.
JavaScript
3
star
31

wctrn-site-setup-script

Site setup script for the WordCamp Torino 2018 WP-CLI workshop
Shell
3
star
32

user-switching-duo-security

User Switching add-on plugin so it plays nicely with Duo Security
PHP
3
star
33

PrettyFilters

A proof-of-concept WordPress plugin which adds a much nicer interface to the filters on post listing screens
PHP
3
star
34

qm-self-awareness

Self-profiling plugin for Query Monitor.
PHP
3
star
35

gitattributes-globs

Parse a .gitattributes file and return its export-ignore entries as an array of glob patterns.
JavaScript
2
star
36

resource-host-monitor

PHP
1
star
37

ssl-helper

PHP
1
star
38

.github

1
star
39

johnbillion

1
star