Chapter
in package
Define cookbook chapters functionality.
- Provide methods to return posts and recipes in taxonomy.
- Provide a grid of chapter cards.
Tags
Table of Contents
Constants
- DEFAULT_CHAPTER_GRID_ATTS = array( 'action' => '', 'childless' => true, 'hide_empty' => true, 'meta_key' => '', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key 'order' => 'ASC', 'orderby' => 'preferred', 'parent' => '', 'taxonomy' => '', )
- Chapter grid attributes.
- DEFAULT_CHAPTER_POST_ARGS = array('tid' => 0, 'order' => 'ASC', 'orderby' => 'name')
- Chapter post default selection attributes.
- TAX_EXCERPT_KEY = 'pnet_excerpt'
- Define taxonomy term excerpt key name.
- TAX_IMAGE_KEY = 'pnet_image_id'
- Define taxonomy image key name.
- TAX_SEQUENCE_KEY = 'pnet_sequence'
- Define taxonomy term preferred sequence key name.
Properties
- $chapters : Chapters
- The instance of the Chapters class.
- $instances : array<string|int, object>
- The array of instances of this class and sub-classes.
- $taxonomy : Taxonomy
- The instance of the taxonomy class.
- $term : Term
- The instance of the Term class.
Methods
- get_chapters() : array<string|int, mixed>
- Get chapters in slug sequence.
- get_data() : array<string|int, mixed>
- Return the chapter metadata.
- get_instance() : object
- Creates and/or returns the instance of this class.
- get_post_ids() : array<string|int, int>
- Get post_ids in a chapter.
- get_posts() : array<string|int, mixed>
- Get posts in a chapter.
- get_recipe_ids() : array<string|int, int>
- Get recipe ids in a chapter.
- render_grid() : void
- Render the grid of chapter cards.
- __construct() : void
- Initialise the class and set its properties.
- get_chapter_cards() : string
- Return chapter cards.
- set_post_order() : array<string|int, mixed>
- Override the display order within some chapters.
Constants
DEFAULT_CHAPTER_GRID_ATTS
Chapter grid attributes.
protected
array<string|int, mixed>
DEFAULT_CHAPTER_GRID_ATTS
= array(
'action' => '',
'childless' => true,
'hide_empty' => true,
'meta_key' => '',
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
'order' => 'ASC',
'orderby' => 'preferred',
'parent' => '',
'taxonomy' => '',
)
- Set some sane defaults.
{ Default settings for the chapter grid display. @type string $action The action to take when card is clicked. @type bool $childless Flag to indicate whewhether to return chapers with no children. Default true. @type bool $hide_empty Flag to indicate whether to hide chapters with no posts. Default true. @type string $meta_key The meta key to use for ordering. @type string $order The chapter sort order. Defaults to ascending. @type string $orderby The chapter sort key. Defaults to the preferred sequence, set in the taxonomy. @type string $parent The top level item to restrict items by. @type string $taxonomy The taxonomy to get the chapters from. }
Tags
DEFAULT_CHAPTER_POST_ARGS
Chapter post default selection attributes.
protected
array<string|int, mixed>
DEFAULT_CHAPTER_POST_ARGS
= array('tid' => 0, 'order' => 'ASC', 'orderby' => 'name')
{ Default settings for the chapter post selection. @type int|string $tid The term id of the chapter to use. @type string $order The post sort order. @type string $orderby The posts sort key. }
Tags
TAX_EXCERPT_KEY
Define taxonomy term excerpt key name.
protected
string
TAX_EXCERPT_KEY
= 'pnet_excerpt'
Tags
TAX_IMAGE_KEY
Define taxonomy image key name.
protected
string
TAX_IMAGE_KEY
= 'pnet_image_id'
Tags
TAX_SEQUENCE_KEY
Define taxonomy term preferred sequence key name.
protected
array<string|int, mixed>
TAX_SEQUENCE_KEY
= 'pnet_sequence'
Tags
Properties
$chapters
The instance of the Chapters class.
protected
Chapters
$chapters
Tags
$instances
The array of instances of this class and sub-classes.
protected
static array<string|int, object>
$instances
= array()
Tags
$taxonomy
The instance of the taxonomy class.
protected
Taxonomy
$taxonomy
Tags
$term
The instance of the Term class.
protected
Term
$term
Tags
Methods
get_chapters()
Get chapters in slug sequence.
public
get_chapters([array<string|int, mixed> $args = array() ]) : array<string|int, mixed>
Parameters
- $args : array<string|int, mixed> = array()
-
The chapter request arguments.
Tags
Return values
array<string|int, mixed> —An array of chapter terms.
get_data()
Return the chapter metadata.
public
get_data([int|string $chapter_id = 0 ]) : array<string|int, mixed>
Parameters
- $chapter_id : int|string = 0
-
The chapter id to use.
Tags
Return values
array<string|int, mixed> —The chapter term data and metadata.
get_instance()
Creates and/or returns the instance of this class.
public
static get_instance() : object
Tags
Return values
object —The instance of this class.
get_post_ids()
Get post_ids in a chapter.
public
get_post_ids([int $chapter_id = 0 ]) : array<string|int, int>
Parameters
- $chapter_id : int = 0
-
The chapter id to search. If empty return all recipe chapters.
Tags
Return values
array<string|int, int> —The post ids within the chapter in slug sequence.
get_posts()
Get posts in a chapter.
public
get_posts([array<string|int, mixed> $args = array() ]) : array<string|int, mixed>
Parameters
- $args : array<string|int, mixed> = array()
-
The chapter post selection criteria.
Tags
Return values
array<string|int, mixed> —An array of post objects within the chapter in required sequence.
get_recipe_ids()
Get recipe ids in a chapter.
public
get_recipe_ids([int $chapter_id = 0 ]) : array<string|int, int>
Parameters
- $chapter_id : int = 0
-
The chapter id to search. If empty return all recipe chapters.
Tags
Return values
array<string|int, int> —The recipe ids within the chapter in slug sequence.
render_grid()
Render the grid of chapter cards.
public
render_grid([array<string|int, mixed> $args = array() ]) : void
Parameters
- $args : array<string|int, mixed> = array()
-
The arguments sent by the shortcode.
Tags
__construct()
Initialise the class and set its properties.
protected
__construct() : void
Tags
get_chapter_cards()
Return chapter cards.
protected
get_chapter_cards(array<string|int, mixed> $atts) : string
Parameters
- $atts : array<string|int, mixed>
-
The display attributes.
Tags
Return values
string —The chapter cards markup.
set_post_order()
Override the display order within some chapters.
protected
set_post_order(array<string|int, mixed> $qv, array<string|int, mixed> $args) : array<string|int, mixed>
Parameters
- $qv : array<string|int, mixed>
-
The query variables.
- $args : array<string|int, mixed>
-
The args given to the calling function.
Tags
Return values
array<string|int, mixed> —The modified query variables.