Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* To add excerpt support to pages */
- add_action( 'init', 'add_pageexcerpt' );
- function add_pageexcerpt() {
- add_post_type_support( 'page', 'excerpt' );
- }
- /* To add excerpt support to pages */
- /* Add tag for placing on the carosel */
- add_action( 'admin_init', 'put_this_on_frontpage' );
- function put_this_on_frontpage() {
- add_meta_box( 'frontpage_meta_box',
- 'Put this page on the homepage?',
- 'display_homepage_meta_box',
- 'page', 'normal', 'high' );
- }
- function display_homepage_meta_box( $page ) {
- $homepagecheck = esc_html( get_post_meta( $page->ID, 'homepagecheckbox', true ) );
- $homepageurl = esc_html( get_post_meta( $page->ID, 'homepageurl', true ) );
- ?>
- <table>
- <tr>
- <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>
- </tr>
- <tr>
- <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>
- </tr>
- </table>
- <?php
- }
- add_action( 'save_post', 'add_homepagedata', 10, 2 );
- function add_homepagedata( $page_id, $pagedata ) {
- if ( $pagedata->post_type == 'page' ) {
- if ( isset( $_POST['homepageyesno'] ) && $_POST['homepageyesno'] != '' ) {
- update_post_meta( $page_id, 'homepagecheckbox', $_POST['homepageyesno'] );
- if (get_post_meta( $page_id, 'homepageordernumber', true )) {
- } else {
- update_post_meta( $page_id, 'homepageordernumber', 0 );
- }
- }
- if ( isset( $_POST['homepageurl'] ) && $_POST['homepageurl'] != '' ) {
- update_post_meta( $page_id, 'homepageurl', $_POST['homepageurl'] );
- } elseif (get_post_meta( $page_id, 'homepageurl', true )) {
- delete_post_meta($page_id, 'homepageurl' );
- }
- }
- }
- /* Add tag for placing on the carosel */
- /* This creates the admin menu for altering the order of the slides on the home page */
- add_action( 'admin_menu', 'homepage_slider_order' );
- function homepage_slider_order() {
- add_options_page( 'Homepage Options', 'Edit Homepage Slider', 'manage_options', 'change_homepage_order', 'display_homepageorder_options' );
- }
- function display_homepageorder_options() {
- if ( !current_user_can( 'manage_options' ) ) {
- wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
- }
- if (!empty($_POST)) {
- echo '<br /><h1>Changes successfully made!</h1>';
- $postsprocessed = 0;
- foreach ($_POST['ordernumber'] as $number) {
- if (empty($number)) {
- $number = 0;
- }
- update_post_meta( $_POST['orderid'][$postsprocessed], 'homepageordernumber', $number );
- $postsprocessed++;
- }
- }
- screen_icon();
- 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 />';
- echo '<div class="wrap">';
- wp_reset_postdata();
- $featured_args = array(
- 'post_type' => 'page',
- 'posts_per_page' => -1,
- 'orderby' => 'meta_value_num',
- 'meta_key' => 'homepageordernumber',
- 'order' => 'ASC',
- 'meta_query' => array( array (
- 'key' => 'homepagecheckbox',
- 'value' => 'Yes'
- ))
- );
- $featured = new WP_Query( $featured_args );
- if ( $featured->have_posts() ) {
- echo '<form id="assignments" enctype="multipart/form-data" action="" method="POST">';
- $postsprocessed = 0;
- while ( $featured->have_posts() ) {
- $featured->the_post();
- $idofpost = get_the_ID();
- $homenumberofpost = get_post_meta( $idofpost, 'homepageordernumber', true );
- echo '<input type="hidden" name="orderid['.$postsprocessed.']" value="'.$idofpost.'"/>';
- $postsprocessed5 = ($postsprocessed + 1)*5 ;
- echo '<textarea cols="4" rows="1" name="ordernumber['.$postsprocessed.']">'.$postsprocessed5.'</textarea> <b>'.get_the_title().'</b><br /><br />';
- $postsprocessed++ ;
- //echo get_post_meta( $idofpost, 'homepageorder', true ).'<br /><br />';
- }
- }
- echo '<input type="submit" name="submit" value="Click to commit your changes" style="border: 3px black solid; height: 50px; width:600px;" />';
- wp_reset_postdata();
- echo '</form>' ;
- echo '</div>';
- }
- /* This creates the admin menu for altering the order of the slides on the home page */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement