How to get blog slug name?

Post Reply
kocritz
Jr. Bludit
Posts: 2
Joined: Wed Sep 13, 2023 2:02 am
Has thanked: 1 time
Been thanked: 1 time

Hello,

I'm developing a theme, and I want to automatically add blog menu/link (if home is a static page) to the navigation bar.

So far what I got is $site->uriFilters('blog') will get the blog URL.

But I still can't find the way to get the slug name.

For example, the slug being inputted is /stories/ or /articles/ or anything else.

How to get this slug name?

Thank you.
User avatar
CCDzine
Ssr. Bludit
Posts: 10
Joined: Thu Sep 07, 2023 11:49 pm
Location: Sierra Nevada Mountains, Califonia
Has thanked: 3 times
Been thanked: 6 times
Contact:

Try getting the field value.

Code: Select all

$site->getField( 'uriBlog' );
.

This is what I do to use the slug as the menu entry...

Code: Select all

$blog_uri = $site->getField( 'uriBlog' );

if ( ! empty( $blog_uri ) ) {

	// Use sprintf() if you need to echo later.
	printf(
		'<li><a href="%s">%s</a></li>',
		$site->url() . str_replace( '/', '', $blog_uri ) . '/',
		ucwords( str_replace( [ '/', '-', '_' ], ' ', $blog_uri ) )
	);
}
Greg Sweet
kocritz
Jr. Bludit
Posts: 2
Joined: Wed Sep 13, 2023 2:02 am
Has thanked: 1 time
Been thanked: 1 time

Splendid. Thank you very much. Never thought can be achieved this way. So much better.
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

Thank you for the workaround! This is an older problem that has never been fixed. ;)
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
User avatar
Romeo21
Ssr. Bludit
Posts: 10
Joined: Fri Nov 25, 2022 7:00 pm
Been thanked: 3 times

Thanks, never knew how to solve it!
Post Reply