Skip Navigation

[Resolved] How to Get a Title in my Category Archive

This support ticket is created 5 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 8 replies, has 3 voices.

Last updated by Minesh 5 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#1158482

I have created a custom wordpress archive for Post Categories. It works great. The problem is, I can't figure out how to put a title at the beginning of the page that tells which category the page is for. Here is my Loop Editor content:

[wpv-layout-start]
<h1>Category: [wpv-post-taxonomy type="category" format="name"]</h1>
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
<div class="ddm-episode-entry">
[wpv-post-body view_template="Loop item in Categories"]
</div>
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
<p class="ddm-not-found">No posts found in this category.</p>
[/wpv-no-items-found]
[wpv-layout-end]

The <h1> just before the [wpv-items-found] should display the title for the selected category. However, only the word "Category: " appears on the rendered page. How do I get the name of the selected category into the title section?

Thanks,

David McLeod

#1158510

I've done some research on this, but still don't have any idea how to solve the problem in Toolset.

In a standard WordPress template file (category.php, for example), I'd add the category title by doing something like this:

<p><?php single_cat_title('Category: '); ?>.</p>

Is there a way to add something like this to my Category archive in Toolset?

David

#1158541

Hello,

In the taxonomy archive page, you can get the current archive information by shortcode [wpv-taxonomy-archive], for example:

Archive for [wpv-taxonomy-archive info="name"]

More help:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-taxonomy-archive
This shortcode displays information about the current taxonomy (usable only for taxonomy queries).

#1159105

Great, that worked fine for both my Category Archive and my Tag Archive. However, when I tried to create an Author Archive, that method no longer works. I assume there is a different shortcode for getting the name of the selected author. Could you please tell me what that is?

Also, it would sure be helpful to know what other shortcodes are available, and also to have better searching in your documentation so that I can eventually find those shortcodes for myself.

Thanks,

David

#1159261

There isn't such a built-in shortcode for author archive page, as a workaround, you can try the custom shortcodes in another similar thread:
https://toolset.com/forums/topic/author-page-single/

If you need more assistance for it, please create a new ticket for it, thanks

#1164527

I don't think this problem was addressed correctly. Actually, the correct answer is to use [wpv-archive-title] for all of these cases--including the author archive page.

The only problem with this method is that it includes the prefix "Category:", "Tag:" or "Author:". The method does not allow for a more general approach.

I think Toolset should look into offering options for the [wpv-archive-title] shortcode.

David McLeod

#1164829

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Luo is on vacation. This is Minesh here and I'll take care of this ticket. Hope this is OK.

Well - as you see the [wpv-archive-title], its expected result its displaying the "Archive" word:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-archive-title

If you would like to get rid of the “Category:”, “Tag:”, “Author:”, “Archives:” and “Other taxonomy name:” in the archive title, use this little function in your (child) theme functions.php file:

function func_override_archive_title( $title ) {
    if ( is_category() ) {
        $title = single_cat_title( '', false );
    } elseif ( is_tag() ) {
        $title = single_tag_title( '', false );
    } elseif ( is_author() ) {
        $title = '<span class="vcard">' . get_the_author() . '</span>';
    } elseif ( is_post_type_archive() ) {
        $title = post_type_archive_title( '', false );
    } elseif ( is_tax() ) {
        $title = single_term_title( '', false );
    }
  
    return $title;
}
 add_filter( 'get_the_archive_title', 'func_override_archive_title' );

More info:
=> https://developer.wordpress.org/reference/functions/get_the_archive_title/

#1165036

This is definitely helpful, thank you!
However, I wonder if your [wpv-archive-title] shortcode could be modified to take some arguments? Obviously, you already make calls to existing WordPress functions, so this should not be a problem for you from a development standpoint.
I think that your short code could pretty easily be implemented in much the same way that you have done here, except that you should provide an additional argument, $prefix, which defaults to the empty string. Thus your shortcode could be implemented something like this:

function wpv_archive_title( $prefix = null ) {
    // Preserve your current default behavior
    if ($prefix == null || strlen($prefix ==0) {
       $title = get_the_archive_title();
    }
    else {  
      if ( is_category() ) {
          $title = $prefix . single_cat_title( '', false );
      } elseif ( is_tag() ) {
          $title = $prefix . single_tag_title( '', false );
      } elseif ( is_author() ) {
          $title = $prefix . '<span class="vcard">' . get_the_author() . '</span>';
      } elseif ( is_post_type_archive() ) {
          $title = $prefix . post_type_archive_title( '', false );
      } elseif ( is_tax() ) {
          $title = $prefix . single_term_title( '', false );
      }
    }
    return $title;
}

Would you please forward this to the development team as a feature request?
Thank you.
David McLeod

#1165329

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Sure. I'll spit the ticket here and send it to concern person who is handling the feature requests.

Please feel free to close this ticket.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.