从多个主题中选择用户(PHP)的动态主题
我想将动态主题添加到我的PHP网站上,该主题将从用户的数据库中存储,下次用户使用该网站应显示该主题,该主题已由用户选择并保存到数据库中。我到处都在搜索,但由于我是PHP的新手,但没有获得逻辑和解决方案。请帮助我。
I want to add dynamic themes to my php website which will be stored from the user's database and next time when user uses the website that theme should be shown which has been selected by user and saved to database. I have searched everywhere but not getting the logic and solution as I am new to php. Please help me out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于摘要的沙箱,下面的片段将在此处丢弃错误,但如果复制到您自己的文档中,则可以使用。
不同主题的选择机制可以是超链接,按钮,无线电按钮或下拉菜单,如下所示。当然,需要修改活动的侦听器,以适合任何选择的机制。
当用户制作选择时,使用
setItem
将关联的值保存到localstorage。加载页面后,检查了localStorage,并为样式表分配了正确的URL。Update
我忽略了上述代码使用的四个样式表,这些样式表按
选择
菜单中的选项命名,例如:Modern.css
&dark.css
等。使用简单setPath
函数设置样式表目录的路径,该功能将路径硬编码为返回字符串(更改以适合自己的环境)The snippet below will throw an error here because of the sandboxing of the snippet but will work if copied to your own document.
The selection mechanism for different themes could be hyperlinks, buttons, radio buttons or a dropdown menu as shown here. The event listener would need to be modified to suit whatever mechanism chosen of course.
When the user makes a selection the value associated is saved to localStorage using
setItem
. When the page is loaded the localStorage is checked and the stylesheet is assigned the correct url.update
I neglected to state that the above code uses four stylesheets that are named as per the options in the
select
menu - eg:modern.css
&dark.css
etc. The path to the stylesheet directory is set with the simplesetpath
function that has the path hardcoded into the return string ( change to suit own environment )