我想分享我在全局和页面特定级别使用On/Off
值编写的PHP脚本。
整体而言,脚本运行良好,因此没有问题,它正常工作
。我只是想分享它,看看是否有人会以不同或更好的方式构建它。
基本上我期待"美化"声明。不确定它们是否可以更快或更快,因为它似乎已经是真的 快速但优化它会很棒。
有关if / elseif语句的注意事项:
ON/OFF
ON/OFF
以下是代码:
<?php
/**
* The Page List System for USLegal
*
* This system uses @wp_list_pages function: https://developer.wordpress.org/reference/functions/wp_list_pages/
* This system has been enhanced by the pagelist plugin: https://wordpress.org/plugins/page-list/
* [pagelist] - hierarchical tree of all pages on site (useful to show sitemap of the site);
* [subpages] - hierarchical tree of subpages to the current page;
* [siblings] - hierarchical tree of sibling pages to the current page;
* [pagelist_ext] - list of pages with featured image and with excerpt;
*
* @package WordPress
* @subpackage USLegal
* @since USLegal 1.0
*/
?>
<?php if( get_field('page_list_global_onoff', 'option') ) :
/**
*
* Does the Page List system have a value, if so run if/else to determine the global value of On/Off. If On check to see if * at the Page Settings level if it is On/Off. If neither has a value then by default show the Page List.
*
*/
?>
<?php if (get_field('page_list_global_onoff', 'option') == 'on') :
/**
*
* Page List global value equals ON, show Page List but check first to make sure it is not disabled on a specific page
* Default to yes if no value exist at the Page level.
*
*/
?>
<?php if (get_field('pagelist_page_onoff') ) :
/**
*
* Does a value exist for Page List on the Page Specific Level. If not skip on/off and just show Page List
* if turned on globally.
*
*/
?>
<?php if (get_field('pagelist_page_onoff') == 'on') :
/**
*
* Field values exist for PageList. The global value is either defaulted to yes or yes has been enbabled and at the Page
* Level the Page has been set to ON. Let's show the Page List.
*
*/
?>
<?php include get_template_directory() . '/inc/pagelist-output.php'; ?>
<?php elseif (get_field('pagelist_page_onoff') == 'off') :
/**
*
* Page Level Field value is set to off. If global setting is ON but Page level value is OFF then nothing will be shown.
* Placeholder for OFF
*
*/
?>
<?php endif; ?>
<?php else : ?>
<?php include get_template_directory() . '/inc/pagelist-output.php'; ?>
<?php endif; ?>
<?php elseif (get_field('page_list_global_onoff', 'option') == 'off') :
/**
*
* Page List is turned off globally. Nothing will show at all across the site. Can't override this at the page level. If you turn it off globally it is assumed
* that you are not interested in using it at all for this site. However if value is ON you then control what pages you want it on and what pages you don't. We
* see this as a better way to control where you want it and where you don't.
*
*/
?>
<?php endif; ?>
<?php elseif (get_field('pagelist_page_onoff') ) :
/**
*
* Does a value exist for Page List on the Page Specific Level. If not skip on/off and just show Page List
* if turned on globally.
*
*/
?>
<?php if (get_field('pagelist_page_onoff') == 'on') :
/**
*
* Field values exist for PageList. The global value is either defaulted to yes or yes has been enbabled and at the Page
* Level the Page has been set to ON. Let's show the Page List.
*
*/
?>
<?php include get_template_directory() . '/inc/pagelist-output.php'; ?>
<?php elseif (get_field('pagelist_page_onoff') == 'off') :
/**
*
* Page Level Field value is set to off. If global setting is ON but Page level value is OFF then nothing will be shown.
* Placeholder for OFF
*
*/
?>
<?php endif; ?>
<?php else : ?>
<?php include get_template_directory() . '/inc/pagelist-output.php'; ?>
<?php endif; ?>
<?php if (get_field('pagelist_page_onoff') == 'onoverride') :
/**
*
* A Page Specific ON - Override that will override the global OFF Page List when needed. Separated from main if/else for
* the purposes of quicker loading instead of having to call the global on/off value it skips that and looks directly at
* the page value value. if it is ON - Override then it will show.
*
*/
?>
<?php include get_template_directory() . '/inc/pagelist-output.php'; ?>
<?php else : ?>
<?php endif; ?>
===============&GT;&GT;
感谢您抽出宝贵时间来审核并协助我。随着我的编码越来越多,我只是想让我的代码变得更漂亮。