This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Aug 15th, 2013  |  syntax: None  |  size: 4.58 KB  |  views: 64  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /* To add excerpt support to pages */
  2.  
  3. add_action( 'init', 'add_pageexcerpt' );
  4. function add_pageexcerpt() {
  5.          add_post_type_support( 'page', 'excerpt' );
  6. }
  7.  
  8. /* To add excerpt support to pages */
  9.  
  10. /* Add tag for placing on the carosel */
  11.  
  12. add_action( 'admin_init', 'put_this_on_frontpage' );
  13.  
  14. function put_this_on_frontpage() {
  15.         add_meta_box( 'frontpage_meta_box',
  16.         'Put this page on the homepage?',
  17.         'display_homepage_meta_box',
  18.         'page', 'normal', 'high' );
  19. }
  20.  
  21. function display_homepage_meta_box( $page ) {
  22.         $homepagecheck = esc_html( get_post_meta( $page->ID, 'homepagecheckbox', true ) );
  23.         $homepageurl = esc_html( get_post_meta( $page->ID, 'homepageurl', true ) );
  24.         ?>
  25.         <table>
  26.                 <tr>
  27.                         <td style="width: 300px">Put this page on the homepage?</td><td><select style="width: 100px" name="homepageyesno"><?php foreach (array('No' , 'Yes') as $yesorno) { ?><option value="<?php echo $yesorno; ?>"<?php echo selected( $yesorno, $homepagecheck ); ?>><?php echo $yesorno; ?></option><?php } ?></select></td>
  28.                 </tr>
  29.                 <tr>
  30.                         <td style="width: 300px">Enter a new url here if you want to direct to a different page. Please include the http:// portion of the link for this to work.</td><td><textarea cols="100" rows="2" name="homepageurl"><?php echo $homepageurl; ?></textarea></td>
  31.                 </tr>
  32.         </table>
  33.  
  34. <?php  
  35. }
  36.  
  37. add_action( 'save_post', 'add_homepagedata', 10, 2 );
  38.  
  39. function add_homepagedata( $page_id, $pagedata ) {
  40.         if ( $pagedata->post_type == 'page' ) {
  41.                 if ( isset( $_POST['homepageyesno'] ) && $_POST['homepageyesno'] != '' ) {
  42.                         update_post_meta( $page_id, 'homepagecheckbox', $_POST['homepageyesno'] );
  43.                         if (get_post_meta( $page_id, 'homepageordernumber', true )) {
  44.                         } else {
  45.                                 update_post_meta( $page_id, 'homepageordernumber', 0 );
  46.                         }
  47.                 }
  48.                 if ( isset( $_POST['homepageurl'] ) && $_POST['homepageurl'] != '' ) {
  49.                         update_post_meta( $page_id, 'homepageurl', $_POST['homepageurl'] );
  50.                 } elseif (get_post_meta( $page_id, 'homepageurl', true )) {
  51.                         delete_post_meta($page_id, 'homepageurl' );
  52.                 }
  53.         }
  54. }
  55.  
  56. /* Add tag for placing on the carosel */
  57.  
  58. /* This creates the admin menu for altering the order of the slides on the home page */
  59.  
  60.  
  61. add_action( 'admin_menu', 'homepage_slider_order' );
  62.  
  63. function homepage_slider_order() {
  64.         add_options_page( 'Homepage Options', 'Edit Homepage Slider', 'manage_options', 'change_homepage_order', 'display_homepageorder_options' );
  65. }
  66.  
  67.  
  68. function display_homepageorder_options() {
  69.         if ( !current_user_can( 'manage_options' ) )  {
  70.                 wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
  71.         }
  72.        
  73.         if (!empty($_POST)) {
  74.                 echo '<br /><h1>Changes successfully made!</h1>';
  75.                 $postsprocessed = 0;
  76.                 foreach ($_POST['ordernumber'] as $number) {
  77.                         if (empty($number)) {
  78.                                 $number = 0;
  79.                         }
  80.                         update_post_meta( $_POST['orderid'][$postsprocessed], 'homepageordernumber', $number );
  81.                         $postsprocessed++;
  82.                 }
  83.         }
  84.        
  85.         screen_icon();
  86.         echo '<br /><h2>Alter the order in which slides on the homepage appear</h2><br />Please enter suitable numbers in the boxes provided. The lower the number the earlier in the slider sequence that page will appear.<br /><br />';
  87.         echo '<div class="wrap">';
  88.        
  89.         wp_reset_postdata();
  90.        
  91.         $featured_args = array(
  92.                                                 'post_type' => 'page',
  93.                                                 'posts_per_page' => -1,
  94.                                                 'orderby' => 'meta_value_num',
  95.                                                 'meta_key' => 'homepageordernumber',
  96.                                                 'order' => 'ASC',
  97.                                                 'meta_query' => array( array (
  98.                                                         'key' => 'homepagecheckbox',
  99.                                                         'value' => 'Yes'
  100.                                                         ))
  101.                                                 );
  102.         $featured = new WP_Query( $featured_args );
  103.        
  104.         if ( $featured->have_posts() ) {
  105.                 echo '<form id="assignments" enctype="multipart/form-data" action="" method="POST">';
  106.                 $postsprocessed = 0;
  107.                 while ( $featured->have_posts() ) {
  108.                         $featured->the_post();
  109.                         $idofpost = get_the_ID();
  110.                         $homenumberofpost = get_post_meta( $idofpost, 'homepageordernumber', true );
  111.                         echo '<input type="hidden" name="orderid['.$postsprocessed.']" value="'.$idofpost.'"/>';
  112.                         $postsprocessed5 = ($postsprocessed + 1)*5 ;
  113.                         echo '<textarea cols="4" rows="1" name="ordernumber['.$postsprocessed.']">'.$postsprocessed5.'</textarea>&nbsp;&nbsp;&nbsp;&nbsp;<b>'.get_the_title().'</b><br /><br />';
  114.                         $postsprocessed++ ;
  115.                        
  116.                         //echo get_post_meta( $idofpost, 'homepageorder', true ).'<br /><br />';
  117.                 }
  118.         }
  119.        
  120.         echo '<input type="submit" name="submit" value="Click to commit your changes" style="border: 3px black solid; height: 50px; width:600px;" />';
  121.        
  122.         wp_reset_postdata();
  123.         echo '</form>' ;
  124.        
  125.         echo '</div>';
  126. }
  127.  
  128.  
  129.  
  130. /* This creates the admin menu for altering the order of the slides on the home page */
clone this paste RAW Paste Data