下面由WordPress教程栏目给大家介绍WordPress只允许游客浏览指定分类的文章的设置方法,希望对需要的朋友有所帮助!
有童鞋问,如何实现未登录用户只能浏览指定的分类文章,这里提供一下方法。
WordPress只允许游客浏览指定分类的文章只允许游客浏览指定分类的文章
网上可以找到类似的代码:
//template_redirect动作钩子是一定会执行的,所以用这个钩子对全站有效 add_action( 'template_redirect', 'ashuwp_show_only_login', 0 ); function ashuwp_show_only_login(){ //判断登录,about页面就允许访问 if( !is_page('about') && !is_user_logged_in() ){ auth_redirect(); //跳转到登录页面 exit(); } }
代码源自:www.ashuwp.com
原代码只允许未登录者访问指定的页面或者直接跳转到登录。
简单改一下,加个判断in_category,只允许访问指定分类的归档页面和文章。
// 首页和指定分类文章可以访问 add_action( 'template_redirect', 'ashuwp_show_only_login', 0 ); function ashuwp_show_only_login(){ //判断登录,只允许访问ID为3和2的分类文章 if( !in_category( array( 3,2 ) ) && !is_home() && !is_user_logged_in() ){ auth_redirect(); //跳转到登录页面 exit(); } }
默认未登录者只允许访问网站首页和分类id为3和2的分类归档页面和文章,否则跳转到登录页面。
把 !in_category 前面的感叹号去掉改成 in_category,则正好相反,访问分类ID为3和2的分类文章跳转到登录,其它文章可以正常访问。
代码添加到主题函数模板functions.php中。
以上是WordPress如何只允许游客浏览指定分类的文章的详细内容。更多信息请关注PHP中文网其他相关文章!

WordPressiser-FrightlyDuetLoitsIntuitiveInterfaceAndcms,whosparateContentFromDesign.itoffersArichTextedextEditorforeasyContentCreationAndialibraryFororRaryFororRory.itsflexeNhangedBancedBynhangedBynHangedBynumereNumerSandeMesandPlugins,elloverSandplugins,elloverOverUseCanimpActpercrance

1)ITSUPPORTSE-CommerceWithPluginSlikeWooCommerce,允许ProductManagementAndAndPaymentProcessing.2)ITSERVESASASASACMSACMSACMSMSACMSMSACMSMASTRATATEBLOGS,增强SeoAndEngagement.3)

WordPressIsnotIdeAlforHigh-TrafficWebsites,customandCompleXapplications,Security-SensitiveApplications,Real-TimedataProcessing,AndhighlyCustomizedUserInterfaces.forhigh-Trafficsites,USENENEXT.JSORXOLCT.JSORXORX.JSORCUSTOMSOMOLTICTS; forCompleXapplications; forcomplexapplications; optfordjangoorrub

Yes,youcanbuildablogwithWordPress.1)ChoosebetweenWordPress.comforbeginnersorWordPress.orgformorecontrol.2)Selectathemetopersonalizeyourblog'slook.3)Usepluginstoenhancefunctionality,likeSEOandsocialmediaintegration.4)Customizeyourthemewithsimplecodetw

WordPressCanbeseCureifManagedProperly.1)keepthewordPressCoreUpdatedTopatchVulnerabilities.2)vetandupdatepluginsandthemesfromreputables.3)EnforcestrongpasseTSandusetWordssandusetWordwordwo-factorauthenticaliation.4)

WordPressCanbuildVariousTypesofwebsites:1)个人博客,EasyTosetUpWithTheMesandPlugins.2)BusinessWebsites,使用drag-and-dropbuilders.3)e-commercePlatforms,forwoocommerceforsemcommerceforseameamseamelesssites.4)communitySites.4)conduction.4)使用bbudicatipration

WordPressisapowerfulCMSwithsignificantadvantagesandchallenges.1)It'suser-friendlyandcustomizable,idealforbeginners.2)Itsflexibilitycanleadtositebloatandsecurityissuesifnotmanagedproperly.3)Regularupdatesandperformanceoptimizationsarenecessarytomainta

WordPressExcccelineaseeandaDaptability,MakeitiTidealForBeginnersandsMallTomedium-SizedBusinesses.1)siseofuse:wordpressisuser-Frylyly.2)安全:drupalleadswithstrongsecurityfeatures.3)性能:performance:performance formation:ghandoffersefersefersefersefersefersefersefersexcellentperformanceeduetonodeutonode.jsorscor.jssor.jjsy.jjsy.jjsy.4)4)


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

WebStorm Mac版
好用的JavaScript开发工具

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

SublimeText3汉化版
中文版,非常好用