NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

formats.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. function make_taxonomy_endpoint_for( $terms ) {
  3. $type_slugs = [];
  4. foreach ($terms as $type_slug) {
  5. array_push($type_slugs, $type_slug->slug);
  6. }
  7. return $type_slugs;
  8. }
  9. function default_post_format( $item, $include_content ) {
  10. $filtered = [];
  11. $filtered[id] = $item->ID;
  12. $filtered[slug] = $item->post_name;
  13. $filtered[type] = $item->post_type;
  14. $filtered[title] = $item->post_title;
  15. $filtered[excerpt] = $item->post_excerpt;
  16. $filtered[date] = $item->post_date;
  17. if($include_content) {
  18. $content = $item->post_content;
  19. $content = apply_filters('the_content', $content);
  20. $filtered[content] = wp_specialchars_decode($content);
  21. }
  22. if(!$filtered[excerpt]) {
  23. $excerpt = get_the_excerpt($item);
  24. $filtered[excerpt] = wp_specialchars_decode($excerpt);
  25. }
  26. $filtered[featured] = get_the_post_thumbnail_url($item);
  27. if(!$filtered[featured]) {
  28. $thumbnailId = get_post_meta( $item->ID, '_thumbnail_id', true );
  29. $filtered[featured] = get_post($thumbnailId)->guid;
  30. }
  31. $filtered[thumb] = get_the_post_thumbnail_url($item, 'medium');
  32. if(!$filtered[thumb]) {
  33. $thumbnailId = get_post_meta( $item->ID, '_thumbnail_id', true );
  34. $filtered[thumb] = get_post($thumbnailId)->guid;
  35. }
  36. $filtered[hero] = get_post_meta( $item->ID, 'hero_header', true );
  37. // Materials + type endpoints
  38. $posts_with_type = ['artist', 'exhbition', 'event'];
  39. if( in_array($item->post_type, $posts_with_type) ) {
  40. $filtered[materials] = make_taxonomy_endpoint_for(get_the_terms( $item, 'material'));
  41. $filtered[subtypes] = make_taxonomy_endpoint_for(get_the_terms( $item, $item->post_type . '_type' ));
  42. }
  43. // Custom fields endpoint
  44. if($item->post_type === 'episode' && $include_content) $filtered[credits] = get_post_meta( $item->ID, 'credits', true );
  45. if($item->post_type === 'artist') $filtered[sortname] = get_post_meta( $item->ID, 'artist-sort-name', true );
  46. $posts_with_date = ['exhbition', 'event'];
  47. if( in_array($item->post_type, $posts_with_date) ) {
  48. $filtered[start] = get_post_meta($item->ID, $item->post_type . '-start-time', true);
  49. $filtered[end] = get_post_meta($item->ID, $item->post_type . '-end-time', true);
  50. $filtered[current] = time() <= (int)$filtered[end] && time() >= (int)$filtered[start];
  51. }
  52. // Post categories and tags (store just the slugs)
  53. if($item->post_type === 'post') {
  54. $filtered[categories] = make_taxonomy_endpoint_for(get_the_terms( $item, 'category' ));
  55. $filtered[tags] = make_taxonomy_endpoint_for(get_the_terms( $item, 'post_tag' ));
  56. }
  57. return $filtered;
  58. }
  59. function minimal_post_format( $item ) {
  60. $filtered = [];
  61. $filtered[id] = $item->ID;
  62. $filtered[slug] = $item->post_name;
  63. $filtered[type] = $item->post_type;
  64. $filtered[title] = $item->post_title;
  65. $filtered[date] = $item->post_date;
  66. $filtered[thumb] = get_the_post_thumbnail_url($item, 'medium');
  67. if(!$filtered[thumb]) {
  68. $thumbnailId = get_post_meta( $item->ID, '_thumbnail_id', true );
  69. $filtered[thumb] = get_post($thumbnailId)->guid;
  70. }
  71. $posts_with_date = ['exhbition', 'event'];
  72. if( in_array($item->post_type, $posts_with_date) ) {
  73. $filtered[start] = get_post_meta($item->ID, $item->post_type . '-start-time', true);
  74. $filtered[end] = get_post_meta($item->ID, $item->post_type . '-end-time', true);
  75. $filtered[current] = time() <= (int)$filtered[end] && time() >= (int)$filtered[start];
  76. }
  77. // Post categories and tags (store just the slugs)
  78. if($item->post_type === 'post') {
  79. $filtered[categories] = make_taxonomy_endpoint_for(get_the_terms( $item, 'category' ));
  80. $filtered[tags] = make_taxonomy_endpoint_for(get_the_terms( $item, 'post_tag' ));
  81. }
  82. return $filtered;
  83. }
  84. ?>