Page 1 of 1
Print tag or category name
Posted: Tue Apr 07, 2020 11:45 pm
by Gohh
Hello, I print a name depending on the category it is or the tag. The name of the category is printed, the name of the tag is not
Code: Select all
<h2>
<?php if ($WHERE_AM_I == 'category') : ?>
<?php $categoryKey = $url->slug();
$category = new Category($categoryKey);
echo $category->name(); ?>
<?php elseif ($WHERE_AM_I == 'tags') : ?>
<?php $tagKey = $Url->slug();
$tag = new Tag($tagKey);
echo $tag->name(); ?>
<?php endif ?>
</h2>
Re: Print tag or category name
Posted: Wed Apr 08, 2020 12:30 am
by Jay
There is no "tags" page, use "tag"
edit: without elseif
You can be either on a category page, or on a tag page.
Re: Print tag or category name
Posted: Wed Apr 08, 2020 7:40 am
by Gohh
Edited like this:
Code: Select all
<?php if ($WHERE_AM_I == 'category') : ?>
<?php $categoryKey = $url->slug();
$category = new Category($categoryKey);
echo $category->name(); ?>
<?php endif ?>
<?php if ($WHERE_AM_I == 'tag') : ?>
<?php $tagKey = $Url->slug();
$tag = new Tag($tagKey);
echo $tag->name(); ?>
<?php endif ?>
The fact is that when I insert "tag" instead of "tags" the tag page is not loaded. Can you somehow turn on the error show, what's the problem?
Re: Print tag or category name
Posted: Wed Apr 08, 2020 2:14 pm
by Jay
Ohh I just realized you are trying to use a snippet from bludit docs.
The mentioned exception to show code on a tag page works as supposed, as I had to make some small changes on my own bloggie couple days ago.
Right after I ended fixes I found this code in docs, and just of sheer curiosity I tried it out.
There are 2 typos in the snippet you use. First one I already mentioned, second one is in $tagKey = $Url->slug(); there should be a $url not $Url
ps. to enable php error reporting change define('DEBUG_MODE', FALSE); to TRUE in /kernel/boot/init.php
Re: Print tag or category name
Posted: Wed Apr 08, 2020 2:36 pm
by Gohh
Jay wrote: ↑Wed Apr 08, 2020 2:14 pm
Ohh I just realized you are trying to use a snippet from bludit docs.
The mentioned exception to show code on a tag page works as supposed, as I had to make some small changes on my own bloggie couple days ago.
Right after I ended fixes I found this code in docs, and just of sheer curiosity I tried it out.
There are 2 typos in the snippet you use. First one I already mentioned, second one is in $tagKey = $Url->slug(); there should be a $
url not $
Url
ps. to enable php error reporting change define('DEBUG_MODE', FALSE); to TRUE in /kernel/boot/init.php
Thank you, now works!
Code: Select all
<?php if ($WHERE_AM_I == 'tag') : ?>
<?php $tagKey = $url->slug();
$tag = new Tag($tagKey);
echo $tag->name(); ?>
<?php endif ?>
Re: Print tag or category name
Posted: Thu Apr 09, 2020 1:10 am
by Jay
Gohh wrote: ↑Wed Apr 08, 2020 2:36 pm
Thank you, now works!
Your'e welcome
I hope you wont eat your own teeth on this piece of software like I did
Re: Print tag or category name
Posted: Thu Apr 09, 2020 7:59 am
by Gohh
Jay wrote: ↑Thu Apr 09, 2020 1:10 am
Gohh wrote: ↑Wed Apr 08, 2020 2:36 pm
Thank you, now works!
Your'e welcome
I hope you wont eat your own teeth on this piece of software like I did
I didn't quite understand the point, but I'll be careful
Re: Print tag or category name
Posted: Sun Jan 14, 2024 2:17 am
by GracefulForm
I came across this and it was very helpful, thank you. To fill the space when a category or tag is not being shown, I added the option to use the word "Recent."
Code: Select all
<?php
// Check if the user is browsing a category
if ($WHERE_AM_I=='category') {
// Get the category key from the URL
$categoryKey = $url->slug();
// Create the Category-Object
$category = new Category($categoryKey);
// Print the category name
echo $category->name();
// Print the category description
echo $category->description();
}
// Check if the user is browsing a tag
elseif ($WHERE_AM_I=='tag') {
// Get the tag key from the URL
$tagKey = $url->slug();
// Create the Tag-Object
$tag = new Tag($tagKey);
// Print the tag name
echo $tag->name();
}
// Show this title if none of the other are being used
else {
echo "Recent";
}
?>