Advertisement
Guest User

Untitled

a guest
Apr 28th, 2016
92
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. function get_page_templates_select() {
  4.  $teh_cats = get_page_templates();
  5.  foreach ( $teh_cats as $template_name => $template_filename ) {
  6.      if (stripos(strtolower($template_filename), 'home') !== false) {
  7.             $results[$template_filename] = $template_name;
  8.         }
  9.    }
  10.    return $results;
  11.    echo $results;
  12. }
  13.  
  14. function remove_styles_sections(){
  15.     global $wp_customize;
  16.     $wp_customize->remove_section('static_front_page');
  17.     $wp_customize->remove_section('colors');
  18.     $wp_customize->remove_section('background_image');
  19.     $wp_customize->remove_section('header_image');
  20.     $wp_customize->remove_section('widgets');
  21. }
  22.  
  23. function get_categories_select() {
  24.  $teh_cats = get_categories();
  25.     $results;
  26.     $count = count($teh_cats);
  27.     for ($i=0; $i < $count; $i++) {
  28.       if (isset($teh_cats[$i]))
  29.         $results[$teh_cats[$i]->slug] = $teh_cats[$i]->name;
  30.       else
  31.         $count++;
  32.     }
  33.   return $results;
  34. }
  35.  
  36. function prowordpress_customize_register( $wp_customize ) {
  37.    
  38.         // Settings, Sections, and Controls are defined here
  39.        
  40.         // HOME PAGE
  41.            
  42.         $wp_customize->add_setting( 'home_page_text' , array(
  43.             'default'           => 'This is the home page text',
  44.             'type'              => 'option',
  45.             'transport'         => 'refresh',
  46.         ));
  47.         $wp_customize->add_section( 'prowordpress_content_customizations' , array(
  48.             'title'       => __('Home Page', 'prowordpress'),
  49.             'description' => __('Modify the Home Page', 'prowordpress'),
  50.             'priority'    => 30,
  51.         ));
  52.         $wp_customize->add_control( 'home_page_text_control', array(
  53.             'label'      => __( 'Home Page Text', 'prowordpress' ),
  54.             'section'    => 'prowordpress_content_customizations',
  55.             'settings'   => 'home_page_text',
  56.             'type'       => 'textarea',
  57.         ));
  58.        
  59.         $wp_customize->add_setting( 'home_page_template_select' , array(
  60.             'default'           => 'test',
  61.             'type'              => 'theme_mod',
  62.             'transport'         => 'refresh',
  63.         ));
  64.         $wp_customize->add_control(
  65.             new WP_Customize_Control(
  66.                 $wp_customize,
  67.                 'home_page_template_select',
  68.                 array(
  69.                     'label'          => __( 'Home page template:', 'blankwptheme' ),
  70.                     'section'        => 'prowordpress_content_customizations',
  71.                     'settings'       => 'home_page_template_select',
  72.                     'type'           => 'select',
  73.                     'choices'        => get_page_templates_select(),
  74.                 )
  75.             )
  76.         );
  77.        
  78.         $wp_customize->add_setting( 'home_page_posts_select' , array(
  79.             'default'           => 'test',
  80.             'type'              => 'theme_mod',
  81.             'transport'         => 'refresh',
  82.         ));
  83.         $wp_customize->add_control(
  84.             new WP_Customize_Control(
  85.                 $wp_customize,
  86.                 'home_page_posts_select',
  87.                 array(
  88.                     'label'          => __( 'Which post type to display on the home page?', 'blankwptheme' ),
  89.                     'section'        => 'prowordpress_content_customizations',
  90.                     'settings'       => 'home_page_posts_select',
  91.                     'type'           => 'select',
  92.                     'choices'        => get_categories_select(),
  93.                 )
  94.             )
  95.         );
  96.        
  97.         // ABOUT PAGE
  98.        
  99.         $wp_customize->add_setting( 'about_page_text' , array(
  100.             'default'           => 'Testing here',
  101.             'type'              => 'option',
  102.             'transport'         => 'refresh',
  103.         ));
  104.         $wp_customize->add_section( 'prowordpress_about_page_customization' , array(
  105.             'title'       => __('About Page', 'prowordpress'),
  106.             'description' => __('Modify the text on the about page', 'prowordpress'),
  107.             'priority'    => 34,
  108.         ));
  109.         $wp_customize->add_control( 'about_page_text_control', array(
  110.             'label'      => __( 'About Page Text', 'prowordpress' ),
  111.             'section'    => 'prowordpress_about_page_customization',
  112.             'settings'   => 'about_page_text',
  113.             'type'       => 'textarea',
  114.         ));
  115.        
  116. }
  117.  
  118. add_action( 'customize_register', 'prowordpress_customize_register' );
  119. add_action( 'customize_register', 'remove_styles_sections', 20 );
  120.  
  121. ?>
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. <?php /* Template Name: Home */
  137.  
  138. get_header();
  139.  
  140. echo "theme selected: " . get_theme_mod('home_page_template_select');
  141.  
  142. $page_id = 5;
  143. update_post_meta( $page_id, '_wp_page_template', get_theme_mod('home_page_template_select') );
  144.  
  145. ?>
  146.  
  147. <div style="margin-top:60px;">
  148.  
  149.     <?php echo get_option('home_page_text'); ?>
  150.  
  151. </div>
  152.  
  153. <div style="margin-top:60px;">
  154.  
  155.     <?php
  156.   $args = array(
  157.     'category_name' => get_theme_mod('home_page_posts_select'),
  158.     'posts_per_page' => 5
  159.   );
  160.  
  161.   // Displays the category's name
  162.   echo "<h3>" . get_category_by_slug($args['category_name'])->name . "</h3>";
  163.   $the_query = new WP_Query( $args );
  164.  
  165.   // The Loop
  166.   if ( $the_query->have_posts() ) :
  167.     //echo "<ul>";
  168.     while ( $the_query->have_posts() ) : $the_query->the_post();
  169.       if(has_post_thumbnail($post->ID)){
  170.         $thumbsrc = get_the_post_thumbnail($post->ID,'medium');
  171.       } else {
  172.         $thumbsrc = "<img src=\"images/no_featured_image.jpg\" alt=\"" . get_the_title() . "\">";
  173.       }
  174.       $link = get_permalink();
  175.       $title = get_the_title();
  176.       $content = get_the_content();
  177.       echo '<div style="width:302px;float:left;height:502px;margin-right:20px;">';
  178.       echo $thumbsrc . '<br>';
  179.       echo '<a href="' . $link . '">'  . $title . '</a><br>' . $content;
  180.       echo '</div>';
  181.     endwhile;
  182.     //echo "</ul>";
  183.   endif;
  184.  
  185.   // Reset Post Data
  186.   wp_reset_postdata();
  187.  
  188. ?>
  189.  
  190. </div>
  191.  
  192. <?php get_footer(); ?>
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203. <?php /* Template Name: Home 2 */
  204.  
  205. get_header();
  206.  
  207. echo "theme selected: " . get_theme_mod('home_page_template_select');
  208.  
  209. $page_id = 5;
  210. update_post_meta( $page_id, '_wp_page_template', get_theme_mod('home_page_template_select') );
  211.  
  212. ?>
  213.  
  214.  
  215. <div style="margin-top:60px;height:700px;">
  216.  
  217.     <?php
  218.   $args = array(
  219.     'category_name' => get_theme_mod('home_page_posts_select'),
  220.     'posts_per_page' => 5
  221.   );
  222.  
  223.   // Displays the category's name
  224.   echo "<h3>" . get_category_by_slug($args['category_name'])->name . "</h3>";
  225.   $the_query = new WP_Query( $args );
  226.  
  227.   // The Loop
  228.   if ( $the_query->have_posts() ) :
  229.     //echo "<ul>";
  230.     while ( $the_query->have_posts() ) : $the_query->the_post();
  231.       if(has_post_thumbnail($post->ID)){
  232.         $thumbsrc = get_the_post_thumbnail($post->ID,'medium');
  233.       } else {
  234.         $thumbsrc = "<img src=\"images/no_featured_image.jpg\" alt=\"" . get_the_title() . "\">";
  235.       }
  236.       $link = get_permalink();
  237.       $title = get_the_title();
  238.       $content = get_the_content();
  239.       echo '<div style="width:302px;float:left;height:502px;margin-right:20px;">';
  240.       echo $thumbsrc . '<br>';
  241.       echo '<a href="' . $link . '">'  . $title . '</a><br>' . $content;
  242.       echo '</div>';
  243.     endwhile;
  244.     //echo "</ul>";
  245.   endif;
  246.  
  247.   // Reset Post Data
  248.   wp_reset_postdata();
  249.  
  250. ?>
  251.  
  252. </div>
  253.  
  254. <div style="margin-top:60px;clear:both;">
  255.  
  256.     <?php echo get_option('home_page_text'); ?>
  257.  
  258. </div>
  259.  
  260. <?php get_footer(); ?>
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement