Topic: Multiple categories:Link to category

Hello,

to make a link to the categories i use this code in my template:

<div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'>{category}
</div>


Article | Categorie:1,3 | one link to 3,6


What can i do when the article have more categories, to have different links?


Article | Categorie:1,3 | first link to 3, second link to 6



Thanks for help.


Re: Multiple categories:Link to category

In which file the variables for the templates {category......}  defined?

Re: Multiple categories:Link to category

There are no templates for category, it is the function of the core (core/core.php).
But this problem can be solved with the help of a plugin. The code you can find below. Write in cdata/plugins any file with the code.
Use of the plugin. Add placeholders in the templates:
[cat-1] .... {catid} .... [/]
...
[cat-N] .... {catid} .... [/]

An example:

[cat-1]category, first[/]
[cat-2]category, second[/]


In case if there is a category 1 there will be the change of placeholder  [cat-1], inside of it there will be a number of a category for this placeholder {catid}. You can add it to the links.

<?php

add_hook('template_replacer_news_middle', 'my_template_replacer_news_middle_1');

function my_template_replacer_news_middle_1($q)
{
    list($o, $n) = $q;

    $cats = $n[NEW_CAT];
    $cats = spsep($cats);

    if (preg_match_all('/\[cat\-\d+\](.*?)\[\/\]/is', $o, $c, PREG_SET_ORDER))
    {
        foreach ($c as $v)
        {
            if (count($cats)) $catid = array_shift($cats); else $catid = FALSE;
            if ($catid !== FALSE) $d = str_replace('{catid}', $catid, $v[1]); else $d = '';
            $o = str_replace($v[0], $d, $o);
        }
    }

    return array($o, $n);
}
?>
Best regards,
CN Support team

Re: Multiple categories:Link to category

Support Team thanks for helping.

My solution:

core.php

     $multi_cat_link_arr = explode(",", $news_arr[NEW_CAT]);
     $multi_cat_arr = explode(",",hesc(catid2name($news_arr[NEW_CAT])));


//Artikel mit Multi Kategorien Links separieren
$i =-1;
    
    foreach($cat as $cat_arr) {
    $i++;            
    $output      = str_replace("{multi_cat_link[$i]}",    $multi_cat_link_arr[$i], $output);
    $output      = str_replace("{multi_cat[$i]}",         $multi_cat_arr[$i], $output);
    
    
    }

template

<div class ="kategorien_nav">Kategorie:  
[url=ategorien.php?category={multi_cat_link[0]}&>{multi_cat[0]}</a>
[url=a] {multi_cat[1]}[/url]
[url=a]{multi_cat[2]}[/url]
[url=a]{multi_cat[3]}[/url]
[url=a]{multi_cat[4]}[/url]
[url=a]{multi_cat[5]}[/url]
[url=a]{multi_cat[6]}[/url]
[url=a]{multi_cat[7]}[/url]
</div>

....cutenews 1.5.4 loops in templates :-)

My testpage: <a href=]strukturart.com/komma[/url]

Re: Multiple categories:Link to category

I used the plugin and the links to the categories work fine but how to get the names of the categories?

6 (edited by 2013-08-14 07:12:29)

Re: Multiple categories:Link to category

Try this:

core.php line 867

<div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'>   
     $multi_cat_link_arr = explode(",", $news_arr[NEW_CAT]);
     $multi_cat_arr = explode(",",hesc(catid2name($news_arr[NEW_CAT])));


//Artikel mit Multi Kategorien Links separieren
$i =-1;
   
    foreach($cat as $cat_arr) {
    $i++;           
    $output      = str_replace("{multi_cat_link[$i]}",    $multi_cat_link_arr[$i], $output);
    $output      = str_replace("{multi_cat[$i]}",         $multi_cat_arr[$i], $output);
   
   
    }</div>


e.g.  header.php


<div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'>
<div class="kategorie_list">
<?php

//NAVIGATION KATEGORIEN

//browserzeile auslesen   
$input=$_SERVER['REQUEST_URI'] ;

//Zwischen category - & Zeichen auslesen
preg_match('/category=(.*?)&/', $input, $ausgabe);


$output = explode (",",$ausgabe[1]);




$cats = file("cutenews/cdata/category.db.php");
   
$ausschuss = array(16,17,18,19,20);



foreach($cats as $cat_line)
{
   
   
      $cat_line_arr = explode("|", $cat_line);
   
            $fetchcat = $cat_line_arr[1];
            //Kategorien ausschliessen
           
           
          if(!in_array($cat_line_arr[0], $ausschuss)){
              //aktive Kategorie stylen
              if(in_array($cat_line_arr[0], $output)){
             $cat_list =" * $cat_line_arr[1]
";
             echo $cat_list;}
             else{
                
                  $cat_list =" * $cat_line_arr[1]
";
             echo $cat_list;
             }
         
          }

}
?>
</div>
</div>

Re: Multiple categories:Link to category

Thank you but I think this is not what I meant. It lists all of the categories with links to them right? I used the template from your first post now that you specified where to paste your code (I used Support_Team's plugin before) and it works fine but there are two more things. Is there a possibility to put a comma between the names of the categories so that it appears only when it is necessary? Every article on my website has a different number of categories so I can't simply put the commas into the template. second thing: the first page of the articles in a specific category looks fine but when I go to the second page it shows articles from all the categories. the url is index.php?start_from=20&ucat=5 and I think it should be index.php?category=5&start_from=20 is there any way to fix this?

Re: Multiple categories:Link to category

Send me the link of your Webpage.

Re: Multiple categories:Link to category

http://naughty-bee.net/english/

for now I used your code only in the full story template