Open isaumya opened 4 years ago
I have a development branch that starts to add this functionality:
https://github.com/benhuson/wp-subtitle/tree/feature/term
You may download that and tests if it suits your needs. It will be integrated into the main plugin after further testing.
Use the API function to add term subtitle to your template files as detailed at the top of this file but use the action/filter ‘plugins/wp_subtitle/the_term_subtitle’ and ‘plugins/wp_subtitle/get_term_subtitle’.
https://github.com/benhuson/wp-subtitle/blob/feature/term/plugin/includes/class-api.php
Can it be used in a production site?
See PR #51
I am using it in several production sites, so when I add it to the core plugin it will use the same API calls:
// Example: Display subtitle for a term
do_action( 'plugins/wp_subtitle/the_term_subtitle', array(
'before' => '<p class="subtitle">', // Before subtitle HTML output (default empty string)
'after' => '</p>', // After subtitle HTML output (default empty string)
'term_id' => {insert term id}, // Term ID
'default_value' => '' // Default output (if no subtitle)
) );
// Example: Get subtitle display
$subtitle = apply_filters( 'plugins/wp_subtitle/get_term_subtitle', '', array(
'before' => '<p class="subtitle">', // Before subtitle HTML output (default empty string)
'after' => '</p>', // After subtitle HTML output (default empty string)
'term_id' => {insert term id} // Term ID
) );
So to show as the main subtitle on a category/term page you could use:
do_action( 'plugins/wp_subtitle/the_term_subtitle', array(
'before' => '<p class="subtitle">',
'after' => '</p>',
'term_id' => get_queried_object_id()
) );
In all likelihood, these changes will be in the next release of the plugin, although check the changelog when the plugin is release just to make sure.
Edit:
Also now added API for displaying subtitle on relevant archive pages (ie. category, tag, term):
// Example: Display archive subtitle
do_action( 'plugins/wp_subtitle/the_archive_subtitle', array(
'before' => '<p class="subtitle">', // Before subtitle HTML output (default empty string)
'after' => '</p>', // After subtitle HTML output (default empty string)
'default_value' => '' // Default output (if no subtitle)
) );
// Example: Get archive subtitle display
$subtitle = apply_filters( 'plugins/wp_subtitle/get_archive_subtitle', '', array(
'before' => '<p class="subtitle">', // Before subtitle HTML output (default empty string)
'after' => '</p>', // After subtitle HTML output (default empty string)
) );
Just re-reading the title of this issue, did you mean display a post subtitle against each post on an archive page, or allow terms to have subtitles so you could show a term subtitle at the top of a terms page?
@benhuson What I mentioned in the post title is that let's say you have a default archive.php
which shows your default archive and taxonomy, like post archive, post tags etc.
Now you can also create your own APT which can also have archive pages to let's say show all of the stuff in your CPT. Now in all of these archive pages when you call the_title()
it shows up the title but as these archive & taxonomy page don't have a proper backend to add subtitle.
Let's say you have a CPT called Portfolio
. Inside your register CPT you have done has_archive => true
and sulg => portfolio
now when anyone visit example.com/portfolio
it will execute the archive.php
to show the CPT archive. Now let's say you have modified that archive.php
file to show your portfolio items. But again on that page you only have a title but no subtitle. That's what I was talking about.
The do_action( 'plugins/wp_subtitle/the_archive_subtitle' )
API I have added will output subtitles on category, tax and taxonomy pages, where you can add a subtitle via the admin.
Post Types don't currently have an admin UI for editing subtitles, so for now you would have to add them via code. eg.
function my_post_type_archive_subtitle( $title, $args ) {
if ( is_post_type_archive( 'my_post_type' ) ) {
$title = 'My post type archive subtitle';
}
return $args['before'] . $title . $args['after'];
}
add_filter( 'plugins/wp_subtitle/get_archive_subtitle', 'my_post_type_archive_subtitle', 11, 2 );
Hi, is there a possibility to add custom subtitle to the archive & taxonomy pages?