<?CModule::IncludeModule("blog");
// выберем все комментарии к сообщению с идентификатором 1
$arOrder = Array(
"ID" => "desc",
"DATE_CREATE" => "desc"
);
$arFilter = 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");
$dbComment = CBlogComment::GetList($arOrder, $arFilter, false, false, $arSelectedFields);
while ($arComment = $dbComment->Fetch())
{
?>
<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> товару ///<?=$arPost["TITLE"]?>///</div>
<br>
<?=$arComment["POST_TEXT"]?><br>
<?=$arComment["POST_ID"]?>
</div>
<hr>
<br>
<br>
<?
}
?>
После размещения вопроса пользователю запрещается осуществлять:
4.2. Редактирование вопроса с целью его искажения или замены бессвязным текстом. На работу с каждым вопросом тратят время другие пользователи ресурса: модераторы (на его редактирование) и пользователи (на его прочтение и подготовку ответа). Соответственно, при удалении вопроса, потраченное ими время будет обесценено.
\Bitrix\Main\Loader::includeModule('iblock');
\Bitrix\Main\Loader::includeModule('blog');
$iblockId = 2;
$arPostsId = $arElements = $arPosts = [];
$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 => false],
false,
false,
['ID', 'NAME', 'DETAIL_PAGE_URL', 'PROPERTY_'.$propertyPostId]
);
while($arRes = $dbRes->GetNext()) {
$propertyPostValue = $arRes['PROPERTY_'.$propertyPostId.'_VALUE'];
$arPostsId[] = $propertyPostValue;
$arElements[$propertyPostValue] = $arRes;
}
$arPostsId = array_unique($arPostsId);
$dbRes = CBlogPost::GetList(
['ID' => 'DESC'],
['ID' => $arPostsId]
);
while($arRes = $dbRes->Fetch()) {
$arPosts[$arRes['ID']] = $arRes;
}
$dbRes = CBlogComment::GetList(
['ID' => 'DESC'],
['POST_ID' => $arPostsId]
);
while($arRes = $dbRes->Fetch()) {
$arPosts[$arRes['POST_ID']]['COMMENTS'][] = $arRes;
$arPosts[$arRes['POST_ID']]['ELEMENT'] = $arElements[$arRes['POST_ID']];
}
print_r($arPosts);
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>
<?
}
\Bitrix\Main\Loader::includeModule('iblock');
\Bitrix\Main\Loader::includeModule('blog');
$iblockId = 2;
$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', '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'];
}
echo '<pre>';
print_r($arComments);
echo '</pre>';
<?if($arComments):?>
<div class="comments">
<?foreach($arComments as $arComment):?>
// здесь верстка коммента, тегам присваиваешь классы, стили переносишь в css
<?endforeach;?>
</div>
<?endif;?>
[URL=http://www.hors.by/catalog/hybersport/mototsikl-ka... Kawasaki NINJA H2R 2020[/URL], чтобы это выглядело как ссылка, то есть типа того: Мотоцикл Kawasaki NINJA H2R 2020
$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;
}
2. При добавлении комментария в элемент не записывается id поста
<?=$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");?>
$blogId = 1;
$arLastComment = [];
$dbRes = CBlogComment::GetList(
['ID' => 'DESC'],
['BLOG_ID' => $blogId],
false,
['nTopCount' => 1]
);
if($arRes = $dbRes->Fetch()) {
$arLastComment = $arRes;
}
echo '<pre>';
print_r($arLastComment);
echo '</pre>';
<?
\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>
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;?>
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'];
}
unset($arComment);