你对JavaScript有多了解?您可以使用Brandon Kelly's CP CSS & JS扩展名。然后使用一个小的自定义JavaScript来构建该功能。不完美,但可能比编写自定义扩展更快。粗略地说,你可以这样做:
- 创建通道域组和所有的渠道,而组分配给您的频道
- 为了让多一点可用的,你要的类别选择到与字段位于相同的“发布”选项卡上:为该频道创建一个自定义发布布局,将“类别”字段从“类别”选项卡移动到“发布”选项卡
- 找到要隐藏的频道字段的ID号,发布页面中的HTML ID看起来像“hold_field_ID#”
- 找出类别的类别ID以点击以显示additi onal领域。在“发布”页面中,该类别将显示在“类别”字段中,并带有“值= ID”属性。
- 脚本时间!前往附加组件>扩展> 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() };
});
});
};
你可能有一些更多的逻辑建立在单击处理程序,以确保选中该复选框,当字段只显示(除其他事项外)但这是基本的想法。
您还需要确保在编辑保存的条目时,如果字段包含先前保存的数据,则这些字段不会隐藏。但这是正确的道路! –
良好的通话!我为该逻辑添加了一个开始。 – unexplainedBacn
工作很好!谢谢 – Dan