function custom_posts_per_page( $query ) {
if ( is_admin() || ! $query->is_main_query() ) {
return;
}
if ( $query->is_search() ) {
$query->set( 'posts_per_page', 12 );
}
if ( $query->is_category() ) {
if ( wp_is_mobile() ) {
$query->set( 'posts_per_page', 5 );
} else {
$query->set( 'posts_per_page', 10 );
}
}//endif
}//function
add_action( 'pre_get_posts', 'custom_posts_per_page' );
$str = "attachment=12345";
list($number) = sscanf($str, "attachment=%d");
echo $number; // 12345
SELECT post_name FROM wp_posts WHERE post_name = 'труляля-765' AND post_type = 'post' AND ID != 0 LIMIT 1
'post_name' => '',
function has_children()
{
return (bool)get_pages(array(
'child_of' => get_the_ID(),
'number' => 1
));
}
var target = $('.elem');
var targetPos = target.offset().top;
var winHeight = $(window).height();
var scrollToElem = targetPos - winHeight;
$(window).scroll(function(){
var winScrollTop = $(this).scrollTop();
if(winScrollTop > scrollToElem){
//сработает когда пользователь доскроллит к элементу с классом .elem
}
});