Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can Subtitle be added to the Archive & Taxonomy Pages? #50

Open
isaumya opened this issue Apr 15, 2020 · 6 comments
Open

Can Subtitle be added to the Archive & Taxonomy Pages? #50

isaumya opened this issue Apr 15, 2020 · 6 comments

Comments

@isaumya
Copy link

isaumya commented Apr 15, 2020

Hi,
is there a possibility to add custom subtitle to the archive & taxonomy pages?

@benhuson
Copy link
Owner

benhuson commented Apr 19, 2020

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

@isaumya
Copy link
Author

isaumya commented Apr 19, 2020

Can it be used in a production site?

@benhuson
Copy link
Owner

benhuson commented Apr 19, 2020

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)
) );

@benhuson
Copy link
Owner

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?

@isaumya
Copy link
Author

isaumya commented Apr 20, 2020

@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.

@benhuson
Copy link
Owner

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 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants