Jump to content

All the comments belonging to a particular field?


ZionBludd
 Share

Recommended Posts

Hi, on my website I have the comments system implemented across each store page. I am wanting to see if their is a built in function to allow to bring in all of the comments for a particular brand into one page

Store Listing 1 (Belongs to store brand XYZ)

Store Listing 2 (Belongs to store brand XYZ)

Store Brand Listing Page (Lists all of the store listings, plus all of the comments from Store listing 1 & Store Listing 2)

 

Link to comment
Share on other sites

From what I understand, you want to list comments from each product page on the product brand page?

Comments documentation is here: https://processwire.com/docs/modules/guides/comments/

If you look at the section in the docs titled OPTIONAL : Generating your own output it has this example code:

foreach($page->comments as $comment) {
    if($comment->status < 1) continue; // skip unapproved or spam comments
    $cite = htmlentities($comment->cite); // make sure output is entity encoded
    $text = htmlentities($comment->text);
    $date = date('m/d/y g:ia', $comment->created); // format the date
    echo "<p><strong>Posted by $cite on $date</strong><br />$text</p>";
}

Of course you can always replace the $page variable in that example with your own variable that returns a page, so you could do something like:

$brandProducts = $page->children();
$foreach($brandProducts as $product){
  foreach($product->comments as $comment) {
      if($comment->status < 1) continue; // skip unapproved or spam comments
      $cite = htmlentities($comment->cite); // make sure output is entity encoded
      $text = htmlentities($comment->text);
      $date = date('m/d/y g:ia', $comment->created); // format the date
      echo "<p><strong>Posted by $cite on $date</strong><br />$text</p>";
  }
}

If your products aren't children of a brand, but simply have a brand field set using a page reference field for example, you'd need to use a selector instead to populate $brandProducts eg

$brandProducts = $pages->find("brand={$page->brand}");

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...