Guest User

Untitled

a guest
Jan 22nd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. <?php
  2.  
  3. /* header menu */
  4. register_nav_menu("menu", "Main menu");
  5.  
  6. /* footer menu */
  7. register_nav_menu("menu_footer", "Footer menu");
  8.  
  9. /* thumbnails */
  10. add_theme_support('post-thumbnails');
  11.  
  12. function my_get_post($post_id) {
  13. // Custom fields
  14. $ret['custom_fields'] = get_post_custom($post_id);
  15.  
  16. // Content
  17. $content = get_extended(get_post_field('post_content', $post_id));
  18. $ret['content'] = [
  19. 'title' => get_the_title($post_id),
  20. 'main' => apply_filters('the_content', $content['main']),
  21. 'extended' => apply_filters('the_content', $content['extended']),
  22. ];
  23. $ret['content_free'] = [
  24. 'title' => get_the_title($post_id),
  25. 'main' => $content['main'],
  26. 'extended' => $content['extended'],
  27. ];
  28.  
  29. // Images
  30. $ret['thumbnail'] = [
  31. 'thumbnail' => get_the_post_thumbnail_url($post_id, 'thumbnail'),
  32. 'medium' => get_the_post_thumbnail_url($post_id, 'medium'),
  33. 'large' => get_the_post_thumbnail_url($post_id, 'large'),
  34. 'full' => get_the_post_thumbnail_url($post_id, 'full'),
  35. ];
  36.  
  37. // Media
  38. $thumbnail_id = get_post_thumbnail_id($post_id);
  39. $medias = get_attached_media('image', $post_id);
  40. foreach ($medias as $media) {
  41. if ($media->ID != $thumbnail_id) {
  42. $ret['media']['image'][] = [
  43. 'thumbnail' => wp_get_attachment_image_src($media->ID, 'thumbnail')[0],
  44. 'medium' => wp_get_attachment_image_src($media->ID, 'medium')[0],
  45. 'large' => wp_get_attachment_image_src($media->ID, 'large')[0],
  46. 'full' => wp_get_attachment_image_src($media->ID, 'full')[0],
  47. 'excerpt' => $media->post_excerpt,
  48. ];
  49. }
  50. }
  51.  
  52. return $ret;
  53. }
  54.  
  55. function my_get_posts($post_type = 'post', $cat_id = 0, $tag = NULL) {
  56. $ret = [];
  57. $args = array(
  58. 'numberposts' => -1,
  59. 'category' => $cat_id,
  60. 'orderby' => 'date',
  61. 'order' => 'ASC',
  62. 'include' => array(),
  63. 'exclude' => array(),
  64. 'meta_key' => '',
  65. 'meta_value' => '',
  66. 'post_type' => $post_type,
  67. 'suppress_filters' => true,
  68. 'tag' => $tag ? $tag : '',
  69. );
  70. $posts = get_posts($args);
  71. foreach ($posts as $post) {
  72. setup_postdata($post);
  73. $ret[$post->ID] = my_get_post($post->ID);
  74. }
  75. wp_reset_postdata();
  76. return $ret;
  77. }
Add Comment
Please, Sign In to add comment