4

我在ExpressionEngine中构建了一个博客网站。我有两种类型的条目,我想保留在同一个频道中。当选择某个类别时,我想显示其他字段。ExpressionEngine:有条件地在频道条目中显示自定义字段

**EXAMPLE 
Channel > Article 
    Fields: 
     - Title 
     - Post Body 
     - Image 
     - Tags 

    Additional Fields for a category: 
     - Price 
     - Product Bio 

这可能吗?

回答

3

你对JavaScript有多了解?您可以使用Brandon Kelly's CP CSS & JS扩展名。然后使用一个小的自定义JavaScript来构建该功能。不完美,但可能比编写自定义扩展更快。粗略地说,你可以这样做:

  1. 创建通道域组和所有的渠道,而组分配给您的频道
  2. 为了让多一点可用的,你要的类别选择到与字段位于相同的“发布”选项卡上:为该频道创建一个自定义发布布局,将“类别”字段从“类别”选项卡移动到“发布”选项卡
  3. 找到要隐藏的频道字段的ID号,发布页面中的HTML ID看起来像“hold_field_ID#”
  4. 找出类别的类别ID以点击以显示additi onal领域。在“发布”页面中,该类别将显示在“类别”字段中,并带有“值= ID”属性。
  5. 脚本时间!前往附加组件>扩展> CP CSS & JS设置并在自定义JavaScript字段中添加一些JS。

事情是这样的:

$(document).ready(function() { 

    // Cache the divs with your channel fields 
    var $theSecretFields = $('#hold_field_5, #hold_field_6'); 

    // Hide them 
    $theSecretFields.each(function() { 
     // But only if they're empty (no previous saved data) 
     // If you're using a textarea or something else, change the .find selector 
     if ($(this).find('input').val() === '' ) { $(this).hide() }; 
    }); 

    // When you click the category ID (the input[value="id"] selector)... 
    $('#hold_field_category').find('input[value="12"]').click(function() { 
     // Toggle the visibility of the channel fields 
     // Again, only show/hide them if they're empty 
     $theSecretFields.each(function() { 
     // Again, change the .find selector for your field type if necessary 
     if ($(this).find('input').val() === '' ) { $(this).toggle() }; 
     }); 
    }); 
}; 

你可能有一些更多的逻辑建立在单击处理程序,以确保选中该复选框,当字段只显示(除其他事项外)但这是基本的想法。

+1

您还需要确保在编辑保存的条目时,如果字段包含先前保存的数据,则这些字段不会隐藏。但这是正确的道路! –

+0

良好的通话!我为该逻辑添加了一个开始。 – unexplainedBacn

+0

工作很好!谢谢 – Dan

0

你想在控制面板或网站的前端?

+0

在控制面板中 – Dan

0

要做到这一点与类别作为触发器,你需要编写一个自定义的扩展,添加JavaScript来显示和隐藏。

您可能想看看Entry Type加载项,它允许您使用下拉菜单更改显示的字段。

相关问题