feat: customize articles per page for article archives
Added a function to set the number of articles displayed per page to 9 for the 'article' post type archive page. This enhances the user experience by providing a consistent number of posts per page when viewing article archives. Also refactored code for better readability and added missing newlines.
This commit is contained in:
parent
9ece16c681
commit
640879a2b9
1 changed files with 22 additions and 3 deletions
|
@ -750,6 +750,7 @@ function tcpdf_missing_notice()
|
||||||
echo '</p></div>';
|
echo '</p></div>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
add_action('admin_notices', 'tcpdf_missing_notice');
|
add_action('admin_notices', 'tcpdf_missing_notice');
|
||||||
|
|
||||||
// Add custom endpoint for PDF download
|
// Add custom endpoint for PDF download
|
||||||
|
@ -757,6 +758,7 @@ function add_pdf_download_endpoint()
|
||||||
{
|
{
|
||||||
add_rewrite_rule('^download-pdf/([0-9]+)/?', 'index.php?download_pdf=$matches[1]', 'top');
|
add_rewrite_rule('^download-pdf/([0-9]+)/?', 'index.php?download_pdf=$matches[1]', 'top');
|
||||||
}
|
}
|
||||||
|
|
||||||
add_action('init', 'add_pdf_download_endpoint');
|
add_action('init', 'add_pdf_download_endpoint');
|
||||||
|
|
||||||
// Add query vars for PDF download
|
// Add query vars for PDF download
|
||||||
|
@ -765,6 +767,7 @@ function add_pdf_query_vars($vars)
|
||||||
$vars[] = 'download_pdf';
|
$vars[] = 'download_pdf';
|
||||||
return $vars;
|
return $vars;
|
||||||
}
|
}
|
||||||
|
|
||||||
add_filter('query_vars', 'add_pdf_query_vars');
|
add_filter('query_vars', 'add_pdf_query_vars');
|
||||||
|
|
||||||
// Handle PDF download
|
// Handle PDF download
|
||||||
|
@ -826,15 +829,19 @@ function handle_pdf_download()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
add_action('template_redirect', 'handle_pdf_download');
|
add_action('template_redirect', 'handle_pdf_download');
|
||||||
|
|
||||||
function allow_more_uploads($mime_types) {
|
function allow_more_uploads($mime_types)
|
||||||
|
{
|
||||||
$mime_types['py'] = 'text/x-python';
|
$mime_types['py'] = 'text/x-python';
|
||||||
return $mime_types;
|
return $mime_types;
|
||||||
}
|
}
|
||||||
|
|
||||||
add_filter('upload_mimes', 'allow_more_uploads');
|
add_filter('upload_mimes', 'allow_more_uploads');
|
||||||
|
|
||||||
function disable_real_mime_check($data, $file, $filename, $mimes) {
|
function disable_real_mime_check($data, $file, $filename, $mimes)
|
||||||
|
{
|
||||||
$wp_filetype = wp_check_filetype($filename, $mimes);
|
$wp_filetype = wp_check_filetype($filename, $mimes);
|
||||||
$ext = $wp_filetype['ext'];
|
$ext = $wp_filetype['ext'];
|
||||||
$type = $wp_filetype['type'];
|
$type = $wp_filetype['type'];
|
||||||
|
@ -842,4 +849,16 @@ function disable_real_mime_check($data, $file, $filename, $mimes) {
|
||||||
|
|
||||||
return compact('ext', 'type', 'proper_filename');
|
return compact('ext', 'type', 'proper_filename');
|
||||||
}
|
}
|
||||||
add_filter('wp_check_filetype_and_ext', 'disable_real_mime_check', 10, 4);
|
|
||||||
|
add_filter('wp_check_filetype_and_ext', 'disable_real_mime_check', 10, 4);
|
||||||
|
|
||||||
|
function custom_articles_per_page($query)
|
||||||
|
{
|
||||||
|
if (!is_admin() && $query->is_main_query()) {
|
||||||
|
if (is_post_type_archive('article')) {
|
||||||
|
$query->set('posts_per_page', 9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
add_action('pre_get_posts', 'custom_articles_per_page');
|
||||||
|
|
Loading…
Reference in a new issue