Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Add your custom functions here
- // Queue parent style followed by child/customized style
- add_action( 'wp_enqueue_scripts', 'sparkling_enqueue_child_styles', 99);
- function sparkling_enqueue_child_styles() {
- wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
- wp_dequeue_style('sparkling-style');
- wp_enqueue_style( 'child-style',
- get_stylesheet_directory_uri() . '/style.css',
- array('parent-style')
- );
- }
- register_sidebar( array(
- 'name' => __( 'International Start', 'sparkling' ),
- 'id' => 'internationalstart',
- 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
- 'after_widget' => '</aside>',
- 'before_title' => '<h3 class="widget-title">',
- 'after_title' => '</h3>',
- ) );
- register_sidebar( array(
- 'name' => __( 'Benelux Start', 'sparkling' ),
- 'id' => 'beneluxstart',
- 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
- 'after_widget' => '</aside>',
- 'before_title' => '<h3 class="widget-title">',
- 'after_title' => '</h3>',
- ) );
- ?>
- <?php
- function my_category_queries( $query ) {
- // only homepage and is the main query
- if ($query->is_home() && $query->is_main_query()){
- // display only posts in category with slug 'articles'
- $query->set('category_name', 'news');
- // avoid sticky posts
- $query->set('post__not_in', get_option( 'sticky_posts' ) );
- }
- }
- add_action( 'pre_get_posts', 'my_category_queries' );
- ?>
- <?php
- add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
- function theme_enqueue_styles() {
- wp_enqueue_style( 'sparkling-bootstrap', get_template_directory_uri() . '/assets/css/bootstrap.min.css' );
- wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
- }
- if ( ! function_exists( 'sparkling_header_menu' ) ) :
- /**
- * Header menu (should you choose to use one)
- */
- function sparkling_header_menu() {
- // display the WordPress Custom Menu if available
- wp_nav_menu(array(
- 'menu' => 'primary',
- 'theme_location' => 'primary',
- 'depth' => 6,
- 'container' => 'div',
- 'container_class' => 'collapse navbar-collapse navbar-ex1-collapse',
- 'menu_class' => 'nav navbar-nav',
- 'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
- 'walker' => new wp_bootstrap_navwalker()
- ));
- } /* end header menu */
- endif;
- update_option('upload_url_path', '/wp-content/uploads');
- function only_admins_login_area( $redirect_to, $request, $user ) {
- global $user;
- if ( isset( $user->roles ) && is_array( $user->roles ) )
- {
- //check for admins
- if ( in_array( 'administrator', $user->roles ) )
- {
- // Redirect to default admin area
- return $redirect_to;
- }
- }
- return home_url();
- }
- add_filter( 'login_redirect', 'only_admins_login_area', 10, 3 );
- function exclude_widget_categories($args){
- $exclude = "122"; // The IDs of the excluding categories
- $args["exclude"] = $exclude;
- return $args;
- }
- add_filter("widget_categories_args","exclude_widget_categories");
- ?>
- <?php
- function register_my_menus() {
- register_nav_menus(
- array(
- 'benelux' => __( 'Benelux' ),
- 'International' => __( 'International' )
- )
- );
- }
- add_action( 'init', 'register_my_menus' );
- ?>
- <?php
- add_action('restrict_manage_posts', 'tsm_filter_post_type_by_taxonomy');
- function tsm_filter_post_type_by_taxonomy() {
- global $typenow;
- $post_type = 'post'; // change to your post type
- $taxonomy = 'location'; // change to your taxonomy
- if ($typenow == $post_type) {
- $selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
- $info_taxonomy = get_taxonomy($taxonomy);
- wp_dropdown_categories(array(
- 'show_option_all' => __("All Locations"),
- 'taxonomy' => $taxonomy,
- 'name' => $taxonomy,
- 'orderby' => 'name',
- 'selected' => $selected,
- 'show_count' => false,
- 'hide_empty' => true,
- ));
- };
- }
- add_filter('parse_query', 'tsm_convert_id_to_term_in_query');
- function tsm_convert_id_to_term_in_query($query) {
- global $pagenow;
- $post_type = 'post'; // change to your post type
- $taxonomy = 'location'; // change to your taxonomy
- $q_vars = &$query->query_vars;
- if ( $pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == $post_type && isset($q_vars[$taxonomy]) && is_numeric($q_vars[$taxonomy]) && $q_vars[$taxonomy] != 0 ) {
- $term = get_term_by('id', $q_vars[$taxonomy], $taxonomy);
- $q_vars[$taxonomy] = $term->slug;
- }
- }
- add_action('restrict_manage_posts', 'page_filter_post_type_by_taxonomy');
- function page_filter_post_type_by_taxonomy() {
- global $typenow;
- $post_type = 'page'; // change to your post type
- $taxonomy = 'location'; // change to your taxonomy
- if ($typenow == $post_type) {
- $selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
- $info_taxonomy = get_taxonomy($taxonomy);
- wp_dropdown_categories(array(
- 'show_option_all' => __("All Locations"),
- 'taxonomy' => $taxonomy,
- 'name' => $taxonomy,
- 'orderby' => 'name',
- 'selected' => $selected,
- 'show_count' => false,
- 'hide_empty' => true,
- ));
- };
- }
- add_filter('parse_query', 'page_convert_id_to_term_in_query');
- function page_convert_id_to_term_in_query($query) {
- global $pagenow;
- $post_type = 'page'; // change to your post type
- $taxonomy = 'location'; // change to your taxonomy
- $q_vars = &$query->query_vars;
- if ( $pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == $post_type && isset($q_vars[$taxonomy]) && is_numeric($q_vars[$taxonomy]) && $q_vars[$taxonomy] != 0 ) {
- $term = get_term_by('id', $q_vars[$taxonomy], $taxonomy);
- $q_vars[$taxonomy] = $term->slug;
- }
- }
- ?>
- <?php
- add_filter( 'manage_edit-post_sortable_columns', 'my_sortable_post_column' );
- function my_sortable_post_column( $columns ) {
- $columns['author'] = 'author';
- $columns['categories'] = 'categories';
- $columns['column-taxonomy'] = 'column-taxonomy';
- $columns['column-meta'] = 'column-meta';
- //To make a column 'un-sortable' remove it from the array
- //unset($columns['date']);
- return $columns;
- }
- add_filter( 'manage_edit-page_sortable_columns', 'page_post_column' );
- function page_post_column( $columns ) {
- $columns['author'] = 'author';
- $columns['categories'] = 'categories';
- $columns['column-taxonomy'] = 'column-taxonomy';
- //To make a column 'un-sortable' remove it from the array
- //unset($columns['date']);
- return $columns;
- }
- add_filter( 'manage_edit-sm-location_sortable_columns', 'locations_post_column' );
- function locations_post_column( $columns ) {
- $columns['column-taxonomy'] = 'column-taxonomy';
- $columns['column-meta'] = 'column-meta';
- $columns['column-meta-1'] = 'column-meta-1';
- $columns['column-meta-2'] = 'column-meta-2';
- $columns['column-meta-3'] = 'column-meta-3';
- //To make a column 'un-sortable' remove it from the array
- //unset($columns['date']);
- return $columns;
- }
- add_filter( 'ngg_manage_images_columns', 'ngg_thumbnail_column' );
- function ngg_thumbnail_column( $columns ) {
- $columns['thumbnail'] = 'thumbnail';
- //To make a column 'un-sortable' remove it from the array
- //unset($columns['date']);
- return $columns;
- }
- ?>
- <?php
- function benelux_featured_slider() {
- {
- echo '<div class="flexslider">';
- echo '<ul class="slides">';
- $count = of_get_option( 'sparkling_slide_number' );
- $slidecat = of_get_option( 'sparkling_slide_categories' );
- $query = new WP_Query( array(
- 'cat' => '230',
- 'posts_per_page' => $count,
- 'meta_query' => array(
- array(
- 'key' => '_thumbnail_id',
- 'compare' => 'EXISTS'
- ),
- ),
- ) );
- if ( $query->have_posts() ) :
- while ( $query->have_posts() ) : $query->the_post();
- if ( of_get_option( 'sparkling_slider_link_checkbox', 1 ) == 1 ) {
- echo '<li><a href="' . get_permalink() . '">';
- } else {
- echo '<li>';
- }
- if ( (function_exists( 'has_post_thumbnail' )) && ( has_post_thumbnail() ) ) :
- if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) {
- $feat_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
- $args = array(
- 'resize' => '1920,550',
- );
- $photon_url = jetpack_photon_url( $feat_image_url[0], $args );
- echo '<img src="' . $photon_url . '">';
- } else {
- echo get_the_post_thumbnail( get_the_ID(), 'activello-slider' );
- }
- endif;
- echo '<div class="flex-caption">';
- if ( get_the_title() != '' ) { echo '<h2 class="entry-title">' . get_the_title() . '</h2>';
- }
- if ( get_the_excerpt() != '' ) { echo '<div class="excerpt">' . get_the_excerpt() . '</div>';
- }
- echo '</div>';
- echo '</a></li>';
- endwhile;
- endif;
- wp_reset_postdata();
- echo '</ul>';
- echo ' </div>';
- }// End if().
- }
- ?>
- <?php
- function international_featured_slider() {
- {
- echo '<div class="flexslider">';
- echo '<ul class="slides">';
- $count = of_get_option( 'sparkling_slide_number' );
- $slidecat = of_get_option( 'sparkling_slide_categories' );
- $query = new WP_Query( array(
- 'cat' => '231',
- 'posts_per_page' => $count,
- 'meta_query' => array(
- array(
- 'key' => '_thumbnail_id',
- 'compare' => 'EXISTS'
- ),
- ),
- ) );
- if ( $query->have_posts() ) :
- while ( $query->have_posts() ) : $query->the_post();
- if ( of_get_option( 'sparkling_slider_link_checkbox', 1 ) == 1 ) {
- echo '<li><a href="' . get_permalink() . '">';
- } else {
- echo '<li>';
- }
- if ( (function_exists( 'has_post_thumbnail' )) && ( has_post_thumbnail() ) ) :
- if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) {
- $feat_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
- $args = array(
- 'resize' => '1920,550',
- );
- $photon_url = jetpack_photon_url( $feat_image_url[0], $args );
- echo '<img src="' . $photon_url . '">';
- } else {
- echo get_the_post_thumbnail( get_the_ID(), 'activello-slider' );
- }
- endif;
- echo '<div class="flex-caption">';
- if ( get_the_title() != '' ) { echo '<h2 class="entry-title">' . get_the_title() . '</h2>';
- }
- if ( get_the_excerpt() != '' ) { echo '<div class="excerpt">' . get_the_excerpt() . '</div>';
- }
- echo '</div>';
- echo '</a></li>';
- endwhile;
- endif;
- wp_reset_postdata();
- echo '</ul>';
- echo ' </div>';
- }// End if().
- }
- ?>
- <?php
- /**
- * Enqueue scripts and styles.
- */
- function international_scripts() {
- wp_dequeue_script( 'flexslider-js' );
- wp_dequeue_script( 'flexslider-customization' );
- wp_enqueue_script( 'flexslider-js', get_template_directory_uri() . '/assets/js/vendor/flexslider.min.js', array( 'jquery' ), '20140222', true );
- // Flexslider customization
- wp_enqueue_script( 'flexslider-customization', get_template_directory_uri() . '/assets/js/flexslider-custom.min.js', array( 'jquery', 'flexslider-js' ), '20140716', true );
- // Add slider CSS for pages
- wp_enqueue_style( 'flexslider-css', get_template_directory_uri().'/assets/css/flexslider.css' );
- }
- add_action( 'wp_enqueue_scripts', 'international_scripts' );
- function benelux_scripts() {
- wp_dequeue_script( 'flexslider-js' );
- wp_dequeue_script( 'flexslider-customization' );
- wp_enqueue_script( 'flexslider-js', get_template_directory_uri() . '/assets/js/vendor/flexslider.min.js', array( 'jquery' ), '20140222', true );
- // Flexslider customization
- wp_enqueue_script( 'flexslider-customization', get_template_directory_uri() . '/assets/js/flexslider-custom.min.js', array( 'jquery', 'flexslider-js' ), '20140716', true );
- // Add slider CSS for pages
- wp_enqueue_style( 'flexslider-css', get_template_directory_uri().'/assets/css/flexslider.css' );
- }
- add_action( 'wp_enqueue_scripts', 'benelux_scripts' );
- add_action('template_redirect', 'bwp_template_redirect');
- function bwp_template_redirect()
- {
- if (is_author())
- {
- wp_redirect( home_url() ); exit;
- }
- }
- function author_archive_redirect() {
- if( is_author() ) {
- wp_redirect( home_url(), 301 );
- exit;
- }
- }
- add_action( 'template_redirect', 'author_archive_redirect' );
- /*remove wordpress version number from front-end pages*/
- function remove_version_from_mysite() {
- return '';
- }
- add_filter('the_generator','remove_version_from_mysite');
- add_filter('generator','remove_version_from_mysite');
- /**
- * Add custom taxonomies
- *
- * Additional custom taxonomies can be defined here
- * http://codex.wordpress.org/Function_Reference/register_taxonomy
- */
- function add_custom_taxonomies() {
- // Add new "Location" taxonomy to Posts
- register_taxonomy('location',array('post','page','attachment'), array(
- // Hierarchical taxonomy (like categories)
- 'hierarchical' => true,
- // This array of options controls the labels displayed in the WordPress Admin UI
- 'labels' => array(
- 'name' => _x( 'Location', 'taxonomy general name' ),
- 'singular_name' => _x( 'Location', 'taxonomy singular name' ),
- 'search_items' => __( 'Search Locations' ),
- 'all_items' => __( 'All Locations' ),
- 'parent_item' => __( 'Parent Location' ),
- 'parent_item_colon' => __( 'Parent Location:' ),
- 'edit_item' => __( 'Edit Location' ),
- 'update_item' => __( 'Update Location' ),
- 'add_new_item' => __( 'Add New Location' ),
- 'new_item_name' => __( 'New Location Name' ),
- 'menu_name' => __( 'Location' ),
- ),
- // Control the slugs used for this taxonomy
- 'rewrite' => array(
- 'with_front' => true,
- 'ep_mask'=> EP_ALL,
- ),
- ));
- }
- add_action( 'init', 'add_custom_taxonomies', 0 );
- /*add_rewrite_tag('%location%', '^([^&/]+)', 'location=');
- add_rewrite_rule('^([^/]*)/([^/]*)/?','index.php?location=$matches[1]&name=$matches[2]','top');
- */
- // add region category to main queries
- add_action('pre_get_posts', 'tg_set_region');
- function tg_set_region( $query ) {
- //--------debug-----------
- //if ( !is_admin() && $query->is_main_query())
- // print_r( $query );
- //-----------------------
- if ( get_option('page_on_front') == $query->get('page_id')) return;
- if ( !is_admin() && $query->is_main_query()) {
- global $region;
- $explode = explode('/', $_SERVER['REQUEST_URI']);
- $cat = $query->get('category_name');
- $region = $explode[1]; // $region = 'benelux'; //$explode[1];
- if ( '' != $cat ) $cat .= '+' . $region;
- else $cat = $region;
- $query->set('category_name', $cat);
- }
- }
- // go to region home page if a home page request from same site
- // region determined from referrer URL
- //add_action('init', 'tg_home_by_region');
- function tg_home_by_region( $query ) {
- if ( array_key_exists('HTTP_REFERER', $_SERVER ) && 0 === strpos( $_SERVER['HTTP_REFERER'], site_url('/'))) {
- $explode = explode('/', $_SERVER['HTTP_REFERER']);
- $region = $explode[3];
- if ( "/$region/" != $_SERVER['REQUEST_URI'] && '/' == $_SERVER['REQUEST_URI']) {
- wp_redirect( site_url("/$region/"));
- exit;
- }
- }
- }
- // alter category and tag links to be compatible with global $region category
- //add_filter('term_link', 'tg_alter_term_links', 999, 3 );
- function tg_alter_term_links( $termlink, $term, $taxonomy ) {
- global $region;
- if ('category' == $taxonomy ) {
- $termlink = site_url('/') . $region . '?category_name=' . $term->slug;
- }
- if ('post_tag' == $taxonomy ) {
- $termlink = site_url('/') . $region . '?tag=' . $term->slug;
- }
- return $termlink;
- }
- /**
- * Outputs prev/next nav links for custom query pages
- *
- * @param array, $args, the same $args used for the page's main WP_Query
- * The args array must include an 'offset' argument, relying on 'paged' will not work.
- * string, $next, text for next page link (optional) default "Older Posts"
- * string, $prev, text for previous page link (optional) default "Newer Posts"
- * @return none, outputs prev/next nav links with region_page URL parm inside a div with
- * class 'search_page_nav', anchor links have class 'search_page_next' and 'search_page_prev'
- * @globals $_GET['region_page'], used to determine current page number. Page 1 assumed
- * if 'region_page' is not set.
- */
- function tg_custom_query_nav( $args, $next = 'Older Posts', $prev = 'Newer Posts' ) {
- // determine pagination parms
- $s_page = isset( $_GET['region_page']) ? sanitize_text_field( $_GET['region_page']) : 1;
- $pppage = isset( $args['posts_per_page']) ? $args['posts_per_page'] : get_option('posts_per_page');
- if ( -1 == $pppage ) return;
- $prev_off = ( $s_page - 2 ) * $pppage;
- $next_off = $s_page * $pppage;
- // check for more posts
- $args['no_found_posts'] = true; // just get a count
- $args['ignore_sticky_posts'] = true;
- $args['offset'] = $next_off;
- $query = new WP_Query( $args ); // get next page post count
- $ct_next = $query->post_count;
- $args['offset'] = $prev_off;
- $query = new WP_Query( $args ); // get prev page post count
- $ct_prev = 1 < $s_page ? $query->post_count : 0;
- // output links
- echo "\n<div class=\"paging-navigation\"><div class=\"nav-links\">";
- $link = remove_query_arg('region_page');
- $next .= '<i class="fa fa-chevron-right" aria-hidden="true"></i>';
- $nxt_link = esc_url( add_query_arg('region_page', $s_page+1, $link ));
- if ( $ct_next ) echo "\n<a class=\"nav-next\" href=\"$nxt_link\">$next</a>";
- $prev = '<i class="fa fa-chevron-left" aria-hidden="true"></i>'. $prev;
- $prv_link = esc_url( add_query_arg('region_page', $s_page-1, $link ));
- if ( $ct_prev ) echo "\n<a class=\"nav-previous\" href=\"$prv_link\">$prev</a>\n";
- echo "</div></div>\n";
- }
- // Insert region into post links
- add_filter('post_link', 'tg_add_region', 999, 3 );
- function tg_add_region( $link, $post, $leavename) {
- global $region;
- $link = str_replace('.com/', ".com/$region/", $link );
- return $link;
- }
- // Insert region into post links
- add_filter('post_link', 'tg_add_region', 999, 3 );
- function tg_add_region( $link, $post, $leavename) {
- global $region;
- $cats = wp_get_post_categories( $post->ID, array('fields'=>'ids',));
- if ( in_array( 123, $cats )) $region = 'benelux';
- if ( in_array( 124, $cats )) $region = 'international';
- if ( null == $region ) $region = 'international';
- $link = str_replace('.com/', ".com/$region/", $link );
- return $link;
- }
- // Add region category to main queries
- add_action('pre_get_posts', 'tg_set_region');
- function tg_set_region( $query ) {
- if ( get_option('page_on_front') == $query->get('page_id')) return;
- if ( !is_admin() && $query->is_main_query()) {
- global $region;
- $explode = explode('/', $_SERVER['REQUEST_URI']);
- $cat = $query->get('category_name');
- $region = $explode[1];
- if ( ! in_array( $region, array('benelux','international',))) $region = 'international';
- if ( '' != $cat ) $cat .= '+' . $region;
- else $cat = $region;
- $query->set('category_name', $cat);
- }
- }
- @ini_set( 'upload_max_size' , '64M' );
- @ini_set( 'post_max_size', '64M');
- @ini_set( 'max_execution_time', '300' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement