你對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