custom-fields.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php if (!defined('__TYPECHO_ADMIN__')) exit; ?>
  2. <?php
  3. $fields = isset($post) ? $post->getFieldItems() : $page->getFieldItems();
  4. $defaultFields = isset($post) ? $post->getDefaultFieldItems() : $page->getDefaultFieldItems();
  5. ?>
  6. <section id="custom-field"
  7. class="typecho-post-option<?php if (empty($defaultFields) && empty($fields)): ?> fold<?php endif; ?>">
  8. <label id="custom-field-expand" class="typecho-label"><a href="##"><i
  9. class="i-caret-right"></i> <?php _e('自定义字段'); ?></a></label>
  10. <table class="typecho-list-table mono">
  11. <colgroup>
  12. <col width="20%"/>
  13. <col width="15%"/>
  14. <col width="55%"/>
  15. <col width="10%"/>
  16. </colgroup>
  17. <?php foreach ($defaultFields as $field): ?>
  18. <?php [$label, $input] = $field; ?>
  19. <tr>
  20. <td><?php $label->render(); ?></td>
  21. <td colspan="3"><?php $input->render(); ?></td>
  22. </tr>
  23. <?php endforeach; ?>
  24. <?php foreach ($fields as $field): ?>
  25. <tr>
  26. <td>
  27. <label for="fieldname" class="sr-only"><?php _e('字段名称'); ?></label>
  28. <input type="text" name="fieldNames[]" value="<?php echo htmlspecialchars($field['name']); ?>"
  29. id="fieldname" class="text-s w-100">
  30. </td>
  31. <td>
  32. <label for="fieldtype" class="sr-only"><?php _e('字段类型'); ?></label>
  33. <select name="fieldTypes[]" id="fieldtype">
  34. <option
  35. value="str"<?php if ('str' == $field['type']): ?> selected<?php endif; ?>><?php _e('字符'); ?></option>
  36. <option
  37. value="int"<?php if ('int' == $field['type']): ?> selected<?php endif; ?>><?php _e('整数'); ?></option>
  38. <option
  39. value="float"<?php if ('float' == $field['type']): ?> selected<?php endif; ?>><?php _e('小数'); ?></option>
  40. <option
  41. value="json"<?php if ('json' == $field['type']): ?> selected<?php endif; ?>><?php _e('JSON 结构'); ?></option>
  42. </select>
  43. </td>
  44. <td>
  45. <label for="fieldvalue" class="sr-only"><?php _e('字段值'); ?></label>
  46. <textarea name="fieldValues[]" id="fieldvalue" class="text-s w-100"
  47. rows="2"><?php echo htmlspecialchars($field[($field['type'] == 'json' ? 'str' : $field['type']) . '_value']); ?></textarea>
  48. </td>
  49. <td>
  50. <button type="button" class="btn btn-xs"><?php _e('删除'); ?></button>
  51. </td>
  52. </tr>
  53. <?php endforeach; ?>
  54. <?php if (empty($defaultFields) && empty($fields)): ?>
  55. <tr>
  56. <td>
  57. <label for="fieldname" class="sr-only"><?php _e('字段名称'); ?></label>
  58. <input type="text" name="fieldNames[]" placeholder="<?php _e('字段名称'); ?>" id="fieldname"
  59. class="text-s w-100">
  60. </td>
  61. <td>
  62. <label for="fieldtype" class="sr-only"><?php _e('字段类型'); ?></label>
  63. <select name="fieldTypes[]" id="fieldtype">
  64. <option value="str"><?php _e('字符'); ?></option>
  65. <option value="int"><?php _e('整数'); ?></option>
  66. <option value="float"><?php _e('小数'); ?></option>
  67. </select>
  68. </td>
  69. <td>
  70. <label for="fieldvalue" class="sr-only"><?php _e('字段值'); ?></label>
  71. <textarea name="fieldValues[]" placeholder="<?php _e('字段值'); ?>" id="fieldvalue"
  72. class="text-s w-100" rows="2"></textarea>
  73. </td>
  74. <td>
  75. <button type="button" class="btn btn-xs"><?php _e('删除'); ?></button>
  76. </td>
  77. </tr>
  78. <?php endif; ?>
  79. </table>
  80. <div class="description clearfix">
  81. <button type="button" class="btn btn-xs operate-add"><?php _e('+添加字段'); ?></button>
  82. <?php _e('自定义字段可以扩展你的模板功能, 使用方法参见 <a href="https://docs.typecho.org/help/custom-fields">帮助文档</a>'); ?>
  83. </div>
  84. </section>