echo '<pre>';
print_r($arComments);
echo '</pre>';
а вот в верстке коммента выдает 5, но 2 последних - это 4й.... <?if($arComments):?>
<div class="comments">
<?foreach($arComments as $arComment):?>
<div>
<div>
<strong style="color: slategray;"><?=$arComment["AUTHOR_NAME"]?></strong><strong><?=$arComment["USER_LAST_NAME"]?> <?=$arComment["USER_NAME"]?></strong>
<p style=" background-color: #fff4ca; padding-top: 2px; padding-bottom: 3px;
padding-left: 4px; padding-right: 4px; color: #767676; display: inline;">
<?=$arComment["DATE_CREATE"]?></p>
<a href="<?=$arComment['ELEMENT']['DETAIL_PAGE_URL']?>" alt="<?=$arComment['ELEMENT']['NAME']?>" title="<?=$arComment['ELEMENT']['NAME']?>"><?=$arComment['ELEMENT']['NAME']?></a>
</div><br><div>
<?=$arComment["POST_TEXT"]?>
</div>
</div>
<hr>
<br>
<br>
<?endforeach;?>
</div>
<?endif;?>
<?
\Bitrix\Main\Loader::includeModule('iblock');
\Bitrix\Main\Loader::includeModule('blog');
$iblockId = 11;
$arComments = $arPostsId = $arPosts = $arElements = array();
$arSelectedFields = Array("ID", "BLOG_ID", "POST_ID", "PARENT_ID", "AUTHOR_ID", "AUTHOR_NAME", "AUTHOR_EMAIL", "AUTHOR_IP", "AUTHOR_IP1", "TITLE", "POST_TEXT", "DATE_CREATE","USER_NAME");
$dbRes = CBlogComment::GetList(
['ID' => 'ASC', 'DATE_CREATE' => 'DESC'],
[],
false,
false,
$arSelectedFields
);
while($arRes = $dbRes->Fetch()) {
$arComments[] = $arRes;
$arPostsId[] = $arRes['POST_ID'];
}
$arPostsId = array_unique($arPostsId);
$dbRes = CBlogPost::GetList(
['ID' => 'DESC'],
['ID' => $arPostsId]
);
while($arRes = $dbRes->Fetch()) {
$arPosts[$arRes['ID']] = $arRes;
}
$dbRes = \Bitrix\Iblock\PropertyTable::getList([
'select' => ['ID', 'CODE'],
'filter' => [
'=IBLOCK_ID' => $iblockId,
'=PROPERTY_TYPE' => \Bitrix\Iblock\PropertyTable::TYPE_NUMBER,
'=MULTIPLE' => 'N',
'=CODE' => [CIBlockPropertyTools::CODE_BLOG_POST]
]
]);
if($arRes = $dbRes->Fetch()) {
$propertyPostId = $arRes['ID'];
}
$dbRes = CIBlockElement::GetList(
[],
['=IBLOCK_ID' => $iblockId, 'PROPERTY_'.$propertyPostId => $arPostsId],
false,
false,
['ID', 'NAME', 'DETAIL_PAGE_URL', 'LIST_PAGE_URL', 'PROPERTY_'.$propertyPostId]
);
while($arRes = $dbRes->GetNext()) {
$propertyPostValue = $arRes['PROPERTY_'.$propertyPostId.'_VALUE'];
$arElements[$propertyPostValue] = $arRes;
}
foreach($arComments as &$arComment) {
$arComment['POST_DETAIL_TEXT'] = $arPosts[$arComment['POST_ID']]['DETAIL_TEXT'];
$arComment['ELEMENT']['NAME'] = $arElements[$arComment['POST_ID']]['NAME'];
$arComment['ELEMENT']['DETAIL_PAGE_URL'] = $arElements[$arComment['POST_ID']]['DETAIL_PAGE_URL'];
$arComment['ELEMENT']['LIST_PAGE_URL'] = $arElements[$arComment['POST_ID']]['LIST_PAGE_URL'];
}
/*
echo '<pre>';
print_r($arComments);
echo '</pre>';
*/
?>
<div class="comments">
// здесь верстка коммента, тегам присваиваешь классы, стили переносишь в css
</div>
<?=$tit?><?
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
$APPLICATION->SetTitle("Отзывы к товарам:");
?>
<?
\Bitrix\Main\Loader::includeModule('iblock');
\Bitrix\Main\Loader::includeModule('blog');
$iblockId = 12;
$arComments = $arPostsId = $arPosts = $arElements = array();
$arSelectedFields = Array("ID", "BLOG_ID", "POST_ID", "PARENT_ID", "AUTHOR_ID", "AUTHOR_NAME", "AUTHOR_EMAIL", "AUTHOR_IP", "AUTHOR_IP1", "TITLE", "POST_TEXT", "DATE_CREATE","USER_NAME");
$dbRes = CBlogComment::GetList(
['ID' => 'DESC', 'DATE_CREATE' => 'DESC'],
[],
false,
false,
$arSelectedFields
);
while($arRes = $dbRes->Fetch()) {
$arComments[] = $arRes;
$arPostsId[] = $arRes['POST_ID'];
}
$arPostsId = array_unique($arPostsId);
$dbRes = CBlogPost::GetList(
['ID' => 'DESC'],
['ID' => $arPostsId]
);
while($arRes = $dbRes->Fetch()) {
$arPosts[$arRes['ID']] = $arRes;
}
$dbRes = \Bitrix\Iblock\PropertyTable::getList([
'select' => ['ID', 'CODE'],
'filter' => [
'=IBLOCK_ID' => $iblockId,
'=PROPERTY_TYPE' => \Bitrix\Iblock\PropertyTable::TYPE_NUMBER,
'=MULTIPLE' => 'N',
'=CODE' => [CIBlockPropertyTools::CODE_BLOG_POST]
]
]);
if($arRes = $dbRes->Fetch()) {
$propertyPostId = $arRes['ID'];
}
$dbRes = CIBlockElement::GetList(
[],
['=IBLOCK_ID' => $iblockId, 'PROPERTY_'.$propertyPostId => $arPostsId],
false,
false,
['ID', 'NAME', 'DETAIL_PAGE_URL', 'LIST_PAGE_URL', 'PROPERTY_'.$propertyPostId]
);
while($arRes = $dbRes->GetNext()) {
$propertyPostValue = $arRes['PROPERTY_'.$propertyPostId.'_VALUE'];
$arElements[$propertyPostValue] = $arRes;
}
foreach($arComments as &$arComment) {
$arComment['POST_DETAIL_TEXT'] = $arPosts[$arComment['POST_ID']]['DETAIL_TEXT'];
$arComment['ELEMENT']['NAME'] = $arElements[$arComment['POST_ID']]['NAME'];
$arComment['ELEMENT']['DETAIL_PAGE_URL'] = $arElements[$arComment['POST_ID']]['DETAIL_PAGE_URL'];
$arComment['ELEMENT']['LIST_PAGE_URL'] = $arElements[$arComment['POST_ID']]['LIST_PAGE_URL'];
}
echo '<pre>';
print_r($arComments);
echo '</pre>';
print_r($propertyPostId);
?>
<?if($arComments):?>
<div class="comments">
<?foreach($arComments as $arComment):?>
<div>
<div>
<strong style="color: slategray;"><?=$arComment["AUTHOR_NAME"]?></strong><strong><?=$arComment["USER_NAME"]?></strong>
<p style=" background-color: #fff4ca; padding-top: 2px; padding-bottom: 3px;
padding-left: 4px; padding-right: 4px; color: #767676; display: inline;">
<?=$arComment["DATE_CREATE"]?></p> товару
///
<a href="<?=$arComment['ELEMENT']['DETAIL_PAGE_URL']?>" alt="<?=$arComment['ELEMENT']['NAME']?>">+<?=$arComment['ELEMENT']['NAME']?>+</a>
///
</div>
<br>
<?=$arComment["POST_TEXT"]?>
</div>
<hr>
<br>
<br>
<?endforeach;?>
</div>
<?endif;?>
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");?>
2. При добавлении комментария в элемент не записывается id поста
$dbRes = CIBlockElement::GetList(
[],
['=IBLOCK_ID' => $iblockId, 'PROPERTY_'.$propertyPostId => $arPostsId],
false,
false,
['ID', 'NAME', 'DETAIL_PAGE_URL', 'PROPERTY_'.$propertyPostId]
);
while($arRes = $dbRes->GetNext()) {
$propertyPostValue = $arRes['PROPERTY_'.$propertyPostId.'_VALUE'];
$arElements[$propertyPostValue] = $arRes;
}
[URL=http://www.hors.by/catalog/hybersport/mototsikl-ka... Kawasaki NINJA H2R 2020[/URL], чтобы это выглядело как ссылка, то есть типа того: Мотоцикл Kawasaki NINJA H2R 2020
while($arRes = $dbRes->Fetch())
{
$arPosts[$arRes['POST_ID']]['COMMENTS'][] = $arRes;
$arPosts[$arRes['POST_ID']]['ELEMENT'] = $arElements[$arRes['POST_ID']];
?>
<div><div>
<strong style="color: slategray;"><?=$arRes["AUTHOR_NAME"]?></strong><strong><?=$arRes["USER_NAME"]?></strong>
<p style=" background-color: #fff4ca; padding-top: 2px; padding-bottom: 3px;
padding-left: 4px; padding-right: 4px; color: #767676; display: inline;">
<?=$arRes["DATE_CREATE"]?></p> товару ///<?=$arRes["TITLE"]?>///</div>
<br>
<?=$arRes["POST_TEXT"]?><br>
<?=$arRes["POST_ID"]?>
</div>
<hr>
<br>
<br>
<?
}