mentormate / template-part-args

一个方便的WordPress库,用于获取带有裁剪选项的图像src。

1.0 2017-11-21 10:12 UTC

This package is not auto-updated.

Last update: 2024-09-20 02:36:24 UTC


README

这是一个替代原生WordPress函数 get_template_part 的选择,允许向模板部分传递任意参数。

如何使用

插件暴露了两个模板函数 - get_template_part_argsget_template_part_vars。前者用于替代 get_template_part,即传递参数,后者用于在模板部分中检索它们。

以下是一个示例

// Anywhere in your theme templates
get_template_part_args( 'template', 'part', [ 'example_argument' => true ] ); 
// in template-part.php

// define defaults
$defaults = [
	'example_argument' => false,
];

// combine defaults with passed args
$args = wp_parse_args( get_template_part_vars( $this ), $defaults );