$nav = wp_nav_menu( array(
'menu' => '',
'container' => 'nav',
'container_class' => 'menu',
'container_id' => '',
'menu_class' => '',
'menu_id' => '',
'echo' => false,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul>%3$s</ul>',
'depth' => 0,
'walker' => new My_Walker_Nav_Menu(),
) );
echo preg_replace('/(<a[^>]*>)(.*?)(<\/a)/i', '$1<span>$2</span>$3', $nav);
class Wpp_Pf_Endpoints {
function __construct() {
add_action( 'init', array( __CLASS__, 'add_endpoints' ) );
add_action( 'template_include', array( __CLASS__, 'change_template' ) );
}
/**
* Add template for end_point
*
* @param $template
*
* @return mixed
*/
public static function change_template( $template ) {
$points = self::endpoint_settings();
$point = self::get_current_endpoint();
if ( empty( $point ) ) {
return $template;
}
if ( get_query_var( $point, false ) !== false ) {
$template_name = $points[ $point ]['template'];
if ( file_exists( $template_name ) ) {
return $template_name;
}
}
return $template;
}
/**
* Add endpoints for query vars.
*/
public static function add_endpoints() {
$args = self::endpoint_settings();
foreach ( $args as $one_point => $val ) {
if ( ! empty( $one_point ) ) {
$mask = ! empty( $val['places'] ) ? esc_attr( $val['places'] ) : EP_ROOT;
add_rewrite_endpoint( $one_point, $mask );
}
}
}
/**
* Get page title for an endpoint.
*
* @return array
*/
public static function endpoint_settings() {
$end_points = [];
return apply_filters( 'wpp_pf_endpoints_args', $end_points );
}
/**
* Get query current active query var.
*
* @return string
*/
public static function get_current_endpoint() {
global $wp;
$args = self::endpoint_settings();
foreach ( $args as $key => $value ) {
if ( isset( $wp->query_vars[ $key ] ) ) {
return $key;
}
}
return false;
}
}
new Wpp_Pf_Endpoints();
function add_my_test_point( $end_points ) {
$end_points['custom-product-view'] = array(
'template' => __DIR__ . '/template.php',
'places' => EP_ROOT
);
return $end_points;
}
add_filter( 'wpp_pf_endpoints_args', 'add_my_test_point' );
$n = 0;
foreach ( $posts as $post ) {
setup_postdata( $post );
$class_img = $n % 2 === 1 ? 'class-1' : 'class-2';
$class_post = $n % 2 === 1 ? '' : ' offset-md-2 offset-lg-4';
?>
<div class="col-md-5 col-lg-4<?php echo $class_post; ?>">
<div class="about">
<?php the_post_thumbnail( 'post-thumbnail', array( 'class' => $class_img ) ); ?>
<h3 class="h3 about__heading"><?php the_title(); ?></h3>
<p class="about__descr"><?php the_field( 'intro_descr' ) ?></p>
</div>
</div>
<?php
$n ++;
}
<input class="myclass" placeholder="Поиск" type="text" value="" name="s" id="search">
jQuery(function ($) {
$(document).on('keyup', '#search', function () {
var $val = $(this).val(),
$length = $val.length,
$data = {
action: 'wpp_search',
security: WppAjax.security,
string: $val
};
if ($length >= 3) {
$.post(WppAjax.ajax_url, $data, function ($response) {
if ($response.success) {
//$response.data.result - тут лежит результат поиска
} else {
// бла бла бла обработка ощшибок
}
});
}
});
})
add_action( 'wp_ajax_wpp_search', 'wpp_search' );
add_action( 'wp_ajax_nopriv_wpp_search', 'wpp_search' );
function wpp_search() {
check_ajax_referer( 'wpp-string', 'security' );
$string = sanitize_text_field( $_POST['string'] );
$out = '';
$errors = [];
if ( ! empty( $string ) ) {
$q = new WP_Query(
array(
's' => $string
)
);
if ( $q->have_posts() ) {
ob_start();
while ( $q->have_posts() ) : $q->the_post();
//тут стандартный вывод постов
endwhile;
$out .= ob_get_clean();
} else {
$out .= __( 'Не найдено результатов по запросу -', 'txt' ) . sprintf( '<b><i>%s</i></b>', $string );
}
} else {
$errors = __( 'Поисковый запрос пуст или не корректен', 'txt' );
}
if ( empty( $errors ) ) {
wp_send_json_success( array( 'result' => $out ) );
} else {
wp_send_json_error( array( 'result' => $errors ) );
}
}
add_action( 'wp_enqueue_scripts', 'wpp_assets' );
function wpp_assets() {
wp_enqueue_script( 'ajax', get_template_directory_uri() . '/assets/js/script.js', array( 'jquery' ), '1.0.0', true );
wp_localize_script( 'ajax', 'WppAjax', array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'security' => wp_create_nonce( 'wpp-string' )
) );
}