简体   繁体   English

如何根据分配给每个页面的类别为wordpress菜单lis着色?

[英]How to colour wordpress menu lis based on category assigned to each page?

I would like to create a nav menu that displays all the pages of a wordpress site, its layout similar to what you would see in a footer sitemap layout, approx 5 columns with all the pages shown. 我想创建一个导航菜单来显示wordpress网站的所有页面,其布局类似于在页脚站点地图布局中看到的布局,显示的所有页面大约5列。 Each page will be a project. 每个页面都是一个项目。 I want to use wordpress category checkboxes (like you have for posts) to allow selection of one relevant category for each project page. 我想使用wordpress类别复选框(就像帖子一样),以允许为每个项目页面选择一个相关类别。 Each page will then show a category caption below the project's description text, this I will style with CSS so each category has a different background colour. 然后,每个页面将在项目的描述文本下方显示类别标题,我将使用CSS设置样式标题,以便每个类别具有不同的背景色。

Because Wordpress doesn't provide categories for pages, I have found a plugin to add this category feature to pages called ninja-page-categories-and-tags: http://wordpress.org/extend/plugins/ninja-page-categories-and-tags/ 因为Wordpress不提供页面类别,所以我找到了一个插件可以将该类别功能添加到名为ninja-page-categories-and-tags的页面: http : //wordpress.org/extend/plugins/ninja-page-categories -和标签/

It's possible to edit the plugin php code under basic-functions.php to return a 'class' for the category displayed using get_slug and then applying css for each. 可以在basic-functions.php下编辑插件php代码,以使用get_slug为显示的类别返回一个“类”,然后为每个类别应用css。

My problem is that on the menu, which will be a secondary menu in Thirty Ten displaying the pages, I want to be able to colour the background of each link to match the category that has previously been assigned to each page using the ninja plugin. 我的问题是在菜单上(这将是显示页面的三十个菜单中的第二个菜单),我希望能够为每个链接的背景着色,以匹配先前使用忍者插件分配给每个页面的类别。 Because the menu works with pages and the categories are not directly linked to the menu items (firebug will not show category details in the html of each link to reference with the css) I am wondering how I can colour each link based on category? 因为菜单适用于页面,并且类别未直接链接到菜单项(Firebug不会在每个链接的html中显示类别详细信息以引用css),所以我想知道如何为基于类别的每个链接着色吗? Any ideas? 有任何想法吗?

Ultimately what I would like to achieve is a grid of page links that are all coloured based on their category, a colour coded menu. 最终,我想实现的是一个页面链接网格,所有链接均根据其类别(一个颜色编码的菜单)进行着色。

The plugin uses the standard wordpress category functionality but I just can't think how to connect these category details to the menu items to allow me to style them with css, any help would be really appreciated, even if just a point in the right direction. 该插件使用标准的wordpress类别功能,但是我只是想不出如何将这些类别详细信息连接到菜单项,以允许我使用CSS设置样式,即使只是朝着正确的方向迈出了任何帮助,也将不胜感激。

Thanks 谢谢

It's difficult to understand exactly what you're after, but essentially if you want to add extra classes to menu items (which will allow styling), you need to create a custom walker function. 很难确切地了解您要执行的操作,但是从本质上讲,如果您想向菜单项添加额外的类(这将允许样式设置),则需要创建一个自定义的walker函数。

Have a look at a tutorial like this: http://wp.tutsplus.com/tutorials/creative-coding/understanding-the-walker-class/ 看看这样的教程: http : //wp.tutsplus.com/tutorials/creative-coding/understanding-the-walker-class/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WordPress-列出页面lis并包含主页的菜单 - Wordpress - menu that lists page `lis` and also includes the home page 如何在WordPress的页面菜单中同时包含类别和页面? - How to include both category and page in page's menu in WordPress? 仅当在wordpress中分配帖子时,才在菜单上显示类别 - Display category on menu only when post(s) assigned in wordpress 如何根据页面类别在wordpress中显示帖子? - How can I display posts in wordpress based on page category? 在每个类别页面上显示子类别 - Display subcategories on each category page wordpress 如何在wordpress中基于当前页面加载不同的菜单? - How to load different menu based on current page in wordpress? 如何在WordPress博客列表页面的每页中间显示13个特定类别的最近帖子 - How to display 13 post with specific category recent post in middle in each page of WordPress blog list page 如何在Wordpress中添加类别菜单的活动状态? - How to add active state of category menu in wordpress? 如何在 wordpress 中动态制作具有产品类别的菜单 - How to Make a menu with product category Dynamically in wordpress 如何使用php根据用户角色更改WordPress管理页面的背景颜色? - How to change background colour of WordPress admin page based on user role using php?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM