Small thumbnails on home

This commit is contained in:
2019-06-06 04:08:42 +02:00
parent 2450fc6da5
commit 647e333a16
14 changed files with 575 additions and 117 deletions

View File

@@ -28,7 +28,8 @@ if (function_exists('add_theme_support')) {
add_image_size('large', 700, '', true); // Large Thumbnail
add_image_size('medium', 250, '', true); // Medium Thumbnail
add_image_size('small', 120, '', true); // Small Thumbnail
add_image_size('home-thumbnail', 1024, 1024, true); // Custom Thumbnail Size call using the_post_thumbnail('home-thumbnail');
add_image_size('home-big-thumbnail', 1024, 1024, true); // Custom Thumbnail Size call using the_post_thumbnail('home-thumbnail');
add_image_size('home-small-thumbnail', 256, 256, true); // Custom Thumbnail Size call using the_post_thumbnail('home-thumbnail');
// Add Support for Custom Backgrounds - Uncomment below if you're going to use
/*add_theme_support('custom-background', array(
@@ -96,7 +97,7 @@ function dis2019_header_scripts()
wp_register_script('conditionizr', get_template_directory_uri() . '/js/lib/conditionizr-4.3.0.min.js', array(), '4.3.0'); // Conditionizr
wp_enqueue_script('conditionizr'); // Enqueue it!
wp_register_script('modernizr', get_template_directory_uri() . '/js/lib/modernizr-2.7.1.min.js', array(), '2.7.1'); // Modernizr
wp_register_script('modernizr', get_template_directory_uri() . '/js/lib/modernizr-custom.js', array(), '2.7.1'); // Modernizr
wp_enqueue_script('modernizr'); // Enqueue it!
wp_register_script('simpler-sidebar', get_template_directory_uri() . '/js/lib/jquery.simpler-sidebar.min.js', array('jquery'), '2.2.5'); // Modernizr
@@ -411,39 +412,70 @@ function misha_my_load_more_scripts()
add_action('wp_enqueue_scripts', 'misha_my_load_more_scripts');
function misha_loadmore_ajax_handler()
{
// prepare our arguments for the query
$args = json_decode(stripslashes($_POST['query']), true);
$args['paged'] = $_POST['page'] + 1; // we need next page to be loaded
$args['post_status'] = 'publish';
$args['posts_per_page'] = 6;
//First, define your desired offset...
$offset = 14;
//Next, determine how many posts per page you want (we'll use WordPress's settings)
$ppp = get_option('posts_per_page');
//Next, detect and handle pagination...
//Manually determine page query offset (offset + current page (minus one) x posts per page)
$args['offset'] = $offset + (($_POST['page'] - 1) * $ppp);
// it is always better to use WP_Query but not here
query_posts($args);
get_template_part('loop');
// if( have_posts() ) :
// run the loop
// while( have_posts() ): the_post();
// look into your theme code how the posts are inserted, but you can use your own HTML of course
// do you remember? - my example is adapted for Twenty Seventeen theme
// get_template_part( 'template-parts/post/content', get_post_format() );
// get_template_part('loop');
// for the test purposes comment the line above and uncomment the below one
// the_title();
// endwhile;
// endif;
die; // here we exit the script and even no wp_reset_query() required!
}
add_action('wp_ajax_loadmore', 'misha_loadmore_ajax_handler'); // wp_ajax_{action}
add_action('wp_ajax_nopriv_loadmore', 'misha_loadmore_ajax_handler'); // wp_ajax_nopriv_{action}
/* -------------------- different number of posts on home ------------------- */
add_action('pre_get_posts', 'dis_2019_more_posts_on_home', 1 );
function dis_2019_more_posts_on_home(&$query) {
//Before anything else, make sure this is the right query...
if ( ! $query->is_home() ) {
return;
}
//set post_per_page if it's homepage
if (! $query->is_paged ) {
$query->set('posts_per_page',14);
}
else {
return;
}
}
// add_filter('found_posts', 'myprefix_adjust_offset_pagination', 1, 2 );
// function myprefix_adjust_offset_pagination($found_posts, $query) {
// //Define our offset again...
// $offset = 2;
// //Ensure we're modifying the right query object...
// if ( $query->is_home() ) {
// //Reduce WordPress's found_posts count by the offset...
// return $found_posts - $offset;
// }
// return $found_posts;
// }
/*------------------------------------*\
Actions + Filters + ShortCodes
\*------------------------------------*/