Dotclear

Vous n'êtes pas identifié(e).

Annonce

13 février 2024 Sortie de Dotclear 2.29

#26 2009-04-25 12:51:33

i_love_dc
Membre
Inscription : 2007-07-13

Re : tpl:Categories + tpl:LoopPosition + tpl:Entries category !!

voici le code complet du public.php

<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of Dotclear 2.
#
# Copyright (c) 2003-2008 Olivier Meunier and contributors
# Licensed under the GPL version 2.0 license.
# See LICENSE file or
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { return; }

# Surcharge CategoryIf
$GLOBALS['core']->tpl->addValue('MyCategoryIf',array('tplMytpl','MyCategoryIf'));
	
class tplMytpl
{
	/*dtd
	<!ELEMENT tpl:CategoryIf - - -- tests on current entry -->
	<!ATTLIST tpl:CategoryIf
	url		CDATA	#IMPLIED	-- category has given url
	has_entries	(0|1)	#IMPLIED	-- post is the first post from list (value : 1) or not (value : 0)
	>
	*/
	public static function MyCategoryIf($attr,$content)
	{
		$if = array();
		$operator = isset($attr['operator']) ? self::getOperator($attr['operator']) : '&&';
		
		if (isset($attr['url'])) {
			$compar_cat_op = '==';
			$url = addslashes(trim($attr['url']));
			if (substr($url,0,1) == '!') {
				$url = substr($url,1);
				$compar_cat_op = '!=';
			}
			$urls = explode(",", $url);
			
			foreach ($urls as $k => $url)
			{
				$if[] = '($_ctx->categories->cat_url '.$compar_cat_op.' "'.$url.'")';
			}
		}
		
		if (isset($attr['has_entries'])) {
			$sign = (boolean) $attr['has_entries'] ? '>' : '==';
			$if[] = '$_ctx->categories->nb_post '.$sign.' 0';
		}
		
		if (!empty($if)) {
			return '<?php if('.implode(' '.$operator.' ',$if).') : ?>'.$content.'<?php endif; ?>';
		} else {
			return $content;
		}
	}
	
	protected function getOperator($op)
	{
		switch (strtolower($op))
		{
			case 'or':
			case '||':
				return '||';
			case 'and':
			case '&&':
			default:
				return '&&';
		}
	}	
}
?>
<?php
$core->tpl->addValue('ScrollDownLink',array('tplKatzenjammer','ScrollDownLink'));
$core->tpl->addValue('ScrollAnchor',array('tplKatzenjammer','ScrollAnchor'));

class tplKatzenjammer
{
	/*
	Cette fonction  crée un lien qui défile vers le prochain article
	Utilisation : {{tpl:ScrollDownLink}}
	*/
	public static function ScrollDownLink($attr)
	{
		
		$f = $GLOBALS['core']->tpl->getFilters($attr);

		
		$res = 
		'<?php echo "<div class=\"scroller\">"; ?>'.
		'<?php echo "<a href=\"#item-"; ?>'.
		'<?php echo $_ctx->posts->post_id; ?>'.
		'<?php echo "\">"; ?>'.
		'<?php echo "<img src=\""; ?>'.
		'<?php echo '.sprintf($f,'$core->blog->settings->themes_url."/".$core->blog->settings->theme').'; ?>'.
		'<?php echo "/img/down.gif\" alt=\"Scroll down\" />"; ?>'.
		'<?php echo "</a>"; ?>'.
		'<?php echo "</div>"; ?>';
		
		return $res;
	}

	
	/*
	Cette fonction crée une ancre au nom de l'id de l'article
	Utilisation : {{tpl:ScrollAnchor}}
	*/
	public static function ScrollAnchor($attr)
	{
		return '
		<?php 
			$res = \'<a name="item-\'.$_ctx->posts->post_id.\'"></a> \';
			echo $res;
		?>';	
	}

}

?>

le code contient en premier lieux ta fonction "CategoryIf" puis la fonction "scroll" du thème de ansso

Hors ligne

#27 2009-04-25 14:43:52

i_love_dc
Membre
Inscription : 2007-07-13

Re : tpl:Categories + tpl:LoopPosition + tpl:Entries category !!

heu...et si au lieu d'exclure quelques catégories...
pour éviter un tas de problèmes, ne devrais-je pas plutôt prendre le problème à l'envers et donner uniquement quelques catégories choisies dans la boucle ??

est-ce possible ?
et comment si prendre dans s'cas?

Hors ligne

#28 2009-04-25 20:35:23

liopil
Membre
Lieu : Pontivy
Inscription : 2008-11-10

Re : tpl:Categories + tpl:LoopPosition + tpl:Entries category !!

Est-ce qu'il ne faudrait pas écrire url="!cat-1,!cat-2" au lieu de url="!cat-1,cat-2", avec un point d'exclamation devant chaque catégorie à tester ?

Hors ligne

#29 2009-04-25 21:41:56

adjaya
Membre
Lieu : Provence - Luberon
Inscription : 2006-09-05
Site Web

Re : tpl:Categories + tpl:LoopPosition + tpl:Entries category !!

i-love_dc > dans ton fichier _public.php y'a deux ligne en trop :

?>
<?php

Pour filtrer sur un choix de categories à afficher c'est url="cat-1,cat-2", pour exclure c'est url="!cat-1,cat-2".
liopil > non


Photo, Art et Création Numérique : http://benoit-grelier.photo7.fr/

Hors ligne

#30 2009-04-25 22:33:59

i_love_dc
Membre
Inscription : 2007-07-13

Re : tpl:Categories + tpl:LoopPosition + tpl:Entries category !!

Voici mon _public.php

<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of Dotclear 2.
#
# Copyright (c) 2003-2008 Olivier Meunier and contributors
# Licensed under the GPL version 2.0 license.
# See LICENSE file or
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { return; }

# Surcharge CategoryIf
$GLOBALS['core']->tpl->addValue('MyCategoryIf',array('tplMytpl','MyCategoryIf'));
	
class tplMytpl
{
	/*dtd
	<!ELEMENT tpl:CategoryIf - - -- tests on current entry -->
	<!ATTLIST tpl:CategoryIf
	url		CDATA	#IMPLIED	-- category has given url
	has_entries	(0|1)	#IMPLIED	-- post is the first post from list (value : 1) or not (value : 0)
	>
	*/
	public static function MyCategoryIf($attr,$content)
	{
		$if = array();
		$operator = isset($attr['operator']) ? self::getOperator($attr['operator']) : '&&';
		
		if (isset($attr['url'])) {
			$compar_cat_op = '==';
			$url = addslashes(trim($attr['url']));
			if (substr($url,0,1) == '!') {
				$url = substr($url,1);
				$compar_cat_op = '!=';
			}
			$urls = explode(",", $url);
			
			foreach ($urls as $k => $url)
			{
				$if[] = '($_ctx->categories->cat_url '.$compar_cat_op.' "'.$url.'")';
			}
		}
		
		if (isset($attr['has_entries'])) {
			$sign = (boolean) $attr['has_entries'] ? '>' : '==';
			$if[] = '$_ctx->categories->nb_post '.$sign.' 0';
		}
		
		if (!empty($if)) {
			return '<?php if('.implode(' '.$operator.' ',$if).') : ?>'.$content.'<?php endif; ?>';
		} else {
			return $content;
		}
	}
	
	protected function getOperator($op)
	{
		switch (strtolower($op))
		{
			case 'or':
			case '||':
				return '||';
			case 'and':
			case '&&':
			default:
				return '&&';
		}
	}	
}

$core->tpl->addValue('ScrollDownLink',array('tplKatzenjammer','ScrollDownLink'));
$core->tpl->addValue('ScrollAnchor',array('tplKatzenjammer','ScrollAnchor'));

class tplKatzenjammer
{
	/*
	Cette fonction  crée un lien qui défile vers le prochain article
	Utilisation : {{tpl:ScrollDownLink}}
	*/
	public static function ScrollDownLink($attr)
	{
		
		$f = $GLOBALS['core']->tpl->getFilters($attr);

		
		$res = 
		'<?php echo "<div class=\"scroller\">"; ?>'.
		'<?php echo "<a href=\"#item-"; ?>'.
		'<?php echo $_ctx->posts->post_id; ?>'.
		'<?php echo "\">"; ?>'.
		'<?php echo "<img src=\""; ?>'.
		'<?php echo '.sprintf($f,'$core->blog->settings->themes_url."/".$core->blog->settings->theme').'; ?>'.
		'<?php echo "/img/down.gif\" alt=\"Scroll down\" />"; ?>'.
		'<?php echo "</a>"; ?>'.
		'<?php echo "</div>"; ?>';
		
		return $res;
	}

	
	/*
	Cette fonction crée une ancre au nom de l'id de l'article
	Utilisation : {{tpl:ScrollAnchor}}
	*/
	public static function ScrollAnchor($attr)
	{
		return '
		<?php 
			$res = \'<a name="item-\'.$_ctx->posts->post_id.\'"></a> \';
			echo $res;
		?>';	
	}

}

?>

et la boucle dans le tpl

<tpl:Categories level="1">
 <tpl:MyCategoryIf url="!Cat-1,Cat-2">
	<div>
     <tpl:Entries category="#self ?sub" lastn="1" no_context="1" ignore_pagination="1">           
      <h2 class="boucle-cat-title"><a href="{{tpl:EntryURL}}">{{tpl:EntryTitle encode_html="1"}}</a></h2>
      <div class="boucle-cat-excerpt">
	  <p>{{tpl:EntryExcerpt encode_html="1" remove_html="1" cut_string="90"}}
	 <br /> <a href="{{tpl:EntryURL}}" title="{{tpl:lang Continue reading}} {{tpl:EntryTitle encode_html="1"}}">
	  {{tpl:lang Continue reading}}...</a></p>
	  </div>   
     </tpl:Entries>
    </div>
  </tpl:MyCategoryIf>
</tpl:Categories>

j'espère ne plus me tromper, mais malgré ça, ça ne fonctionne toujours pas!

Hors ligne

#31 2009-06-09 15:22:52

i_love_dc
Membre
Inscription : 2007-07-13

Re : tpl:Categories + tpl:LoopPosition + tpl:Entries category !!

heu adjaya tu ne m'a pas mentionné ou étaient ses 2 ligne en trop

?>
<?php

Hors ligne

#32 2009-06-09 18:16:14

adjaya
Membre
Lieu : Provence - Luberon
Inscription : 2006-09-05
Site Web

Re : tpl:Categories + tpl:LoopPosition + tpl:Entries category !!

i_love_dc a écrit :

heu adjaya tu ne m'a pas mentionné ou étaient ses 2 ligne en trop

?>
<?php

Ben t'a trouvé tout seul, non :) ?
Pour la ligne :
<tpl:MyCategoryIf url="!Cat-1,Cat-2"> , il faut bien sûr remplacer Cat-1 et Cat-2 par l'url sécifique de tes catégories à exclure et que celles-ci soient de niveau 1 ( vu que tu le spécifie sur <tpl:Categories level="1"> .


Photo, Art et Création Numérique : http://benoit-grelier.photo7.fr/

Hors ligne

#33 2009-06-09 20:40:18

i_love_dc
Membre
Inscription : 2007-07-13

Re : tpl:Categories + tpl:LoopPosition + tpl:Entries category !!

Je viens de retenter le coup mais sans aucuns succès, je comprend vraiment pas!

je vais surement tenter autre chose mais...
y à t-il un exemple de boucle qui pourrait inclure sur le home les x billets de la page deux?
Exemple, cette boucle en sidebarre sur le home donnerait :
> Home = x billets de la page2
> Page2 =  x billets de la page3...etc..etc

avec un

<tpl:Entries><tpl:LoopPosition start"..." length"... ">    </tpl:LoopPosition></tpl:Entries>

peut être non?

Hors ligne

Vous n'êtes pas identifié(e).

Pied de page des forums

Sites map