Simple commenting system using AJAX. How to properly implement a CRM system: algorithm of actions and common mistakes Social network widgets

Hello, friends and blog guests! Today I’ll tell you using PHP and MySQL. And we will also talk about commenting systems for the site and we will choose the best one for your site from the ones I offer.

Question one: by using PHP and MySQL?

To do this, you and I first need to create a table in the database of your site, which will be called - comments. This created table will store comments in fields with the following designations:

id is a unique identifier.
page_id— this field will store the identifier of the site page on which this comment is located.
name- this is the name of the commentator who left this comment.
text_comment— accordingly, this is the text of the current comment.

The next step, after creating a table for comments in the database, we need to implement special code for our future comments on the site. This code on the site will allow our commentators to add their comments to our articles. Here is the code:


It's simple HTML form comments for the site. You place it on your website in a place where it is convenient for leaving a comment on a post - naturally, under the post itself.

query("INSERT INTO `comments` (`name`, `page_id`, `text_comment`) VALUES ("$name", "$page_id", "$text_comment")");// Add a comment to the table header(" Location: ".$_SERVER["HTTP_REFERER"]);// Do we redirect back?>

The last step in creating a comment form for a site in PHP and MySQL is to display our comments on the site page. Here's the code for this:

query("SELECT * FROM `comments` WHERE `page_id`="$page_id""); //Fetch all comments for this page while ($row = $result_set->fetch_assoc()) ( print_r($row); //Output comments echo "
"; } ?>

That's all! Our simple comment form for the site has been created and can work on the site.

But this is certainly not for a beginner who will not bother with all this HTML, PHP and MySQL code. Nor will he learn how to create a database. He needs everything at once, quickly and without headaches. I'm right? Of course you're right!

Then let's move on to the next section of my material and find out everything about ready-made comment systems for the site and choose the most convenient, functional and acceptable for your site...

Comment systems for the site. Which one to choose?

How to make comments on the site- this is an important question because comments on a site play an important role not only for communication between the site owner and the visitor, but comments are also important for SEO promotion and promotion.

With the help of comments on the site, the site’s position in search results increases, behavioral factors improve, traffic to the site increases, and, consequently, your earnings increase. You see how important comments are for the site!

So let's take a look how to make comments on the site and which one commenting system choose the most best option?

In general, comments on websites are displayed in many ways. These are special plugins for wordpress engines and comments from social networks all sorts of things, such as In contact with, Facebook, Disqus. There are also independent services that offer their own comment systems for the site, for example.

I’ll now give you one tablet that will immediately put everything in its place and no questions will arise about choosing a comment system for the site:

Here you can clearly and clearly see which comment system is the best and several presented ones, which are most often used by webmasters on their resources. I think that explanations are unnecessary here and the choice is yours!

Reading time: 55 min

Good day to all.

Now the time has come for the long-awaited material about micro markup.

I’ll say right away that this article will be quite difficult to understand at first, especially for beginners, since there are many options for micro markup and it’s difficult to get it all in your head at once. But I will try to describe the overall picture and at the same time focus on the most important and common things.

The material is quite voluminous, but I hope that it will help you create micro-markup on the site.

Lately I've noticed that a lot of people are obsessed with microdata. This happened after various SEO bloggers began to vigorously discuss it. But let's figure out why it is used at all and whether it is necessary to pay so much attention to it. Is the game worth the candle?

What is micro markup and why is it needed?

If you hear micro-markup or semantic markup of a page (site), then know that this means marking up a page using additional attributes (tags), which give search engines an idea about individual elements of the page, indicating their content.

You must understand that a regular page is already marked up, but the usual generally accepted tags and attributes are used. This is quite enough for search engines and many sites still exist this way and are thriving quite successfully.

But, if we want to help search engines understand our site, point them to important areas of the page, understand its structure, pointing out the content of those areas that first need to be paid attention to, then it is necessary to implement micro-markup, that is, add certain tags and attributes that will indicate everything.

By doing this, we will not only help search engines, but also our site, since micro markup is used not only to understand the site structure and content, but also to build search results, forming functional and attractive snippets, which affects the click-through rate (CTR) of the site in issuance. And this is an increase in overall site traffic.

You can see a striking example of such snippets below.

On this image you can see, which complements and makes it more noticeable among the gray masses of other sites in the search results. I also used arrows to highlight the breadcrumb trail, which shows a clear structured path to the material on the site, rather than a simple unclear URL.

This navigation chain is quite simple. All you have to do is install them on the site.

Here is another option for rich snippets.

The same option allows the visitor to immediately understand what the site is about and what it can give him. If the snippet is constructed correctly in this case, then the user can immediately take the action you need, and as we know, each site must perform its own tasks (subscription, purchase, etc.).

Agree that such a snippet will be more noticeable in the search results than a regular page description, since it has much more larger size. Yes, and it looks more solid.

Let's now answer a question that may concern those who think that micro markup helps in increasing positions and is one of the ranking factors.

Does micro markup affect rankings? Should we expect an increase in positions after its implementation?

In order not to write our reasoning, let's turn to the help of the Yandex search engine. So, what does Yandex itself tell us about this? I quote:

Will my site rank better if I use markup?

Answer: Markup can make your site more visible in Yandex Search and thus attract more visitors belonging to target audience. Yandex is interested in users solving their problems using Search. One of the Search quality metrics is called “user happiness.” Websites that increase “happiness” rank higher.

We can conclude that markup does not directly affect positions, but only indirectly, since we can make a more attractive snippet, which in itself will bring more visitors to the resource. Then it's a matter of technique. More visitors means more accumulated good indicators about the pages (if the content is high-quality) and the positions will gradually increase.

It is also worth noting that by helping search engines understand the nature of the content, its type (information, meeting, product, etc.), we make the content more relevant search query and he should occupy higher positions. Maybe not directly, but indirectly - that’s for sure. Yandex confirmed this to us (see above).

So, let's make a short checklist of the benefits of having micro markup on the site. These are those points that indirectly or directly indicate the quality of the site, increase its position and help search engines.

  1. Firstly, we can conclude that the trust in the site from search engines increases, since we point the search robot to the main elements of the site, without being afraid that something is wrong with us and without trying to hide something from the search robot . As a result, it is logical for search engines to think that we are helping them and revealing to them the “soul of the site,” which will certainly affect the quality of the site’s indexing, and ultimately its positions;
  2. Secondly, with the proper settings, we can highlight our snippet in the search results, which will lead to an instant increase in traffic to the resource pages without changing positions. Ultimately, increased traffic will lead to increased individual pages in the search results and the site as a whole;
  3. Thirdly, we increase the behavioral factor - CTR in search results (click-through rate). This point is very closely related to the previous one. Since more people click on our website, it means we have more accurately helped the visitor understand that our page is of higher quality than on other sites. This means that the site needs to be slightly raised in search results.

So, I think the answer to the question has been given.

Is markup necessary at all? - Yes, I need it.

Of course, if there is a choice between the painful implementation of markup on the site and working on other aspects, then, of course, you should not focus only on semantic markup. It’s better to work on content, which is much more important than some technical detail among hundreds or thousands of other things. Moreover, now you can highlight your snippet in the search results without introducing markup into the template, but only by installing , which already provides rating markup.

Once we know the main benefits, we can move on to consider the main types of semantic markup.

Main types of micro markup

Everything is quite complicated here. First, you need to understand that there are micro markup dictionaries and their syntaxes.

A dictionary can be understood as a micro-markup language that includes a set of classes and properties that indicate the essence of the page content. In each dictionary, each element on the site is identified using different tags. For example, in the Schema.org dictionary, the name of the document is indicated using the "name" tag, but microformats use a CSS class inside the block of the element that is worth marking up ( Chamomile, where fn org is the title tag in this case).

Each dictionary and syntax has its own tags and attributes, which makes micro markup formats a so-called vinaigrette. It's really hard to figure everything out.

Syntax is understood as the way of using a particular language (dictionary) of semantic markup. The syntax determines which tags will be used to indicate the essence of objects and their properties on the page.

From the previous definition about syntax, the concept of essence was introduced. What does this mean applicable to the issue at hand?

Essence - simply put, this is the type of information (unit of content, information) that we point to search engines. For example, we need to point to announcements on the main page of the blog, that is, highlight the essence of this area with some tag, defining it as an announcement area. The same needs to be done with the post page, where you need to indicate the essence of the area where the content (article) is located, that is, highlight the text as a content area.

For almost every element of the page, you can define the essence, that is, indicate what it is: content or rating, or comments in general. Thus, entities can be specified on such pages (I’ll take a simple blog template like mine as an example):

  • Home - list of announcements;
  • Posts page - comments, content, rating (if available), breadcrumbs;
  • A regular static page - content, comments (if any).

In addition, on each type of page you can designate the same element - site header, footer (footer), sidebar (side column), main menu.

Each entity has its own properties, for example:

  • Content area on the posts page - article title, article text, description, article author name, publication date, category, images, videos and others;
  • The area for the list of announcements on the main page, sections and archives is the same;
  • Comment area - commentator name, date, comment text;
  • The content area on a regular static page is basically the same as in posts;
  • Site header area - title, description;
  • Rating area on pages - maximum rating, current rating, number of ratings.
  • Footer area (site footer) - year of copyright;
  • Sidebar area (side column) - name of widgets;
  • Main menu area - links.

There are other areas with properties, but I will not consider them, since in each markup dictionary there are several dozen of them, and in the markup from schema.org their number is generally in the hundreds.

We will look at what tags and attributes to use to indicate the entities and properties of each of them in the practical part of this article.

Now let's move on to the main idea of ​​the paragraph and consider the main formats of semantic markup. A short list of basic vocabularies and syntaxes can be seen in the mind map below.

We will not consider all dictionaries and syntaxes, as this is pointless. You won't need them. Let's discuss only briefly the main markup formats:

  • Schema.org;
  • Open Graph;
  • Microformats.

We will touch on some of the rest quite a bit.


The last step is worth noting another dictionary, namely Data Vocabulary, which was developed by Google and now its development has been suspended. All attention shifted to Schema.org. We can say that all the properties and entities that were in this markup language became prototypes for markup from schema.org.

As far as I understand, the Data Vocabulary dictionary can work with syntaxes: microdata and the RDF language, which can be very clearly seen in the Google help on breadcrumb micro-markup material. There are 2 markup options:

  1. Data Vocabulary tagging with microdata;
  2. Data Vocabulary Markup with RDFa.

I'll get ahead of myself a little. In the first image you can see that microdata from Schema.org is used along with the Data Vocabulary. The fact is that breadcrumbs with schema are not supported yet. Therefore, a combined option is used.

Which markup format is best to use?

I think you already know the answer to this question, since in the description of each type of markup I gave an undeniable argument that search engines They themselves recommend the Schema.org markup dictionary. This is exactly what you need to use. But there can be a lot of options for implementing this micro markup, both from plugins and the introduction of entities and properties into design templates.

The last option is the most optimal, since this is a one-time job and micro markup will be on absolutely every page. All search engines will see it, since it will be built into the template. But beginners may have problems implementing it, since they need to understand the code of their template at least at a minimum basic level and see what tag displays the title of the article, where the code is for displaying the text, and so on. All these moments will need to be wrapped with micro markup tags.

This point also raises the issue of combining different dictionaries on one site. This is acceptable and in some cases it cannot be avoided. This is clearly seen in the example of breadcrumb markup, when a variant of the Data Vocabulary markup and microdata markup from Schema.org are combined. There's nothing wrong with that. Yandex itself speaks about this.

It's up to your discretion. If you find it easier to use microformats, then go for it. I personally will show the whole process on Schema.org micro markup, since I myself have implemented it and everything works with a bang without a single error.

How to check the presence of markup on a website

Our task at this stage is to find out whether our template has some kind of markup format. This is quite possible, because most of the templates used are translated English-language themes that already contain some kind of semantic markup format. As a rule, this is markup in microformats, which is of no use to us at all. It is better if it is not there initially, as this will save us from the headache when it is removed.

To check the presence of markup, you can use both the micro markup validator from Yandex and the Google structured data verification tool. I prefer and strongly recommend that you use the Yandex validator, as it is much simpler.

After going to the Yandex validator, we enter the page address and click “Check”.

If it says “Micro markup not detected,” it means there is no third-party markup in the template. This is very good, since you don’t need to waste effort on removing it. But be careful, because on one type of page there may be no markup, but on another it will be present (for example, on an article page).

So, I’m analyzing the post page and it turns out that the template comments are marked with microformats (vcard is present). This is evidenced by different codes in the scan results.

We don't need microformats, so we should remove them. It may happen that your template is marked up in other markup formats. Then they should also be removed. And it is possible that markup from Schema.org will be immediately implemented. This also happens, but very rarely, since there are practically no worthwhile templates available for free. But bad ones are a dime a dozen.

Now let's look at the process of removing third-party markup.

Removing third-party markup

Since in my case it turned out to be third-party markup using microformats, I will use its example to show this process. If you have some other markup, then the principle of deleting it will be similar.

It all comes down to removing the tags and their attributes from the markup that you have. The only difference between microformats and other types of micro markup will be that all types except microformats add new tags and attributes. Microformats do not add anything but are written inside a specific class attribute html element template (for example, the title of an article), as I wrote in the paragraph about the main types.

By the way, in point No. 6 of this article I give the comment markup code that needs to be inserted into the template function file functions.php. This code should cure these errors from third-party microformat markup. Therefore, if you have this problem, I first recommend checking that code on your template. He should help. This will save you the unnecessary work of manual disposal. If nothing works out, then we do everything by hand, as I describe below.

Now let's move on to the process itself. So, earlier it became clear that I had extra markup from microformats. When checking in the validator, we were given the vcard tag, which creates errors.

Now we need to open the folder with the template to see all its files and then we turn to those files that are responsible for displaying those elements where the microformats are located. How to do this, see the list below:

I hope I explained it quite simply. Although, a beginner may have more confusion in his head.

This is how this piece of code with vcard originally looked in my template file.

After the change it became like this.

I also made changes to the styles.

Now there are no microformats and the design has been preserved in its original state.

So, when we have removed the standard markup (if it was present), we can embed new one from Schema.org. TO this process we get started.

Implementing micro markup Schema.org

Let's start with a little explanation and theory, since you always need to prepare before practice.

First, it’s worth figuring out what files we need to point to the necessary entities and their properties. Now I’m talking about files for the WordPress engine. I won’t say anything about other engines, since I don’t work with them. The marking principle remains the same. You just need to determine the files where the required areas for marking are located.

  • Single.php file (record file): entity - content area (article), properties - publication date, author, category, article title, images;
  • Functions.php file (in my case - comment code markup): entity - comment, properties - comment text, date and name of the commentator;
  • Files with a list of announcements index.php, category.php, archive.php (main, categories and archives, respectively): entity - list of announcements, properties - publication date, author, category, article title;
  • File page.php (regular static page - optional): entity - content area, properties - text title and, if available, date, author and others;
  • In the header.php file, also mark the header - the entity will be the header, and the properties will be the site title + description;
  • File sidebar.php (side column): entity - the entire sidebar, property - the title of each widget;
  • File footer.php (site footer): entity - the entire footer, property - copyright date + site name (I did not mark up the name);
  • File header.php ( top part resource): entity - main navigation menu, property - links + their anchors.

Now about the tags and attributes that correspond to each type of entity and their corresponding properties. First about the entities.

/***List of announcements***/ itemscope itemtype="http://schema.org/BlogPosting" /***Post page content***/ itemscope itemtype="http://schema.org/Article" / ***Comments***/ itemprop="comment" itemscope itemtype="http://schema.org/Comment" /***Regular static page***/ itemscope itemtype="http://schema.org/ Article" /***Sidebar (sidebar)***/ itemscope itemtype="http://schema.org/WPSideBar"> /***Footer (site footer)***/ itemscope itemtype="http:/ /schema.org/WPFooter"> /***Site Navigation (main menu)***/ itemscope itemtype="http://schema.org/SiteNavigationElement"> /***Images***/ itemscope="" itemtype="https://schema.org/ImageObject" /***Permanent link to the page***/ itemscope itemprop="mainEntityOfPage" itemType="https://schema.org/WebPage" /***Organization* **/ itemscope itemtype="https://schema.org/Organization" /***Address***/ itemscope itemtype="http://schema.org/PostalAddress"

Now the property tags.

  • Page (text) title - itemprop="headline"
  • Entry text - itemprop="articleBody" (can also be used for description if it is formed as part of the full text)
  • Date of publication - itemprop="datePublished"
  • Author - itemprop="author"
  • Article category - itemprop="articleSection"
  • Image - itemprop="image"
  • Comment text - itemprop="text"
  • Commentator name - itemprop="creator"
  • Comment date - itemprop="datePublished"
  • Link (applies to main menu and image) - itemprop="url"
  • Copyright year in the footer - itemprop="copyrightYear"
  • Date the page was last modified - itemprop="dateModified"
  • Address - itemprop="address"
  • Street - itemprop="streetAddress"
  • Index - itemprop="postalCode"
  • Address location - itemprop="addressLocality"
  • Telephone - itemprop="telephone"
  • Image length - itemprop="width"
  • Image width - itemprop="height"
  • Logo - itemprop="logo"

These are the main properties that we will now use.

Further steps to markup the template are quite simple.

Each area that needs to define an entity and property using the tags provided above is wrapped in some kind of common tag. This could be a div block tag, an article tag, a span tag, an H1 header, and others. To make it easier to understand, the title is almost always wrapped in an H1 tag, which is how it should be. There will be 2 tags: opening and closing. And so with every element of the site, and not just with the headers.

The idea is that each required element will need to be given an entity tag (specify the content type: article or comment, or list of announcements, etc.) and properties inside its opening tag.

Now practice. For example, there is a single post (article) file single.php. Let's start with its marking.

Micro markup of a post (article)

Let's start by defining the entity. The template has a common tag that wraps the entire content area of ​​the post (both the text of the article and the title and comments) and it is different for everyone. Some people might have it div block. I have this article. Naturally, this tag opens at the very beginning, where all the content begins, and ends somewhere when the content ends.

And it is at the very beginning, inside the opening article tag, that I need to insert the entity tag of the content area on the post page (I gave the codes a little higher). I’ll give you an image (clickable) of the final markup of the single.php recording file, and then I’ll explain what happened and what happened in the end, if it’s not clear to anyone. The image is large, but clickable, so you can click on it and view it in a larger size, or open it in a new tab and view it in full size.

Initially, the entire content area of ​​the post is opened using the article tag. It was like this:

And it became like this:

As you can see, the post entity tag is included inside the opening article tag. Now the search robot will understand that this is an area that contains content. Will perceive this area as an object. It is very important.

By the way. Many people set article ratings without a plugin, and after checking the page in a Yandex or Google validator, they are told that the object of the review is not specified. This is due to the fact that the rating is posted on its own. You need to place it inside this area, which in turn must be defined by a markup tag as the content area (or review object). Then the rating will belong to the object, that is, the article. After this there will be no errors.

Let's get back to the process. First, we placed the essence of the object (we wrapped the entire main area with a common tag), and then we marked its properties, that is, secondary data: date of publication, author, body of the article (the text itself), information about the publisher (address, organization, logo), date last page change, home page address, and so on. Everything is exactly the same - inside each opening tag of the required element we indicate the corresponding parameters. Below I provide an explanation of what happened before the changes were made and what happened after.

Initially, we copy 2 lines of code immediately after the opening tag that wraps the entire content area. For me this is an article tag with an entity inside it that was placed earlier in the text.

"/>

  • The 1st line is responsible for outputting a line that points to the page address and says that this particular page is the main one.
  • 2nd line - date of last modification of the page.

Then, in the next line, we give information about the publisher, i.e. about who publishes the materials. This includes several entities at once (Organization - the address inside it, the image - the logo). I give you the code, you just replace the hints in it with your data. Whether you put real ones or not is up to you, but if Google still does this in order to improve the results and show your data so that your credibility increases, then I would indicate the real ones. In general, this is everyone's business. Here's the code.

Street name index country, region, city telephone

If you notice, in the above codes there is a display:none style tag, which says that this data does not need to be displayed on the page, but only in the source code, so that the search engine can see it. Actually this is what I need. This tag is located on lines 2 and 9 and hides the display of the logo and address. If you want to display, then remove these styles. In the future, I will do this, when I radically redesign the blog, I will design it into a compact, beautiful blog that will fit well into the design and provide information about me.

Regarding the logo, many simply do not have one. I suggest doing the following - either create a small image and write on it the name of the site with the address (the simplest logo option) or upload your photo (the laziest option). I have a logo, so I registered it.

So now we mark up the following information. It will be easier here. You just need to find all the other necessary codes that display this or that information (title, category, publication date, author), and insert the necessary schema.org markup property tags inside their opening tags in which they are enclosed.

Post title. Was:

Publication date. Was:

Konstantin Khmelev

".$current_category_name."

".$current_category_name."

Article text. Was:

here is third party code

here is third party code

You should do almost the same thing yourself. The only differences will be in the tags, inside which you need to place the entity and property tags. Their order may also be different. Or it may be that something will not be there at all, for example, there will be no publication date or link to the category. Then you will have to add this data to the template.

In the penultimate paragraph of the article, I will give you codes that you can use if you are suddenly missing something.

So, now we must check our page in Yandex and Google validators.

In Google's validator it will be almost the same. There should be no errors in this data. The only nuance concerns the micro-tagging of images, which is what we are moving on to.

You can mark up each image manually, wrapping it in the essence of the images and specifying the necessary properties, but this is quite inconvenient when there are several dozen images in each post. Let's use the following code.

Function micro_images_captions ($a , $attr, $content = null)( extract(shortcode_atts(array("id" => "", "align" => "alignnone", "width" => "", "caption" = > ""), $attr)); if (1 > (int) $width || empty($caption)) return $content; $caption = html_entity_decode($caption); if ($id) $id = "id ="" . esc_attr($id) . "" "; return "

" . do_shortcode($content) . "

" . $caption . "

";) function micro_image($content) ( $ar_mk = "! !si"; $br_mk = " "; $content = preg_replace($ar_mk, $br_mk, $content); return $content; ) add_filter("the_content", "micro_image"); add_filter("img_caption_shortcode", "micro_images_captions", 10, 3);

Now you don't need to add an image markup tag to every article. We go to the validator, check the page with at least one picture, and see the next picture.

There shouldn't be any errors. Everything is clear. Each image should be wrapped with markup, just like in the screenshot above.

Micro markup of the main page

Here you need to wrap the code that displays the list of announcements with the announcement list entity tag. This is done exactly the same way. Inside the general tag that wraps all the code in the template, we place the desired tag (the essence of the list of blog posts is blogposting, or you can do it similarly to the post page -article). See the image (clickable).

As you can see, my list of announcements is displayed using the li list tag, that is, each announcement is enclosed in it. Inside the list is almost the same as inside the entry itself - there are dates, the name of the author, the name of the sections, the address, the logo, the publisher, and so on. You can clearly see this on the blog pages. The structure is similar, only the text of the article is not complete. In general, the markup is exactly the same as for the post page, with the exception of the blogposting announcement entity tag.

It is also necessary to use a slightly different image markup code for the announcements page, since it displays not just pictures, but thumbnails. Micro-marking of thumbnails will be carried out using almost similar code. If previously they had to be marked by hand, now there is no point in doing so. Here is the code (we also place it in the functions.php file).

Function micro_thumbnail($content) ( $ar = "!!si"; $br = ""; $content = preg_replace($ar, $br, $content); return $content; ) add_filter("post_thumbnail_html", "micro_thumbnail ");

We contact the validator and check home page. I showed you only 2 announcements, because... the full screen will be very large.

There will be as many such blogposting entries as there are announcements on this page. If you used article instead of blogposting, then you will have several articles depending on the number of announcements.

Since the main page is similar in structure to the pages of sections and archives, their micro markup is identical. Lists of announcements are displayed on all types of pages.

So, all that remains is to parse the comment markup, which is a rather complicated process for a beginner. There are also regular static pages left. The principle of their markup is similar to records, so I won’t show it.

So, comments. Let's simplify the task to inserting one code into the functions.php file and modifying the function that displays comments on the site pages. First, take the following code and place it inside the functions.php file at the very beginning, right before the opening tag< ?php. Если будет выдавать ошибку, можно попробовать его разместить после закрывающего тега?>at the very end of the file.

There is also a placement option when you need to remove the opening of the php code in this code at the very beginning (remove< ?php) и в самом конце его закрытие (удалить?>). Then you need to place the code not before or after the opening (closing) php tag, but inside these tags next to all other functions. Sometimes I encountered a problem when this particular placement option works.

The code does not work on all templates!

< id="comment-">

%s:
"), get_comment_author_link()); ?>comment_approved) : ?>
$add_below, "depth" => $depth, "max_depth" => $args["max_depth"]))); ?>
$add_below, "depth" => $depth, "max_depth" => $args["max_depth"]))); ?>

The next step is to open the comments.php file and look for the comment output function in it. It looks like this:

< ?php wp_list_comments(); ?>

This is a simplified version of it and it will be good if you do it that way. Then we simply replace it with exactly the same code, only a few changes with a call to the function that we placed earlier in the functions file.

< ?php wp_list_comments("callback=schema_comment"); ?>

There may be a situation when, instead of just a code variant, there will be a slightly modified version with parameters already entered, for example:

< ?php wp_list_comments("type=comment&avatar_size=48"); ?>

In this case, we use the & sign to add a call to our comment markup function callback=schema_comment. It will turn out like this:

< ?php wp_list_comments("type=comment&avatar_size=48&callback=schema_comment"); ?>

In my example, everything is still much more complicated. Inside this function there are parameters, as in the previous line of code. But they are displayed a little differently.

< ?php wp_list_comments(array("style" =>"ol", "short_ping" => true, "avatar_size" => 74,)); ?>

If you have this option, then inside the brackets next to all the parameters we introduce a new one. We will end up with the following code.

< ?php wp_list_comments(array("style" =>"ol", "short_ping" => true, "avatar_size" => 74, "callback" => schema_comment,)); ?>

When we have placed the function code in the functions.php file, and also slightly changed the code for displaying comments on the site in the comments.php file, we can check the operation of the comment markup.

A sign of correct markup of comments is their nesting in the body of the article without any indents or spaces. Each comment must be displayed within the article and shown in the Yandex validator.

As you can see, comments are located inside the body of the article. This is how it should be for you too.

You can also tell search engines the number of comments on each post. There is also a tag for this - itemprop="commentCount". Similar to the earlier steps, it should be placed inside the opening tag that wraps the function for displaying the number of comments. This function is called:

< ?php comments_number ?>

The full output line of this function may be different, but its essence is the same. There should be comments_number inside.

For me, this function has the following complete form along with the wrapping tag.

< ?php comments_number("Комментариев пока нет. Будьте первым!","1 Комментарий","Комментариев: %") ?>

Depending on the template, you need to find the location of the function. Typically, everything is in the same comments.php file. In my template, this function was located in the single entry file single.php before displaying the comment form. Since my function was wrapped in a span text tag, I insert the commentCount property inside it.

We contact the validator.

Important. You only need to wrap the number of comments without any inscriptions or words. The markup only accepts numbers!

Attention: I am not the author of the functions. The functions for automatically marking comments and images are taken from the site http://seo-mayak.com/. I just changed the names a little + corrected something a little somewhere.

Micro markup of the site header

Open the header.php file of the design template and look for the opening header tag. We paste inside it:

Itemscope itemtype="http://schema.org/WPHeader"

  • Heading - itemprop="headline"
  • Description - itemprop="description"

Here is the finished version in the image.

It will be displayed in the validator like this.

Sidebar (side column) micro markup

Everything is simple here too. We open the file that is responsible for the output of the side column, as a rule, this is sidebar.php. We find a block or tag that wraps the entire content of the entire side column and inside it we place the tag of the entity corresponding to the sidebar.

Register_sidebar(array("name" => __("Area for inserting widgets into the sidebar", "xmarkup"), "id" => "primary-widget-area", "description" => __("", "xmarkup "), "before_widget" => "", "after_widget" => "", "before_title" => "", "after_title" => "",));

Of interest are the last 2 lines (before_title and after_title), which determine what will be displayed before and after the widget title, respectively. As you can see, I have indicated that there will be a span text tag before and after. You may have something empty there or some other tags, such as a div block tag. If it’s empty, I recommend adding a span tag similar to my version and specifying the name property (itemprop="name") inside the opening tag (before_title line). You will get the following construction:

Register_sidebar(array("name" => __("Area for inserting widgets into the sidebar", "xmarkup"), "id" => "primary-widget-area", "description" => __("", "xmarkup "), "before_widget" => "", "after_widget" => "", "before_title" => " ", "after_title" => "",));

Depending on the template, there may be several such parts of code. Then all the parts will need to be finalized. After the changes, we check the sidebar markup through the Yandex validator and the following picture should be obtained.

Depending on the number of widgets, the corresponding number of rows will be shown when checking.

Footer (footer) micro markings

Open the footer.php file and look for a common block that wraps all the contents of the footer, including copyrights. Inside the opening tag we place the entity tag itemscope itemtype="http://schema.org/WPFooter".

And inside the opening tag, which contains the copyright date, we place the property tag itemprop="copyrightYear".

It is very important that inside the copyrightYear tag there is only a date in the form of a number. No extraneous words or symbols, otherwise it will generate an error.

In working condition, you will see the following in the validator.

Micro markup of the main navigation menu

Here, too, everything is extremely simple, but this option will not work for everyone, since the structure of constructing and displaying the menu in the templates is different.

The code that displays the menu is in the header.php file. We go there and look for the following content:

< ?php wp_nav_menu(array("theme_location" =>"header-menu-top","container" => "")); ?>

The line may be slightly different. The main thing is to find the line that includes wp_nav_menu. It will be wrapped in tags. For me and in most other topics the principle is similar. The nav tag is used. Inside the opening nav tag we insert a tag that shows the essence of this element, namely the main menu:

Itemscope itemtype="http://schema.org/SiteNavigationElement"

Next, you should make sure that the itemprop="url" attribute is added to each link in the menu, which will indicate that this is a link. If you have a simple site where each menu item is created by hand, then implement this attribute inside the tag of each link. If you have a website on WordPress and the menu is formed in the functions.php file in a standard way, you should place the following code in the same file, which will automatically insert this attribute to each menu item.

Function nav($content) ( $pattern = "

After checking any page (where there is a menu) in the Yandex validator, we should see the entity tag along with a list of all menu items.

If the function for your template does not work, then you will not see links in the validator, but only the entity.

In the latter case, it is better to remove the markup from the menu, since it does not carry any semantic meaning and Google’s structured data checking tool will give a warning.

This completes the main part of the micro markup. A regular blog (information site) doesn’t need anything else.

Micro-marking of addresses (contact details)

If on your website you show visitors your contact information (organization name, address, phone number, etc.), you can mark them up too. This is done very simply. Below I give the code, which you just need to place in html mode on the desired page (for example, contacts) and enter your data.

Name of the site index, country, region, city Street name Telephone: telephone Email: your email is [email protected]

I note that email via regular mail is not appropriate in this case. You need mail like [email protected], that is, mail on the domain.

On this note, the practice is over. Micro markup on your WordPress must be implemented and be without a single error, both in Yandex and in Google.

Now, as promised, I’ll give you some codes that you may need if your template does not display all the information necessary for markup.

Helpful information

I give you a list of codes with markup properties already implemented. In fact, you just need to insert them into the right places in the template and set styles for the classes that are written in these tags.

/***displays the publication date of the entry***/ /***author's conclusion***/ Author: /***display the number of comments***/ Comments: /***output page title***/

/***category output***/ name; $current_category_link = $cat->cat_ID; )) echo "
".$current_category_name.""; ?>

There is also a very large number of email requests to me with the problem of eliminating errors that arise due to the embedded hentry markup in templates. The errors sound like this:

Missing: entry-title
Missing: updated
Missing: author

Why is this situation happening? It's simple - the henrty class is automatically added to the template, which implies that the corresponding tags (classes) must be added to the title, date and author. You can do this - add these classes. I don’t see much point in this, since we have already marked the template with the schema.org dictionary and henrty microformats will not be of any use to us. Therefore, the fastest and easiest way would be to use a small function that removes this henty class from the template and Google will not even find the hentry microformats.

//remove class hentry start function wph_remove_hentry_class($classes) ( $classes = array_diff($classes, array("hentry")); return $classes; ) add_filter("post_class", "wph_remove_hentry_class"); //removing class hentry end

The function is of course added to the functions.php file. If you have already had similar errors or have begun to appear, then gradually as Google’s micro-markup robot crawls the page of your site, they will begin to disappear. If they were not there, then they will not appear.

There is another option when you can suffer and add the necessary tags to the output of the title, date and author. Then Google will find this markup and recognize it. If you decide to take such actions, then you need to find the php codes for displaying the title (1), date (2) and author (3).

The finished codes with microformat tags will be as follows:

Wrapping it this way will also be fine.

The next point will be for those who find it too difficult to do all this or who are too lazy.

I'll do everything for you

I can help you. But, of course, not for free. In addition to clear answers to your questions in the comments, I can embed all of the micro markup described above into your template for a small fee.

The cost of this service is 1000 rubles.

I will mark out all the main data, namely:

  1. Main page + pages of archives and sections;
  2. Post (post) page;
  3. A regular static page;
  4. Website header;
  5. Basement;
  6. Sidebar;
  7. Navigation menu (if the template does not conflict);
  8. Bread crumbs + rating (optional + 200 rubles).

This option is suitable for personal blogs, as well as information sites. I can work on both the WordPress engine and a regular html site. Initially, I will not do anything, since I will first analyze your template and answer whether I can do it at all. It is possible that you will have to redo something in the template or finish it. Each person receives an individual approach.

The principle is the following. You contact me through the “Write to me” page (you can also contact me in the comments of this article). Immediately send me a link to your website + a link to download the template. I analyze and give you an answer within the near future (1-2 days). If everything is within my power, then after payment I immediately begin marking.

All friends. I hope this material helped you. I had no goal of writing here in 2 words how to do everything. My goal was to write the best and most comprehensive guide to implementing markup on a website. Hope it worked out. You can confirm this with your comments, likes and ratings.

See you in the next materials.

Best regards, Konstantin Khmelev!

Now it has become fashionable to replace the usual WordPress comment system with comments from one of the most popular social networks, Facebook. We have already published this before, but a lot of time has passed since then, and now this procedure has been significantly simplified thanks to a ready-made WordPress plugin. So this time everything will be much easier.

We will tell you how to implement Facebook comments on your website a little later, but first we will try to determine all the pros and cons of such a replacement.

Facebook comments: pros and cons

In addition, the factor of the so-called anonymity. It is unlikely that spam comments will be added from Facebook, since they are all tied to real user accounts.

But at the same time, one can also find disadvantages of such a system. Many users prefer anonymity, and not at all because they want to write something bad or leave spam. No. It's purely a matter of psychological moment and the feeling of discomfort and embarrassment that they experience when speaking publicly. This factor may reduce user activity.

Unlike other comment systems like Disqus, Facebook comments do not sync with native WordPress comments. They completely replace them. If older posts already have WordPress comments, they will appear before or after new comments added via the Facebook form.

Here, perhaps, are all the pros and cons of Facebook comments.

If you haven't yet changed your mind about installing them on your WordPress site, then read below on how to do it.

Facebook Comments Plugin for WordPress

First, install and activate the plugin Facebook Comments and configure it in the menu that appears in the Settings → Facebook Comments section.


To start using comments on the site, you first need to create a Facebook application.

If you have created an application before, you can use its ID data right now. Otherwise you will have to create a new one on the page Facebook Apps:

The control panel of the newly created application will display its ID, which you need to copy and paste into the plugin settings. But before that, configure the application on your site in “Settings” using the “Add Platform” button.

A new window will appear in which you need to click on Web site and choose it as your platform.

So on the application settings page a new section “Website” will appear, in which you can specify the address of your website.

Save the changes, copy the application ID and place it in the plugin settings of your site.

If you haven't figured out how to set up the Facebook app, here's another one. brief instructions in English with an example for our website:

This Facebook comments plugin has a lot of options to configure. The default settings should work with most sites. However, you can change them at your own discretion and save the changes.

Now you can test whether the new comment system works correctly on your site.

Comment moderation

Since you have admin rights, you will receive notifications of new comments. You can manage them and decide whether to publish them or not.

You can also add a new moderator in the settings:

We hope this guide has provided clarity and helped you set up Facebook comments for your non-WordPres website yourself.

In this lesson I will talk about how to make comments in HTML, CSS, PHP. Comments are text that is not visible on the web page. They are used for various kinds of explanations, reminders, and descriptions for webmasters, which allows you to structure the document. Comments are indispensable when debugging code; they allow you to quickly navigate the markup of a web page and find the desired block. Comments are often used to debug HTML code. For example, you can temporarily comment out a specific block of code so that it is not executed, and if necessary, you can easily restore it.

Comments in HTML

In HTML, comments are formed using the following characters:. Thus, any text between these characters is a comment. Let's look at an example:

Comments in CSS

Comments in CSS are created using the characters: /* and */. To create a comment, you simply need to place the web page code between these characters:

/* Start of a block with styles for Body*/ body ( background: #efeded; font-family: Verdana, Helvetica, sans-serif; font-size: 12px; margin: 0px; padding: 0px; ) /* End of a block with styles for Body*/

Comments in PHP

Comments in PHP can be single-line or multi-line:

1) Single-line comments in PHP are created using the characters: //. Simply put this character in front of the line and it will be commented out. This option is used in the case when the comment consists of only one line.

2) To implement multi-line comments, the following symbols are used: /* and */. This option is useful if the comment spans several lines.

So we learned to do

This time we are making a simple AJAX commenting system. This will demonstrate how to achieve efficient interoperability between JQuery and PHP/MySQL using JSON. The system works in such a way that added comments are placed on the page without completely reloading it, giving the feeling of the site running only on the user's computer, thereby avoiding the need to wait for some time to reload the page with the added comment.

Here's a rough demo of what we plan to implement:

Step 1 - XHTML

First, let's take a look at the comment markup. This code is generated by PHP in a comment, which we're going to look at in a moment.

Demo.php

Name
July 30, 2010

A comment

The Div of the avatar class contains a hyperlink corresponding to the avatar (if the user specified a valid link to the avatar when sending a comment), for example from gravatar.com. Well, we'll come back to this when we work with PHP. Finally, we have the name and time also in the DIVs, as well as the comment, that is, the text itself in the paragraph.

Another important element in the XHTML part is the comment submission form itself (all fields except the URL field are required).

Demo.php

Add a comment

Step 2 - PHP

PHP handles connections to the MySQL database and creates comment markup. In addition, AJAX is used at the end and inserts a comment into the comments table. You can see the code that displays comments on the page below.

Demo.php /* / Select all comments and fill the $comments array */ $comments = array(); $result = mysql_query("SELECT * FROM comments ORDER BY id ASC"); while($row = mysql_fetch_assoc($result)) ( $comments = new Comment($row); )

The MySQL query fetches all entries from the database and populates the $comments array with the comment class object you see below. This array is output after the script is executed.

Demo.php /* / Display comments one by one */ foreach($comments as $c)( echo $c->markup(); )

Each comment has a markup() method, which generates HTML code for printing the page. You can see this method and class below.

The class takes a string from the database (fetched with mysql_fetch_assoc()) and stores it in the $data variable. It is only available to methods of this class and cannot be accessed from outside.

Comment.class.php – Step 1 class Comment ( private $data = array(); public function __construct($row) ( /* / Constructor */ $this->data = $row; ) public function markup() ( / */ This method outputs the XHTML markup comment */ // Create an alias so we don't have to write // $this->data data every time: $d = &$this->data; $link_open = ""; $link_close = ""; if($d["url"])( // If the person filled in the URL when // adding a comment // Define the hyperlink $link_open = ""; $link_close = ""; ) // Time conversion $d[ "dt"] = strtotime($d["dt"]); // Required for default Gravatar images: $url = "http://".dirname($_SERVER["SERVER_NAME"]. $_SERVER["REQUEST_URI "])."/img/default_avatar.gif"; return "

".$link_open." ".$link_close."
".$link_open.$d["name"].$link_close."

".$d["body"]."

"; }

This script uses Gravatar to show avatars in comments. For those who haven't used Gravatar, it is a very useful service that allows you to associate an avatar with your email address. The avatar can be easily taken by passing the hash via md5().

Notice on line 39 above it - the script tries to figure out the URL it is on and determines the exact address of the default_avatar.gif image. This GIF is transmitted to Gravatar using an md5 hash, so if an avatar was found on this email address, a fallback stock image is displayed instead.

Comment.class.php – Step 2 public static function validate(&$arr) ( /* / This method is used to validate data / passed through AJAX. / / This returns true/false depending / on the data is valid, and is filled in / The $arr array is passed as paremter / (note the ampersand above) / Either valid data input, or error messages. */ $errors = array(); $data = array(); // Using the filter_input function introduced in PHP 5.2.0 if(!($data["email"] = filter_input(INPUT_POST,"email",FILTER_VALIDATE_EMAIL))) ( $errors["email"] = "Please enter a valid Email. "; ) if(!($data["url"] = filter_input(INPUT_POST,"url",FILTER_VALIDATE_URL))) ( // If the URL field does not match the wrong URL $url = ""; ) // Using filters with custom // callback function: if(!($data["body"] = filter_input(INPUT_POST,"body",FILTER_CALLBACK, array("options"=>"Comment::validate_text")))) ( $errors[ "body"] = "Comment error."; ) if(!($data["name"] = filter_input(INPUT_POST,"name",FILTER_CALLBACK, array("options"=>"Comment::validate_text")))) ( $errors["name"] = " Name error."; ) if(!empty($errors))( //If there are errors, write $errors to the $arr array: $arr = $errors; return false; ) foreach($data as $k=>$ v)( $arr[$k] = mysql_real_escape_string($v); ) // Make sure the emails are in lowercase // (for the correct Gravatar hash): $arr["email"] = strtolower(trim($arr[ "email"])); return true; )

validate() is defined as static in the manner described above. This means that it can be called as Comment::validate() directly, without having to create an object of that class. This method does not validate input that is provided via AJAX.

This method uses the new filter functions that are available in PHP 5.2.0. This allows us to easily validate and filter any input that is passed into the script. For example filter_input(INPUT_POST, "URL", FILTER_VALIDATE_URL) means that we are checking $_POST["url"] is a valid URL. If so, then the function returns the value of the variable, otherwise the returns are false.

This is very useful because until now, we had to use our own regular expressions to validate the data. Additionally, another advantage is that this data is taken before any configuration-specific transformations (such as magic quotes).

We also have the ability to specify a custom function that is going to apply some more advanced modifications to the data, as seen in lines 31 and 37.

Comment.class.php – Step 3 private static function validate_text($str) ( /* / This method is used internally as FILTER_CALLBACK */ if(mb_strlen($str,"utf8") , ", etc..) and convert // Newlines to
tags: $str = nl2br(htmlspecialchars($str)); // Remove any remaining newlines $str = str_replace(array(chr(10),chr(13)),"",$str); return $str; )

The last method is validate_text, which we pass as a callback function. It escapes all HTML special characters, effectively eliminating XSS attacks from them. It also replaces character strings with
lines.

Submit.php /* / This array will be filled with either / The data that was submitted to the script or / Error messages: /*/ $arr = array(); $validates = Comment::validate($arr); if($validates) ( /* Everything is good, insert it into the database: */ mysql_query(" INSERT INTO comments(name,url,email,body) VALUES ("".$arr["name"]."", " ".$arr["url"].", "".$arr["email"].", "".$arr["body"]."")"); $arr["dt" ] = date("r",time()); $arr["id"] = mysql_insert_id(); /* / Data in $arr insert query, / but unescaped text, / so we use stripslashes / for all array elements: /*/ $arr = array_map("stripslashes",$arr); $insertedComment = new Comment($arr); /* Output markup */ echo json_encode(array("status"=>1, "html" =>$insertedComment->markup())); ) else ( /* Display error messages */ echo "("status":0,"errors":". json_encode($arr).")"; )

submit.php receives the comment data as an AJAX request. It checks it and produces a JSON object, either the XHTML markup that was successfully rendered, or a list of error messages. JQuery uses ownership status to determine whether error messages should be displayed or a page markup comment should be added.

You can see two examples below.