开发者

How to show comments on nodes that are on the Drupal 7 default home page (promoted)?

开发者 https://www.devze.com 2023-04-07 00:31 出处:网络
I have a Drupal 7 installation with a default front page and a few article nodes \"promoted to the front page\". These are displayed as teasers and in node--article.tpl.php I have a template for my te

I have a Drupal 7 installation with a default front page and a few article nodes "promoted to the front page". These are displayed as teasers and in node--article.tpl.php I have a template for my teasers and this all works fine. The node teasers display as expected.

On each teaser there is a link that says "View full story". I want to use Ajax to expand the teaser into the full story in place on the home page (I have some fancy animations etc but that's besides the point)

So I have a custom module that accepts a nid parameter, loads the node, an开发者_JAVA技巧d returns it to my javascript/jQuery. I am using the jQuery.load() function to make this request.

This again all works fine, the teaser is replaced by the full node version which uses the same node--article.tpl.php to define it's appearance.

The trouble is, I have comments enabled on articles and on an individual articles page the form and comments show up fine, but when loaded via ajax as described above, the comments don't appear along with the rest of the full node.

Is this due to it being the front page? I have print_r'd the $content array and I don't see the comments there at all. Is there a simple workaround for this or am I going to have to write a little module to manually grab the comments and comment form and append them to my nodes after loading?


The problem is that node_load (which I assume your module uses) does not load the comments. You'll need to modify the module so that it grabs them, something like:

$comments = db_select('comment','c')
                       ->condition('nid', $nid, '=')
                       ->execute()
                       ->fetchAssoc();
0

精彩评论

暂无评论...
验证码 换一张
取 消