Print tag or category name

Post Reply
Gohh
Ssr. Bludit
Posts: 11
Joined: Fri Aug 23, 2019 11:32 pm

Tue Apr 07, 2020 11:45 pm

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>
User avatar
Jay
Master Bludit
Posts: 106
Joined: Mon Feb 11, 2019 8:41 pm

Wed Apr 08, 2020 12:30 am

Code: Select all

($WHERE_AM_I == 'tags')
There is no "tags" page, use "tag" ;)

edit: without elseif
You can be either on a category page, or on a tag page.
Gohh
Ssr. Bludit
Posts: 11
Joined: Fri Aug 23, 2019 11:32 pm

Wed Apr 08, 2020 7:40 am

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?
User avatar
Jay
Master Bludit
Posts: 106
Joined: Mon Feb 11, 2019 8:41 pm

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
Gohh
Ssr. Bludit
Posts: 11
Joined: Fri Aug 23, 2019 11:32 pm

Wed Apr 08, 2020 2:36 pm

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 ?>
User avatar
Jay
Master Bludit
Posts: 106
Joined: Mon Feb 11, 2019 8:41 pm

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 ;)
Gohh
Ssr. Bludit
Posts: 11
Joined: Fri Aug 23, 2019 11:32 pm

Thu Apr 09, 2020 7:59 am

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 :D
Post Reply