0

We have a blockcategories menu in Prestashop with about 400 categories total including all the subcategories, and this is creating too many links on each of our page, resulting in not-optimal onpage SEO.

I want to add rel="nofollow" and some Javascript to all links except the root and the selected category and it's children and siblings.

Example: - Subcategory A (Root, dofollow) - Subcategory A-1(Sibling of selected, dofollow) - Subcategory A-2 (Selected, dofollow) - Subcategory A-2-a (Child of selected, dofollow) - Subcategory A-2-b (Child of selected, dofollow) - Subcategory A-2-c (Child of selected, dofollow) - Subcategory A-3 (Sibling of selected, dofollow) - Subcategory B (Root, dofollow) - Subcategory B-1 (Nofollow) - Subcategory B-2 (Nofollow) - Subcategory B-2-a (Nofollow) - Subcategory B-2-b (Nofollow) - Subcategory B-3 (Nofollow) - Subcategory C (Root, dofollow) - Subcategory D (Root, dofollow)

I have been successful with Selecting the Root, the Selected and the Children of the selected. However I've been unsuccessful with selecting the Siblings of the selected (That share the same Parent).

How do I Select the Siblings of the Selected Category within the Blockcategories .tpl files?

4

3 回答 3

0

我遇到了非常相似的问题-我需要更改所选类别的所有兄弟姐妹的样式,因此解决方案是相同的

你需要修改 category-tree-branch.tpl

<li {if isset($last) && $last == 'true'}class="last"{/if}>
    {assign var="RET" value=""}
    {if $node.children|@count > 0}
        {foreach from=$node.children item=child name=categoryTreeBranch}
            {if $smarty.foreach.categoryTreeBranch.last}
                {include file="$branche_tpl_path" node=$child last='true' assign='childItems'}
            {else}
                {include file="$branche_tpl_path" node=$child last='false' assign='childItems'}
            {/if}
            {assign var="RET" value="{$RET}{$childItems}"}
        {/foreach}
    {/if}
    <a href="{$node.link|escape:'htmlall':'UTF-8'}" {if $RET|strpos:'selected'} class="parentselect"{/if}{if isset($currentCategoryId) && $node.id == $currentCategoryId}class="selected"{/if}
        title="{$node.desc|strip_tags|trim|escape:'htmlall':'UTF-8'}">{$node.name|escape:'htmlall':'UTF-8'}</a>
    {if $RET}<ul>{$RET}</ul>{/if}
</li>

您所需要的只是将您需要的任何内容放在活动分支之间...或更改未选择分支的{if $RET|strpos:'selected'}条件{\if}{if $RET|strpos:'selected'==false}

于 2014-03-10T00:19:54.660 回答
0

PrestaShop 使用嵌套集模型来存储其类别:

这使您可以轻松选择树的一部分(父母、孩子、兄弟姐妹等)。

每个“类别”对象都有一个nleftnright成员,可以帮助您执行这些选择。

另一种更简单的方法是使用level_depth成员,所有兄弟姐妹都将具有相同的 level_depth 值。

您可以修改blockcategories.php 文件,在hookLeftColumn() 的SELECT 语句中添加level_depth。然后在 category-tree-branch.tpl 文件中,简单的添加一个测试:

{if $node.level_depth == ....}rel="nofollow"{/if}

请注意,Google 可能不喜欢这样一个事实,即一个类别的某些页面是 nofollow 并且在其他页面上是 dofollow。

于 2013-07-08T12:39:44.383 回答
0

我通过修改 blockcategories.php、blockcategories.tpl 和 category-tree-branch.tpl 解决了这个问题。

首先在 blockcategories.php 中我编辑了第 148 和 246 行。

第 148 行是模块在 .tpl 文件中分配名为 $node 的返回数组的 getTree()。在这里,我将以下行添加到数组中(我将 id_parent 值分配给父级:

'parent' => $resultIds[$id_category]['id_parent']

在第 246 行,我将“currentCategoryParent”添加到 smarty->assign 数组中。

$this->smarty->assign(array('currentCategory' => $category, 'currentCategoryId' => $category->id, 'currentCategoryParent' => $category->id_parent));

然后,我可以使用 $currentCategoryParent 和 $node.parent 从 .tpl 文件中访问这些变量。

于 2015-02-13T06:17:50.523 回答