mirror of
https://gh.wpcy.net/https://github.com/WordPressUtilities/WPUInstaller.git
synced 2026-05-06 19:52:36 +08:00
90 lines
2.8 KiB
PHP
90 lines
2.8 KiB
PHP
<?php
|
|
/*
|
|
Plugin Name: [wpuprojectname] Page News
|
|
Description: Handle page News
|
|
*/
|
|
|
|
/* ----------------------------------------------------------
|
|
Add Page
|
|
---------------------------------------------------------- */
|
|
|
|
add_filter('wputh_pages_site', 'wpuprojectid_pagenews_wputh_set_pages_site');
|
|
function wpuprojectid_pagenews_wputh_set_pages_site($pages_site) {
|
|
$pages_site['news__page_id'] = array(
|
|
'post_title' => 'News',
|
|
'page_template' => "page-news.php",
|
|
'disable_items' => array()
|
|
);
|
|
return $pages_site;
|
|
}
|
|
|
|
/* ----------------------------------------------------------
|
|
Add current class to news menu item on single posts & categories
|
|
---------------------------------------------------------- */
|
|
|
|
add_filter('nav_menu_css_class', function ($classes, $item) {
|
|
if ($item->object_id == wpuprojectid_pagenews_get_id() && (is_singular('post') || is_category())) {
|
|
$classes[] = 'current-menu-item';
|
|
}
|
|
return $classes;
|
|
}, 10, 2);
|
|
|
|
/* ----------------------------------------------------------
|
|
ACF fields
|
|
---------------------------------------------------------- */
|
|
|
|
add_filter('wpuprojectid_master_header_acf_location', function ($acf_location, $args) {
|
|
$acf_location[] = array(
|
|
array(
|
|
'param' => 'page_template',
|
|
'operator' => '==',
|
|
'value' => 'page-news.php'
|
|
)
|
|
);
|
|
return $acf_location;
|
|
}, 10, 2);
|
|
|
|
/* ----------------------------------------------------------
|
|
Get page news
|
|
---------------------------------------------------------- */
|
|
|
|
function wpuprojectid_pagenews_get_id() {
|
|
$news_page_id = get_option('news__page_id');
|
|
if (function_exists('pll_get_post')) {
|
|
$news_page_id = pll_get_post($news_page_id);
|
|
}
|
|
return $news_page_id;
|
|
}
|
|
|
|
function wpuprojectid_pagenews_get_url() {
|
|
$news_page_id = wpuprojectid_pagenews_get_id();
|
|
if (!$news_page_id) {
|
|
return home_url();
|
|
}
|
|
return get_permalink($news_page_id);
|
|
}
|
|
|
|
/* ----------------------------------------------------------
|
|
Redirect Year/Month/Day archives to news page
|
|
---------------------------------------------------------- */
|
|
|
|
add_action('template_redirect', function () {
|
|
if (is_year() || is_month() || is_day()) {
|
|
wp_redirect(wpuprojectid_pagenews_get_url());
|
|
exit;
|
|
}
|
|
});
|
|
|
|
/* ----------------------------------------------------------
|
|
Breadcrumb on News Page
|
|
---------------------------------------------------------- */
|
|
|
|
add_filter('wputh_get_breadcrumbs__after_home', function ($elements_ariane) {
|
|
if (is_category() || is_singular('post')) {
|
|
$elements_ariane['archive-news'] = array(
|
|
'name' => get_the_title(wpuprojectid_pagenews_get_id()),
|
|
'link' => wpuprojectid_pagenews_get_url()
|
|
);
|
|
}
|
|
return $elements_ariane;
|
|
}, 10, 1);
|