Wordpress - Use a comment system beyond pages and posts

therefore, I am currently using pods to create separate pages for the magazine, filled with custom materials.

Now I want to use a comment system for each of these pages, for example:

mydomain.com/podpages/page1 mydomain.com/podpages/page2 mydomain.com/podpages/page3 

these are not pages created with Wordpress, so just adding <?php comments_template(); ?> <?php comments_template(); ?> doesn't work.

any ideas how to solve this problem? thanks in advance

please leave a comment if something is unclear :)

+4
source share
5 answers

When a comment is stored in the WordPress database, the identifier of the post (or page) associated with the comment is also stored.

The problem is that you are trying to save comments using WordPress, but for a page that she actually does not know about.

So, how about creating a WordPress page for every real page, but just as a presentation, so your real pages and WordPress have a common foundation for working with each other.

So the plan is here:

  • Download WordPress in the background on each of the real pages.
  • See if there is a WordPress page view for a "real" page
  • If it’s not, create it, then there
  • Trick WordPress, thinking we are really looking at the presentation
  • Continue to use all the WP features and template tags as usual.

This code should be somewhere at the beginning of the template file used to render your "real" pages;

 include ('../path/to/wp-load.php'); // remove query string from request $request = preg_replace('#\?.*$#', '', $_SERVER['REQUEST_URI']); // try and get the page name from the URI preg_match('#podpages/([a-z0-9_-]+)#', $matches); if ($matches && isset($matches[1])) { $pagename = $matches[1]; // try and find the WP representation page $query = new WP_Query(array('pagename' => $pagename)); if (!$query->have_posts()) { // no WP page exists yet, so create one $id = wp_insert_post(array( 'post_title' => $pagename, 'post_type' => 'page', 'post_status' => 'publish', 'post_name' => $pagename )); if (!$id) do_something(); // something went wrong } // this sets up the main WordPress query // from now on, WordPress thinks you're viewing the representation page } 

UPDATE

I can’t believe that I was so stupid. The following should replace the current code inside the external if ;

 // try and find the WP representation page - post_type IS required $query = new WP_Query(array('name' => $pagename, 'post_type' => 'page')); if (!$query->have_posts()) { // no WP page exists yet, so create one $id = wp_insert_post(array( 'post_title' => $pagename, 'post_type' => 'page', 'post_status' => 'publish', 'post_name' => $pagename, 'post_author' => 1, // failsafe 'post_content' => 'wp_insert_post needs content to complete' )); } // this sets up the main WordPress query // from now on, WordPress thinks you're viewing the representation page // post_type is a must! wp(array('name' => $pagename, 'post_type' => 'page')); // set up post the_post(); 

PS I think that using query_var name more than pagename better suited - it requests slug, not the pool 'path'.

You will also need to put the input inside the form with the name redirect_to and the URL value that you want to redirect, or , filter the redirection using the function connected to comment_post_redirect , returning the correct URL.

+11
source

add

 require('/path/to/wp-blog-header.php'); 

include wp files. this should provide you with all the features / data you need.

0
source

Can you create pages in Wordpress that display your log data? This may require a new template. Then WordPress will have something to do with the comments.

0
source

Just put wordpress-comment-part with a new ID - start with the fact that your regular posts will never be reached (100.000+ are your ie pages)

I do not know for sure if in wordpress this is a function (saveComment ie), but if so, just use it on your page with its user identifier. However, you will have to embed the comment form yourself.

And don't forget to change the request that the news receives that identifiers over 100,000 are not occurrences.

Or you can write your own template that displays standard Worpress material with identifiers <100,000, or your pages.

To summarize, this should not be very difficult.

ps: If you just want to use wordpress-login, use any comment system or create your own (it's 1 hour) and authenticate / use the worress-session.

0
source

Do you need to use WordPress for this? If not, maybe something in this SO question will help: Unobtrusive function of self-posting comments for posting on existing web pages

0
source

Source: https://habr.com/ru/post/1310976/


All Articles