Guest User

Untitled

a guest
Jan 18th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 KB | None | 0 0
  1. function get_page_templates_select() {
  2. $teh_cats = get_page_templates();
  3. foreach ( $teh_cats as $template_name => $template_filename ) {
  4. if (stripos(strtolower($template_filename), 'home') !== false) {
  5. $results[$template_filename] = $template_name;
  6. }
  7. }
  8. return $results;
  9. echo $results;
  10. }
  11.  
  12. function get_categories_select() {
  13. $teh_cats = get_categories();
  14. $results;
  15. $count = count($teh_cats);
  16. for ($i=0; $i < $count; $i++) {
  17. if (isset($teh_cats[$i]))
  18. $results[$teh_cats[$i]->slug] = $teh_cats[$i]->name;
  19. else
  20. $count++;
  21. }
  22. return $results;
  23. }
  24.  
  25. function prowordpress_customize_register( $wp_customize ) {
  26.  
  27. // Settings, Sections, and Controls are defined here
  28.  
  29. // HOME PAGE
  30.  
  31. $wp_customize->add_setting( 'home_page_text' , array(
  32. 'default' => 'This is the home page text',
  33. 'type' => 'option',
  34. 'transport' => 'refresh',
  35. ));
  36. $wp_customize->add_section( 'prowordpress_content_customizations' , array(
  37. 'title' => __('Home Page', 'prowordpress'),
  38. 'description' => __('Modify the Home Page', 'prowordpress'),
  39. 'priority' => 30,
  40. ));
  41. $wp_customize->add_control( 'home_page_text_control', array(
  42. 'label' => __( 'Home Page Text', 'prowordpress' ),
  43. 'section' => 'prowordpress_content_customizations',
  44. 'settings' => 'home_page_text',
  45. 'type' => 'textarea',
  46. ));
  47.  
  48. $wp_customize->add_setting( 'home_page_template_select' , array(
  49. 'default' => 'test',
  50. 'type' => 'theme_mod',
  51. 'transport' => 'refresh',
  52. ));
  53. $wp_customize->add_control(
  54. new WP_Customize_Control(
  55. $wp_customize,
  56. 'home_page_template_select',
  57. array(
  58. 'label' => __( 'Home page template:', 'blankwptheme' ),
  59. 'section' => 'prowordpress_content_customizations',
  60. 'settings' => 'home_page_template_select',
  61. 'type' => 'select',
  62. 'choices' => get_page_templates_select(),
  63. )
  64. )
  65. );
  66.  
  67. $wp_customize->add_setting( 'home_page_posts_select' , array(
  68. 'default' => 'test',
  69. 'type' => 'theme_mod',
  70. 'transport' => 'refresh',
  71. ));
  72. $wp_customize->add_control(
  73. new WP_Customize_Control(
  74. $wp_customize,
  75. 'home_page_posts_select',
  76. array(
  77. 'label' => __( 'Which post type to display on the home page?', 'blankwptheme' ),
  78. 'section' => 'prowordpress_content_customizations',
  79. 'settings' => 'home_page_posts_select',
  80. 'type' => 'select',
  81. 'choices' => get_categories_select(),
  82. )
  83. )
  84. );
  85.  
  86. }
  87.  
  88. add_action( 'customize_register', 'prowordpress_customize_register' );
  89.  
  90. <?php /* Template Name: Home */
  91.  
  92. get_header();
  93.  
  94. echo "theme selected: " . get_theme_mod('home_page_template_select');
  95.  
  96. $page_id = 5;
  97. update_post_meta( $page_id, '_wp_page_template', get_theme_mod('home_page_template_select') );
  98.  
  99. ?>
  100.  
  101. <div style="margin-top:60px;">
  102.  
  103. <?php echo get_option('home_page_text'); ?>
  104.  
  105. </div>
  106.  
  107. <div style="margin-top:60px;">
  108.  
  109. <?php
  110. $args = array(
  111. 'category_name' => get_theme_mod('home_page_posts_select'),
  112. 'posts_per_page' => 5
  113. );
  114.  
  115. // Displays the category's name
  116. echo "<h3>" . get_category_by_slug($args['category_name'])->name . " </h3>";
  117. $the_query = new WP_Query( $args );
  118.  
  119. // The Loop
  120. if ( $the_query->have_posts() ) :
  121. //echo "<ul>";
  122. while ( $the_query->have_posts() ) : $the_query->the_post();
  123. if(has_post_thumbnail($post->ID)){
  124. $thumbsrc = get_the_post_thumbnail($post->ID,'medium');
  125. } else {
  126. $thumbsrc = "<img src="images/no_featured_image.jpg" alt="" . get_the_title() . "">";
  127. }
  128. $link = get_permalink();
  129. $title = get_the_title();
  130. $content = get_the_content();
  131. echo '<div style="width:302px;float:left;height:502px;margin- right:20px;">';
  132. echo $thumbsrc . '<br>';
  133. echo '<a href="' . $link . '">' . $title . '</a><br>' . $content;
  134. echo '</div>';
  135. endwhile;
  136. //echo "</ul>";
  137. endif;
  138.  
  139. // Reset Post Data
  140. wp_reset_postdata();
  141.  
  142. ?>
  143.  
  144. </div>
  145.  
  146. <?php get_footer(); ?>
Add Comment
Please, Sign In to add comment