Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save janisdonis/5778ec708a4ac25673a575cf811a84b7 to your computer and use it in GitHub Desktop.
Save janisdonis/5778ec708a4ac25673a575cf811a84b7 to your computer and use it in GitHub Desktop.
theme.php
<?php
/**
* Easyhome styles.
* Easyhome css/js assets.
*/
add_action('init', 'my_register_styles');
function my_register_styles() {
}
function baltic_enqueue_styles() {
wp_enqueue_style('bxslider');
wp_enqueue_style('main');
}
add_action('wp_enqueue_scripts', 'baltic_enqueue_styles');
function baltic_adding_scripts() {
}
add_action( 'wp_enqueue_scripts', 'baltic_adding_scripts' );
add_theme_support( 'post-thumbnails' );
add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10, 3 );
function remove_thumbnail_dimensions( $html, $post_id, $post_image_id ) {
$html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
return $html;
}
/**
* Easyhome menus.
* Easyhome side menu.
*/
function register_my_menus() {
register_nav_menus(
array(
'main_navigation' => __( 'Main menu' )
)
);
}
add_action( 'init', 'register_my_menus' );
require_once('wp_bootstrap_navwalker.php');
/**
* Easyhome images sizes.
* Global images sizes.
*/
add_image_size('project_thumb', 363, 192, array( 'center', 'center' ) );
add_image_size('project_gallery', 1119, 480, array( 'center', 'center' ) );
add_image_size('map_thumb', 215, 139, array( 'center', 'center' ) );
add_image_size('slider', 620, 520, array( 'center', 'center' ) );
if ( ! current_user_can( 'manage_options' ) ) {
show_admin_bar( false );
}
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $excerpt;
}
function content($limit) {
$content = explode(' ', get_the_content(), $limit);
if (count($content)>=$limit) {
array_pop($content);
$content = implode(" ",$content).'...';
} else {
$content = implode(" ",$content);
}
$content = preg_replace('/\[.+\]/','', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]&gt;', $content);
return $content;
}
add_filter( 'wp_nav_menu_objects', 'add_has_children_to_nav_items' );
function add_has_children_to_nav_items( $items )
{
$parents = wp_list_pluck( $items, 'menu_item_parent');
foreach ( $items as $item )
in_array( $item->ID, $parents ) && $item->classes[] = 'has-children';
return $items;
}
function wpse_remove_empty_links( $menu ) {
return str_replace( '<a href="#">', '', $menu );
}
add_filter( 'wp_nav_menu_items', 'wpse_remove_empty_links' );
class WPSE_78121_Sublevel_Walker extends Walker_Nav_Menu
{
function start_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent<ul class='sub-menu'>\n";
}
function end_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat("\t", $depth);
$output .= "$indent</ul>\n";
}
}
if( function_exists('acf_add_options_page') ) {
acf_add_options_page();
}
function SearchFilter($query)
{
if (($query->is_search)&&(!is_admin())) {
$query->set('post_type', 'post');
}
return $query;
}
add_filter('pre_get_posts','SearchFilter');
//attach our function to the wp_pagenavi filter
add_filter( 'wp_pagenavi', 'wd_pagination', 10, 2 );
//customize the PageNavi HTML before it is output
function wd_pagination($html) {
$out = '';
//wrap a's and span's in li's
$out = str_replace("<a","<li><a",$html);
$out = str_replace("</a>","</a></li>",$out);
$out = str_replace("<span","<li><span",$out);
$out = str_replace("</span>","</span></li>",$out);
$out = str_replace("<div class='wp-pagenavi'>","",$out);
$out = str_replace("</div>","",$out);
return '<div class="pagination-box">
<ul class="pagination clearfix">'.$out.'</ul>
</div>';
}
add_filter('pll_get_post_types', 'unset_cpt_pll', 10, 2);
function unset_cpt_pll( $post_types, $is_settings ) {
unset($post_types['acf-field-group']);
return $post_types;
}
function get_language_name($code=''){
global $sitepress;
$details = $sitepress->get_language_details($code);
$language_name = $details['english_name'];
return $language_name;
}
function my_acf_init() {
acf_update_setting('google_api_key', 'AIzaSyC9_T0AaU72Qyr0uUif34QzB0phCDDXAFg');
}
add_action('acf/init', 'my_acf_init');
$storeData = [];
while (have_posts()) : the_post();
$location = get_field('location');
$price = get_field('price');
$rentprice = get_field('rent_price');
$area_count = get_field('area');
$floors_count = get_field('floors');
$rooms_count = get_field('rooms');
$thumb = get_the_post_thumbnail_url(get_the_ID(),'map_thumb');
$marker_icon = "".get_bloginfo( 'stylesheet_directory' )."/app/assets/img/map-marker.png";
if( has_term( array('2'), 'property' ) ):
$floors = "<li>". __('Stāvi','easyhome') .": <strong>".$floors_count."</strong></li>";
else:
$floors = "<li>". __('Stāvs','easyhome') .": <strong>".$floors_count."</strong></li>";
endif;
$area = "<li>". __('Platība','easyhome') .": <strong>".$area_count."</strong></li>";
$rooms = "<li>". __('Istabu skaits','easyhome') .": <strong>".$rooms_count."</strong></li>";
$storeData[] = [
'title' => apply_filters('the_title', $post->post_title),
'iconImage' => $marker_icon,
'coords' => array('lat' => floatval($location['lat']), 'lng' => floatval($location['lng'])),
'content' => "<div class='marker-pop-object'><div class='thumb'><img src='".$thumb."'>
<div class='bottom-info'>
<div class='price d-flex align-items-center justify-content-between'>
<ul>
<li class='total'>".$price." EUR</li>
<li class='meter'>".$area_count." m²</li>
</ul>
</div>
</div>
</div>
<h4 class='object-location'>".apply_filters('the_title', $post->post_title)."</span></h4>
<ul class='details d-flex justify-content-center flex-wrap'>
".$rooms."
".$floors."
".$area."
</ul>
</div>"
];
endwhile;
function pw_load_scripts() {
global $post;
global $wp_query;
wp_enqueue_script('custom', get_template_directory_uri() . '/app/assets/js/custom.js');
wp_localize_script( 'custom', 'window.storeData', $storeData );
}
add_action('wp_enqueue_scripts', 'pw_load_scripts');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment