Limit number of Tags (Plugin)

Post Reply
neogeo
Ssr. Bludit
Posts: 11
Joined: Tue Sep 29, 2015 7:06 pm
Been thanked: 1 time

Someone knows how I could limit the numbers of Tags showed in Plugin Tags from Sidebar ?

I would like to show 10 tags, instead of showing all Tags.

Code from: bl-plugins/tags/plugin.php

Code: Select all

<?php

class pluginTags extends Plugin {

	public function init()
	{
		$this->dbFields = array(
			'label'=>'Tags'
		);
	}

	public function form()
	{
		global $L;

		$html  = '<div class="alert alert-primary" role="alert">';
		$html .= $this->description();
		$html .= '</div>';

		$html .= '<div>';
		$html .= '<label>'.$L->get('Label').'</label>';
		$html .= '<input id="jslabel" name="label" type="text" value="'.$this->getValue('label').'">';
		$html .= '<span class="tip">'.$L->get('This title is almost always used in the sidebar of the site').'</span>';
		$html .= '</div>';

		return $html;
	}

	public function siteSidebar()
	{
		global $L;
		global $tags;
		global $url;

		$filter = $url->filters('tag');

		$html  = '<div class="plugin plugin-tags">';
		$html .= '<h2 class="plugin-label">'.$this->getValue('label').'</h2>';
		$html .= '<div class="plugin-content">';
		$html .= '<ul>';

		// By default the database of tags are alphanumeric sorted
		foreach( $tags->db as $key=>$fields ) {
			$html .= '<li>';
			$html .= '<a href="'.DOMAIN_TAGS.$key.'">';
			$html .= $fields['name'];
			$html .= '</a>';
			$html .= '</li>';
		}

		$html .= '</ul>';
 		$html .= '</div>';
 		$html .= '</div>';

		return $html;
	}
}
Last edited by neogeo on Mon Jun 03, 2024 12:07 am, edited 2 times in total.
User avatar
Misteric
Ssr. Bludit
Posts: 18
Joined: Mon Aug 08, 2022 2:55 pm
Has thanked: 9 times
Been thanked: 6 times

You count the numb_tags and break the foreach loop.

Code: Select all

// By default the database of tags are alphanumeric sorted

$numb_tags = 0;

		foreach( $tags->db as $key=>$fields ) {
		
			$html .= '<li>';
			$html .= '<a href="'.DOMAIN_TAGS.$key.'">';
			$html .= $fields['name'];
			$html .= '</a>';
			$html .= '</li>';
			
			$numb_tags++;
				
			if ($numb_tags > 10) {
   				break;       
			}
		}
neogeo
Ssr. Bludit
Posts: 11
Joined: Tue Sep 29, 2015 7:06 pm
Been thanked: 1 time

.
Last edited by neogeo on Sat Jun 08, 2024 2:22 pm, edited 10 times in total.
User avatar
Misteric
Ssr. Bludit
Posts: 18
Joined: Mon Aug 08, 2022 2:55 pm
Has thanked: 9 times
Been thanked: 6 times

You can use this:

Code: Select all

// By default the database of tags are alphanumeric sorted

		foreach( $tags->db as $key=>$fields ) {
			for( $numb_tags = 0; $numb_tags < 10; $numb_tags++ ) { 
				$html .= '<li>';
				$html .= '<a href="'.DOMAIN_TAGS.$key.'">';
				$html .= $fields['name'];
				$html .= '</a>';
				$html .= '</li>';
			}
		}
neogeo
Ssr. Bludit
Posts: 11
Joined: Tue Sep 29, 2015 7:06 pm
Been thanked: 1 time

Misteric wrote: Sat Jun 01, 2024 7:31 pm You count the numb_tags and break the foreach loop.

Code: Select all

// By default the database of tags are alphanumeric sorted

$numb_tags = 0;

		foreach( $tags->db as $key=>$fields ) {
		
			$html .= '<li>';
			$html .= '<a href="'.DOMAIN_TAGS.$key.'">';
			$html .= $fields['name'];
			$html .= '</a>';
			$html .= '</li>';
			
			$numb_tags++;
				
			if ($numb_tags > 10) {
   				break;       
			}
		}
Thank you! this works!
Post Reply