Update CUSTOMIZE.md
This commit is contained in:
parent
5d881fbfbb
commit
6a19b476d1
37
CUSTOMIZE.md
37
CUSTOMIZE.md
@ -103,6 +103,43 @@ add_filter( 'fictioneer_filter_safe_title', 'child_modify_chapter_list_title', 1
|
||||
|
||||

|
||||
|
||||
### Add prefix to chapter index list titles
|
||||
|
||||
Or change them completely, if you want even depending on the chapter or associated story. Related to [this issue](https://github.com/Tetrakern/fictioneer/issues/31). Using a filter, you can rebuild the list item HTML to your liking, in this case just added the prefix if there is one.
|
||||
|
||||
**References**
|
||||
* Filter: [fictioneer_filter_chapter_list_item](https://github.com/Tetrakern/fictioneer/blob/main/FILTERS.md#apply_filters-fictioneer_filter_chapter_list_item-item-post-args-)
|
||||
* Include: [_helpers-templates.php](https://github.com/Tetrakern/fictioneer/blob/main/includes/functions/_helpers-templates.php)
|
||||
|
||||
```php
|
||||
/**
|
||||
* Overwrites the chapter list item string with a prefixed title
|
||||
*
|
||||
* @since x.x.x
|
||||
*
|
||||
* @param string $item Original HTML string
|
||||
* @param WP_Post $post Chapter post object.
|
||||
* @param array $args Array of chapter data.
|
||||
*
|
||||
* @return string New HTML list of list item.
|
||||
*/
|
||||
|
||||
function child_prefix_chapter_index_items( $item, $post, $args ) {
|
||||
$prefix = get_post_meta( $post->ID, 'fictioneer_chapter_prefix', true );
|
||||
|
||||
return sprintf(
|
||||
'<li class="%1$s" data-id="%2$s"><a href="%3$s">%4$s<span>%5$s%6$s</span></a></li>',
|
||||
implode( ' ', $args['classes'] ),
|
||||
$post->ID,
|
||||
get_the_permalink( $post->ID ),
|
||||
$args['icon'],
|
||||
$prefix ? $prefix . ' ' : '',
|
||||
$args['list_title'] ?: $args['title']
|
||||
);
|
||||
}
|
||||
add_filter( 'fictioneer_filter_chapter_list_item', 'child_prefix_chapter_index_items', 1, 3 );
|
||||
```
|
||||
|
||||
## Only show a specific advanced meta field
|
||||
|
||||
Maybe you want only one specific advanced meta field. You can achieve this by manually adding the desired field and saving procedure, similar to how it is done in the [_setup-meta-fields.php](https://github.com/Tetrakern/fictioneer/blob/main/includes/functions/_setup-meta-fields.php). The following example adds the Co-Authors field to stories, which can be adapted for chapters as well. Just make sure to change the {dynamic_parts} and the meta keys.
|
||||
|
Loading…
x
Reference in New Issue
Block a user