简体   繁体   English

合并PHP文件和页面-Wordpress

[英]Combine PHP file and page - Wordpress

I am just wrapping up a long term project I have done for a company, but I am really stuck at this point. 我只是结束了我为一家公司所做的长期项目,但是我真的被困在这一点上。

I have a cool little page here: http://hagen-etc.com/test/buy/ It is basically showing all their retailers in the right hand side div while you can narrow down the results with the different options on the left side (Javascript based). 我在这里有一个很酷的小页面: http : //hagen-etc.com/test/buy/它基本上在右侧div中显示了所有零售商,而您可以使用左侧的不同选项来缩小结果范围(基于Javascript)。

Everything works just fine, but I have run into a problem. 一切正常,但我遇到了问题。 The thing is, the person I am developing the site for has absolutely zero knowledge about programming and website managment etc, and therefore I need a smart way for her to change it. 问题是,我要为其开发网站的人员对编程和网站管理等方面的知识绝对为零,因此我需要一种灵巧的方式让她进行更改。

I have simplified the procedures several other places on the website using shortcodes with Visual Composer and Shortcoder-plugin. 我已将简短代码与Visual Composer和Shortcoder-plugin一起使用简化了网站上的程序。

The problem here is, The Javascript is in footer.php while the actual content is on a Page in the dashboard. 这里的问题是,Javascript位于footer.php中,而实际内容位于仪表板中的Page上。 How do I make a smart solution so she can easily manage this in a blink of an eye? 我该如何制定一个明智的解决方案,以便她可以在眨眼之间轻松解决? You can take a look at the source code in the link above if you would like to. 您可以根据需要在上面的链接中查看源代码。

Would love to get some help on this because I am having a hard time figuring out a solution. 很想在此方面获得帮助,因为我很难找到解决方案。 Maybe a plugin can even do this? 也许插件甚至可以做到这一点?

The different areas, countries, cities and retailers are written in HTML in the Page while reas, countries, cities and retailers are written in Javascript in the footer.php. 不同的地区,国家,城市和零售商在页面中用HTML编写,而地区,国家,城市和零售商在footer.php中用Javascript编写。 I know I can move the Javascript over to the Page, but the problem is, she would still have to change both the Javascript and the HTML. 我知道我可以将Javascript移到Page上,但是问题是,她仍然必须同时更改Javascript和HTML。 I would like it to work with Shortcodes in a structure like this: 我希望它在这样的结构中使用Shortcodes:

[countryopen]
[areaopen]
[cityopen]
[retailer][retailer]
[cityclose]
[areaclose]
[countryclose]

How would I go about this? 我将如何处理? The HTML would be in the top of the file while the Javascript would be in the bottom. HTML将位于文件的顶部,而Javascript将位于文件的底部。 I cannot really change both things with just one shortcode. 我不能只用一个简码就同时改变这两件事。 How would I do this or is there even a better solution? 我该怎么做,或者有更好的解决方案?

So essentially you are trying to allow this person to manage locations? 因此,从本质上讲,您正在尝试允许此人管理位置? You can use Advanced Custom Fields for WordPress and/or custom posts types for WordPress . 您可以将高级自定义字段用于WordPress和/或将自定义帖子类型用于WordPress

I would use a combination. 我会结合使用。 Create a new custom post type in your functions.php and then, after installing the ACF plugin, create Location, Area, City, and Retailer fields and assign them to the new post type. 在您的functions.php创建一个新的自定义帖子类型,然后在安装ACF插件之后,创建“位置”,“区域”,“城市”和“零售商”字段,并将它们分配给新的帖子类型。

Similarly, in the index "Page" that you are working in now, you can create a query to dump any of these Locations onto the page. 同样,在您现在使用的索引“页面”中,您可以创建查询以将这些位置中的任何一个转储到页面上。

I hope this helps. 我希望这有帮助。 Let me know if I missed the point here, the question is still a little unclear. 让我知道是否遗漏了这里的问题,这个问题仍然不清楚。

UPDATE: There are many great tutorials that will walk you through creating a custom post type in your WordPress theme. 更新:有很多很棒的教程,它们将引导您完成在WordPress主题中创建自定义帖子类型的操作。 WPBeginner and Smashing Magazine do a really good job of bringing you through this step-by-step. WPBeginnerSmashing Magazine在逐步引导您方面做得非常好。 It will be very helpful for you to know how to do this and to understand this as a basic part of WordPress's Model-View-Controller system , here you are creating new views for your users to interact with. 知道如何做以及将其理解为WordPress的Model-View-Controller系统的基本组成部分将对您非常有帮助,在这里您将创建供用户交互的新视图。

After creating your new custom post type, which will seem like any other post/page in the Edit view, you can use the ACF plugin to easily add new fields to this new custom post type: 创建新的自定义帖子类型后,就像在“编辑”视图中的任何其他帖子/页面一样,您可以使用ACF插件轻松地向此新的自定义帖子类型添加新字段:

在此处输入图片说明

In the second section called "Location" you can define what type of posts these fields should be appended to. 在名为“位置”的第二部分中,您可以定义这些字段应附加到哪些类型的帖子中。 You would make these inputs says: 您将输入以下内容:

Post Type is equal to [Your New Post Type] Post Type is equal to [Your New Post Type]

Your new post type being "Locations" or "Retailers" or however you want to phrase that. 您的新帖子类型为“位置”或“零售商”,或者您想用短语来表达。 Now, when you check out the Edit view of a new custom post type, you can see these new fields appended to the bottom. 现在,当您签出新的自定义帖子类型的“编辑”视图时,您可以看到这些新字段附加在底部。 Lastly, you may want to remove any field that you wouldn't want your web manager adding information into like WordPress' native Description or Excerpt inputs. 最后,您可能希望删除任何您不想让网络管理员将信息添加到WordPress的本机Description或Excerpt输入中的字段。 You can do this by adding a few lines to your functions.php after you have created the post type: 您可以在创建帖子类型之后,通过向您的functions.php添加几行来做到这一点:

add_action('init', 'remove_editor_from_retailer');
function remove_editor_from_retailer() {
    remove_post_type_support( 'retailer', 'editor' );
}

Granted that "Retailer" is the name of your custom post type. 授予“零售商”是您的自定义帖子类型的名称。

You can't have a user updating data in a javascript file. 您不能让用户更新javascript文件中的数据。 So what you need to do is split the data off from the functionality. 因此,您需要做的就是从功能中分离数据。

To do this, put a script tag in one of your Wordpress template files, and output the area, country etc. data there as a Javascript variable. 为此,请将脚本标记放在您的Wordpress模板文件之一中,然后将区域,国家/地区等数据作为Javascript变量输出。

You can manage and fetch this data using any Wordpress method of your choice. 您可以使用任何选择的Wordpress方法管理和获取此数据。 Anything that allows the user to update data in the admin area which you can then output in your plugin will work. 允许用户更新管理区域中的数据的任何内容,然后可以在您的插件中输出都可以。 So a plugin, a shortcode on some specific post, etc. are possibilities. 因此,可以使用插件,某些特定帖子上的简码等。

Then, in your existing Javascript file, remove your hardcoded data and instead pull it from that variable. 然后,在您现有的Javascript文件中,删除您的硬编码数据,然后从该变量中提取它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM