Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

WordPress only allows visitors to browse specified classified articles.

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how WordPress only allows visitors to browse designated classified articles. I believe most people don't know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's learn about it.

Below by the WordPress tutorial column to introduce you WordPress only allows visitors to browse the specified categories of articles setting method, I hope to help friends in need!

There are children's shoes asked, how to achieve that unlogged-in users can only browse the specified classified articles, here is a method.

WordPress only allows visitors to browse articles with specified categories.

Similar codes can be found online:

/ / the template_redirect action hook must be executed, so using this hook is valid for the whole site add_action ('template_redirect',' ashuwp_show_only_login', 0); function ashuwp_show_only_login () {/ / determines login, the about page is allowed to access if (! is_page ('about') & &! is_user_logged_in ()) {auth_redirect (); / / Jump to the login page exit ();}}

The code comes from: www.ashuwp.com

The original code only allows those who are not logged in to access the specified page or jump directly to login.

Simply change, add a judgment in_category, only allow access to the archive page and articles of the specified category.

/ / Home page and specified classified articles can visit add_action ('template_redirect',' ashuwp_show_only_login', 0); function ashuwp_show_only_login () {/ / determine login, only allow access to classified articles with ID of 3 and 2, if (! in_category (array (3dome 2)) & &! is_home () &! is_user_logged_in () {auth_redirect () / / Jump to login page exit ();}}

By default, non-logins are only allowed to visit the home page of the site and classified archive pages and articles with a category id of 3 and 2, otherwise jump to the login page.

Remove the exclamation point in front of in_category and change it to in_category. On the contrary, access to classified articles with categories ID 3 and 2 jumps to login, and other articles can be accessed normally.

The code is added to the theme function template functions.php.

The above is all the content of the method that WordPress only allows visitors to browse the specified classified articles, thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report