Dynamically load word press posts using ajax

If used within a topic, points to the directory of the sub topic. Because you are loading scripts for footnotes, set alert (\
The next step in creating an event is to create an event to trigger an Ajax call. In our case, an event is a click on a specific link. In order to target links, we need to have some understanding of the surrounding element classes and IDS. Page source code of chrome developer tools. If you want to know how it is displayed, click s shift+command+c on the MAC (s shift+control+c on Windows), hover over the element you want to check, and then click. This tells us that our page links have a page numbers class, and the next link also has a next class, which are contained in the NAV element where the NAV links class is located. In addition to the regular page numbers class, the old links not shown here have the prev class. The
Don’t worry about everything for the time being. We specify the link in the page tag container as the target. You can create the following simple warnings: In the concave 5ca270c7c9ddd18e57b4 load, everything floats with anonymous functions. It is recommended that you do the same. See this thread for why this would help. We created a click event and warned some text (that is, loading the page) to avoid running the default feature. You must get some dynamic data from the server side instead of generating client data using Ajax calls. Some preliminary work is required. The reasons are as follows: You must provide a URL for the Ajax call. Our JavaScript files don’t have the knowledge of our environment, so we can’t use things like get\u stylesheet\u directory\u URI (). However, you can use localization techniques to pass variables to JavaScript. Now, let’s do this in the function file. The
During the loading of the feed 5ca270c7c9ddd18e57b4, we will define the ajaxpagation object (parameter 2) by adding this code to the my\enqueue\u assets() function. Object receives members based on the array provided as the third parameter in the wp_localize_script() function. In other words, after adding this code, admin Ajax will be used to handle Ajax calls. Ajaxpagination is used to define the URL of PHP. Ajaxurl must be available. It works because the localization function outputs the definition of the object before the JavaScript is loaded. As follows: The
During the 5ca270c7c9ddd18e57b4 loading process, you will return to the JavaScript file. Now you have everything you need to build Ajax calls. The method is as follows: You can see $ The Ajax () function is used here. The post and get methods have special features, but they are preferred because of their flexibility. All parameters can be read in the jQuery document. Use the URL parameter to pass the URL of the script to send the data. This is the admin Ajax found in the WP admin directory. Must be a PHP file. It is defined above through the wp\u localize\u script() function. The
Type is set to post. Using get
Yes, but if the query is not very sensitive, but users need to access parameters, they prefer to publish data. The data parameter is an object that contains the data to be passed. For us, we can access the $\u post[\
In the 9ddd18e57b4 load, this is almost the same as our basic example. The first notable thing is that we have added a method to detect the pages that users want to request. Each link has a hidden span element (for screen readers). Create a copy of the element, do not modify the source, delete the range, and do not parse the rest into integers. This gives us the page number we need. You must also know the query parameters used. On the home page, this is very simple. This is only the paged parameter because it uses the default query. If you start from the archive page (such as Category Archive), you also need to know the category name. Use the localization method you learned earlier to pass query variables. Even if it has not been defined, it is now ajaxpaginition. Query\u vars will be used. On the last success, delete all article elements from the default container, delete the paging elements, and add the return value of the Ajax call to the default container. This return value includes the post and the new navigation element. In response, the reason for HTML is easier to understand. End by passing the original query parameters using a localized array. The following function should be placed in the my\enqueue\u assets() function to replace the localization we previously had. During the loading process of 5ca270c7c9ddd18e57b4, you only need to specify the my_ajax_paginition() function. Whatever this feature is, it will replace the content of our page. The final code described below is as follows: Abstract 5ca270c7c9ddd18e57b4 during loading, user-defined queries are created using the passed parameters. This includes using the query variable passed by default and confirming that the page is overwritten with the passed page number parameter. Then create a new query using the final $query\u vars array$ The globals[\
X call considerations it is important to remember that Ajax calls are always considered to be sent by the administrator. This means that drafts, appointments, and private posts can be returned during the call. To avoid this, you must control the action with appropriate parameters, such as post\u status. In Ajax solutions, such as better user experience, it is important to focus on the user experience. I work in a local environment and everything loads very quickly, but it may take longer to load images and other assets on the production server. Therefore, you must at least add a loader or load text, and disable add clicks on navigation elements. When the user clicks, the post and navigation will disappear and the text \
So. Please tell me your opinion on the following opinions. Tag: developer PHP

Author:

Leave a Reply

Your email address will not be published. Required fields are marked *