ID, '_menu_item_object_id', true ); return $atts; } function enqueue_scripts( $hook ) { //if( 'index.php' != $hook ) { // Only applies to dashboard panel //return; //} //wp_enqueue_script( 'ajax-script', plugins_url( '/js/my_query.js', __FILE__ ), array('jquery') ); //wp_enqueue_script( 'f-script', get_template_directory_uri() . '/js/f.js' ); wp_enqueue_script( 'f-script', get_template_directory_uri() . '/js/f.min.js' ); // in JavaScript, object properties are accessed as ajax_object.ajax_url, ajax_object.we_value wp_localize_script( 'f-script', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); } function load_search() { $query = $_POST['query']; $args = array( 'post_type' => 'page', 'post_status' => 'publish', 'posts_per_page' => -1, 'order' => 'ASC', 'orderby' => 'menu_order', 's' => $query ); $search = new WP_Query( $args ); ob_start(); if ( $search->have_posts() ) : while ( $search->have_posts() ) : $search->the_post(); // get depth $postid = get_the_ID(); $depth = ( $postid == get_option('page_on_front') ) ? -1 : 0; while ( $postid > 0 ) { $postid = get_post_ancestors( $postid ); $postid = $postid[0]; $depth++; } if ( $depth > 2 ) { if ( $depth == 3 ) { } } else { // no results } ?>
post_parent.'&parent='.$post->post_parent); // no siblings if ( count( $siblings ) == 1 ) { return false; } foreach ( $siblings as $key => $sibling ){ if ( $post->ID == $sibling->ID ) { $current_id = $key; } } $closest = [ 'before' => get_permalink( $siblings[$current_id-1]->ID ), 'after' => get_permalink( $siblings[$current_id+1]->ID ) ]; if ( $siblings[$current_id-1]->ID == '' ) { $closest['before'] = get_permalink( $siblings[count($siblings)-1]->ID ); } if ( $siblings[$current_id+1]->ID == '' ) { $closest['after'] = get_permalink( $siblings[0]->ID ); } if ( $link == 'before' || $link == 'after' ) { echo $closest[$link]; } else { return $closest; } } // add id to wordpress generated menus add_filter( 'nav_menu_link_attributes', 'tmg__menu_atts', 10, 3 ); // when login to admin, show pages add_action('login_redirect', 'custom_login_redirect'); // reorder admin left navigation elements add_filter( 'custom_menu_order', 'reorder_menu' ); add_filter( 'menu_order', 'reorder_menu' ); // remove admin left navigation elements add_action( 'admin_menu', 'remove_menu' ); // hide admin editor on pages add_action( 'admin_head', 'hide_editor' ); // show menu under appearance add_theme_support( 'menus'); // enabled thumbnails for posts add_theme_support( 'post-thumbnails' ); // add scripts add_action( 'wp_enqueue_scripts', 'enqueue_scripts' ); // remove width height posts add_filter( 'post_thumbnail_html', 'remove_width_attribute', 10 ); add_filter( 'image_send_to_editor', 'remove_width_attribute', 10 ); // ajax: search add_action( 'wp_ajax_load_search', 'load_search' ); add_action( 'wp_ajax_nopriv_load_search', 'load_search' ); ?>