Get Tag Value from within a page.

Post Reply
User avatar
RobinSlee
Jr. Bludit
Posts: 5
Joined: Sat Aug 04, 2018 7:53 am

Sun Aug 05, 2018 4:28 am

Hi, I am sure this is going to be easy for you guys... But i am only just beginning to learn PHP so please bear with me. I am customizing a theme for my site and want to show the tags associated to this 'page'.

I currently have :

Code: Select all

<?php
    $tags = $page->tags(true);

    foreach ($tags as $tag) {
        echo 'Tag name: '   . $tag;
        // echo 'Tag key: '    . $tag->key();
        // echo 'Tag link: '   . $tag->permalink();
        // echo 'Tag amount of pages: ' . count($tag->pages());
    }
?>
which gives me:

Code: Select all

Tag name: Flower Tag name: Course 
How do I just get the 'key' part, or the 'permalink' part? I thought this was an instance of the class 'tag' with the accessible properties of 'key,permalink,name...' But I cannot get to the permalink, through the permalink() method.

Or, is this an array? Of strings?

Cheers for any help. Rob.
User avatar
Edi
Site Admin
Posts: 1261
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Contact:

Sun Aug 05, 2018 11:58 pm

You can find an example for this in the template home.php of the theme Log (line 54):

https://github.com/bludit-themes/log/bl ... p/home.php

For the permalink you can use instead of

Code: Select all

HTML_PATH_ROOT.$Url->filters('tag').'/'.$tagKey
the absolute path (see the plugin Tags):

Code: Select all

DOMAIN_TAGS.$tagKey
Planet Bludit, Tipps, Snippets und nützliche Links. - Newsletter, Informationen zu Bludit (auf Deutsch).
User avatar
RobinSlee
Jr. Bludit
Posts: 5
Joined: Sat Aug 04, 2018 7:53 am

Mon Aug 06, 2018 12:18 am

Thank you, it works. I was able to use the following code block (for anyone who wants it):

Code: Select all

<!-- Post's tags -->
<ul class="stats">
<?php
	$tags = $Page->tags(true);
	echo "Tags: ";
	foreach($tags as $tagKey=>$tagName) {
		echo '<li><a href="'.HTML_PATH_ROOT.$Url->filters('tag').'/'.$tagKey.'">'.$tagName.'</a></li>';
	}
?>
</ul>
I am not sure I fully understand what is happening here, so I will have to dig a little deeper. My lack of php knowledge is slowing me down. I am reading some books on the subject, so hopefully wont be too long, before I can give back to the community through a plugin or something.

Thank you. :-)
Post Reply