php - Using Tag Groups: Displaying groups and adjacent tags of current post

admin2025-01-07  4

I am trying to use tag groups (plugin) and tags as a way to display basic info on a portfolio/blog website's posts. I have organised them as *ex. Tag Group: Year / Tags: 2012, 2013, 2014... etc and tag each post with one tag from each group. What I want to display on a post/project page is Year: 2013, - display the name of the group and the adjacent tag for this post only.

So far, I have made a table and managed to display only adjacent tag groups, but I cannot filter the tag for the post. As an output I get "Group: All tags in it".

I am building the site myself and started with all web coding from zero a couple of months ago, so any help would be appreciated. I think that I miss a condition in the "foreach" function, but I am not sure at all.

This is the code:

$groups = tag_groups_cloud( array( 'groups_post_id' => '0', 'orderby' => 'count', 'order' => 'DESC' ) , true );

            <table>
            <tr>
                <?php if ( $groups ) foreach ( $groups as $group ): ?>
                    <th><?php echo $group['name'] ?></th>
                <?php endforeach; ?>
            </tr>
            <tr>
                <?php foreach ( $groups as $group ): ?>
                <td>
                    <ul>
                        <?php
                        foreach ($group['tags'] as $tag ):
                        ?>
                            <li>
                            <a href="<?php echo $tag['link'] ?>"><?php echo $tag['name'] ?></a></li>

                        <?php endforeach; ?>
                    </ul>
                </td>
                <?php endforeach; ?>
            </tr>
            </table>

I am trying to use tag groups (plugin) and tags as a way to display basic info on a portfolio/blog website's posts. I have organised them as *ex. Tag Group: Year / Tags: 2012, 2013, 2014... etc and tag each post with one tag from each group. What I want to display on a post/project page is Year: 2013, - display the name of the group and the adjacent tag for this post only.

So far, I have made a table and managed to display only adjacent tag groups, but I cannot filter the tag for the post. As an output I get "Group: All tags in it".

I am building the site myself and started with all web coding from zero a couple of months ago, so any help would be appreciated. I think that I miss a condition in the "foreach" function, but I am not sure at all.

This is the code:

$groups = tag_groups_cloud( array( 'groups_post_id' => '0', 'orderby' => 'count', 'order' => 'DESC' ) , true );

            <table>
            <tr>
                <?php if ( $groups ) foreach ( $groups as $group ): ?>
                    <th><?php echo $group['name'] ?></th>
                <?php endforeach; ?>
            </tr>
            <tr>
                <?php foreach ( $groups as $group ): ?>
                <td>
                    <ul>
                        <?php
                        foreach ($group['tags'] as $tag ):
                        ?>
                            <li>
                            <a href="<?php echo $tag['link'] ?>"><?php echo $tag['name'] ?></a></li>

                        <?php endforeach; ?>
                    </ul>
                </td>
                <?php endforeach; ?>
            </tr>
            </table>
Share Improve this question asked Apr 12, 2017 at 11:42 bonevbonev 12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

If I understood your request correctly, then you probably need a different parameter: tags_post_id

$groups = tag_groups_cloud( array( 'tags_post_id' => '0', 'orderby' => 'count', 'order' => 'DESC' ) , true );

I tried it and the output is only the tags of that post, but arranged in a table.

The parameter groups_post_id is used for selecting groups that are connected to the post, while tags_post_id selects the tags.

See the complete description of the parameters.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736254093a177.html

最新回复(0)