Use jQuery to implement @ ID floating display in WordPress
This article mainly introduces the use of JavaScript to implement the function of ID floating display comments in WordPress, which is to display the main content of the comment in a building-in-a-building style comment. Friends who need it can refer to it
For example : A left a message, and B replied to A with @, so B’s reply may be like this:
@A
How much money do you have?
That is, when the mouse is hovering When you stop on @A, A's comment content will be displayed in a floating area.
Implementation steps
Here we will take the iNove theme as an example to explain.
1. Save the following code as commenttips.js:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
2. Place the commenttips.js file into the inove/js directory.
3. Append the style code to style.css As follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
4. Add code to call JavaScript in the theme. Open templates/end.php, and add the following code in the line before :
(If you have other plug-ins or have already The jQuery library has been added, so the first line of code does not need to be added.)
1 2 |
|
5. Okay, refresh the page with the @ reply, wait until the page is loaded, hover the mouse over the @ reply, You will see the effect.
Why can’t it be displayed across pages?
Because the working principle is that when the mouse moves to @{username}, it will be found on this page The corresponding comment is inserted into the comment list and displayed in absolute position. If the comment is not on this page, the object cannot be found, and of course there will be no subsequent processing.
How to cross pages Get comment information?
If the corresponding comment cannot be found on this page, you can use AJAX to return the comment information queried in the background to the page through the comment ID. When the mouse moves over the @ comment, hover to the user The 'Loading...' prompt box is displayed. If the operation is successful, the found comment will be inserted at the end of the comment list, and the content of the comment will be replaced in the 'Loading...' box.
In other words, the comment that has been loaded The comments will always remain on this page, and there is no need to reload when the mouse moves over the @ comment again.
Let’s take a look at how to handle cross-page comments:
On the current page How to find the corresponding comment through @{username}?
1. Each comment will have an ID, the structure is like: comment-{commentId}, this is to facilitate finding the comment through the anchor point, and at the same time It has also become a necessary condition to complete the @ comment prompt.
2. Each @{username} is actually the anchor point pointing to the comment, and naturally the comment ID can be obtained.
So it is actually very simple, if the comment ID is _commentId, then the corresponding comment can be found in JS through the following code.
1 |
|
If the target comment can be found, a hidden temporary comment is created, and the target comment is used as its content, in the @{username} attachment Display it; if the target comment is not found, use the ID to find the corresponding comment in the background and perform cross-page processing.
How to load comments across pages?
The essence of cross-page is to dynamically load comments and append the obtained comments to the end of the comment list so that the comments can be found on this page. The difference is that these comments will not be displayed through CSS processing.
You can refer to Figure below. If the comment is not on this page, it will take the red path. After the comment is added to the current page, there will be an action to replace the Loading information in the prompt box with the comment content. When the user hovers the mouse here @{ username}, the comment is already on the current page, so there is no need to load it again. Instead, take the green path and directly bring up the comment prompt box.
1 2 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Ajax bootstrap beautifies the web page and implements the code of page loading, deletion and viewing details
jquery in$ Introduction to the implementation of .fn and image scrolling effects
The above is the detailed content of Use jQuery to implement @ ID floating display in WordPress. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











There are four ways to adjust the WordPress article list: use theme options, use plugins (such as Post Types Order, WP Post List, Boxy Stuff), use code (add settings in the functions.php file), or modify the WordPress database directly.

To build a website using WordPress hosting, you need to: select a reliable hosting provider. Buy a domain name. Set up a WordPress hosting account. Select a topic. Add pages and articles. Install the plug-in. Customize your website. Publish your website.

A step-by-step guide to replacing a header image of WordPress: Log in to the WordPress dashboard and navigate to Appearance >Theme. Select the topic you want to edit and click Customize. Open the Theme Options panel and look for the Site Header or Header Image options. Click the Select Image button and upload a new head image. Crop the image and click Save and Crop. Click the Save and Publish button to update the changes.

WordPress IP blocking plugin selection is crucial. The following types can be considered: based on .htaccess: efficient, but complex operation; database operation: flexible, but low efficiency; firewall: high security performance, but complex configuration; self-written: highest control, but requires more technical level.

You can view the WordPress front-end by logging into the dashboard and switching to the View Sites tab; automate the viewing process with a headless browser; installing the WordPress plugin to preview the front-end within the dashboard; viewing the front-end via a local URL (if WordPress is set locally).

Importing WordPress source code requires the following steps: Create a sub-theme for theme modification. Import the source code and overwrite the files in the sub-topic. Activate the sub-theme to make it effective. Test the changes to make sure everything works.

WordPress editing dates can be canceled in three ways: 1. Install the Enable Post Date Disable plug-in; 2. Add code in the functions.php file; 3. Manually edit the post_modified column in the wp_posts table.

The steps to create a custom header in WordPress are as follows: Edit the theme file "header.php". Add your website name and description. Create a navigation menu. Add a search bar. Save changes and view your custom header.
