Page 1 of 1

Tags By Letter

Posted: Sun Nov 22, 2020 2:35 am
by antzweb
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

Re: Tags By Letter

Posted: Sun Nov 22, 2020 4:37 pm
by Jay
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;
}	

Re: Tags By Letter

Posted: Sun Nov 22, 2020 9:36 pm
by antzweb
Perfect! thank you very much