0

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).

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.

The problem here is, The Javascript is in footer.php while the actual content is on a Page in the dashboard. 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. 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. I would like it to work with Shortcodes in a structure like this:

[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. I cannot really change both things with just one shortcode. How would I do this or is there even a better solution?

3
  • I'm not sure you have specified an actual issue here, what exactly is the problem? The person taking over doesn't have coding experience but you want the JavaScript to be in a certain place for her? You can put scripts in page templates in WordPress. You can also create modular functions in JS so that they only run if the user is on a certain page. Please update your answer with a clear and concise goal. Commented Jun 5, 2015 at 14:23
  • Sorry, I really have a hard time describing the problem. I have updated the post so now I believe the goal is clearer. Commented Jun 5, 2015 at 14:37
  • check out advanced custom fields plugin. You could create a new post type for each of your countries, and have multiselects for regions and cities in it. That plugin has an easy interface for adding the options, so anyone can add another city to the options, then go back into the country and select that city, ect... They have code to query your advanced custom fields, which you could use to load your js arrays with the data in the footer. Would work for this I think...a little bit of coding to get it setup but then an easy gui for client to maintain Commented Jun 5, 2015 at 14:39

2 Answers 2

1

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.

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.

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. WPBeginner and Smashing Magazine do a really good job of bringing you through this step-by-step. 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.

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:

enter image description here

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]

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. You can do this by adding a few lines to your functions.php after you have created the post type:

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I believe this is exactly what I am looking for. However, I am having a really hard time understanding how it works. Read through the Post Types documentation and also installed the plugin and been messing around a bit with it. Haven't been able to recreate it though. I think what tricks me is the whole thing about parents/nested hierachy of the different type. Do you have any guidances that might help me further in my case? Thanks a lot for your help!
@RasmusBarslundHaxholm I've updated my answer to include more in-depth instructions.
0

You can't have a user updating data in a javascript file. 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.

You can manage and fetch this data using any Wordpress method of your choice. 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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.