Tags By Letter

Post Reply
antzweb
Ssr. Bludit
Posts: 12
Joined: Mon Nov 16, 2020 3:26 pm

Hi Guys,
I was wondering if someone would kindly show me how I can display Tags by the letter eg:

Tag Names: David, john, neil, Donald

If I want to display tags beginning with D to just show Donald and David,or tags beginng with J to display John, how would I go on with this?

I've read the docs and found this code in which I believe lists all tags in the websit.

<?php
foreach ($tags->keys() as $key) {
// Create Tag-Object
$tag = new Tag($key);

echo '<p><a href="'.$tag->permalink().'">'.$tag->name().'</a></p>'. PHP_EOL;

}
?>
thanks
User avatar
Jay
Master Bludit
Posts: 133
Joined: Mon Feb 11, 2019 8:41 pm

Considering you don't have special chars as your first letter in tags, you can just add a simple conditional statement to show only tags starting with fixed letter

Code: Select all

if (strtolower($tag->name()[0]) == 'd')
{
	echo '<p><a href="'.$tag->permalink().'">'.$tag->name().'</a></p>'. PHP_EOL;
}	
antzweb
Ssr. Bludit
Posts: 12
Joined: Mon Nov 16, 2020 3:26 pm

Perfect! thank you very much
Post Reply