Jump to content

ID топиков


Recommended Posts

Пытаюсь использовать данный код (шаблон блока Лента тем)

{{if !empty( $topics ) }}
	{{if \count($topics)}}
		{{foreach $topics as $id => $topic}}
			{{if $id == 0}}
				<ul class='ipsGrid ipsGrid_collapsePhone'>
					{template="row" group="global" app="forums" location="front" params="NULL, NULL, $topic, FALSE"}
				</ul>
			{{else}}
				{{if $id % 2}}
					<ul class='ipsGrid ipsGrid_collapsePhone'>
				{{endif}}
					{template="row" group="global" app="forums" location="front" params="NULL, NULL, $topic, FALSE"}
				{{if  $id % 2 == 0 or ( \count( $topics ) == ( $id + 1) )}}
					</ul>
				{{endif}}
			{{endif}}
		{{endforeach}}
	{{endif}}
{{endif}}

в котором подключается шаблон row

{{$idField = $topic::$databaseColumnId;}}
{{$iPosted = isset( $table->contentPostedIn ) ? $table->contentPostedIn : ( ( $table AND method_exists( $table, 'container' ) AND $topic->container() !== NULL ) ? $topic->container()->contentPostedIn() : array() );}}
<div class='{{if $id}}ipsGrid_span3{{else}}ipsGrid_span6{{endif}} ipsBox'>
{{$post = $topic->topic_firstpost ? \IPS\forums\Topic\Post::load($topic->topic_firstpost)->post : NULL;}}
{{if $post AND \preg_match( '#<fileStore.core_Attachment>\S+(?:jpg|jpeg|png|webp)#', $post, $image_url )}}
  <div>
  {{$image_url = \str_replace('<fileStore.core_Attachment>', \IPS\File::getClass('core_Attachment')->baseUrl(), $image_url[0]);}}
  {{if settings.lazy_load_enabled}}                 
  <a href="{$topic->url( "getPrefComment" )}" title="{lang="read_more_about" sprintf="$topic->_title"}" >
    <img class='ipsImage' src='{expression="\IPS\Text\Parser::blankImage()"}' alt='{wordbreak="$topic->_title"}' data-src='{file="$image_url" extension="core_Attachment"}'></a>
  {{else}}
  <a href="{$topic->url( "getPrefComment" )}" title="{lang="read_more_about" sprintf="$topic->_title"}" >
    <img class='ipsImage' alt='{wordbreak="$topic->_title"}' src='{file="$image_url" extension="core_Attachment"}'></a>                     
  {{endif}}
  </div>
{{endif}}
<div>
	<h4 class='ipsDataItem_title ipsContained_container'>			
	<span class='ipsType_break ipsContained'><a href='{$topic->url( "getPrefComment" )}' {{if $topic->canView()}}data-ipsHover data-ipsHover-target='{$topic->url()->setQueryString('preview', 1)}' data-ipsHover-timeout='1.5' {{endif}}>{$topic->mapped('title')}</a></span>
	</h4>
	
	<p class='ipsType_reset ipsType_medium ipsType_light'>
	<span><i class='fa fa-clock-o'></i> {datetime="$topic->mapped('date')" lowercase="true"}</span>
	</p>
	
	{{foreach $topic->stats(FALSE) as $k => $v}}
	<span {{if $k == 'num_views'}}class=''{{elseif \in_array( $k, $topic->hotStats )}}class="ipsDataItem_stats_hot" data-text='{lang="hot_item"}' data-ipsTooltip title='{lang="hot_item_desc"}'{{endif}}>
	<span class='ipsDataItem_stats_type'>{lang="{$k}" pluralize="$v" format="short"}</span>
	<span class='ipsDataItem_stats_number'>{number="$v" format="short"}</span>	
	{{if ( $k == 'forums_comments' OR $k == 'answers_no_number' ) && \IPS\forums\Topic::modPermission( 'unhide', NULL, $topic->container() ) AND $unapprovedComments = $topic->mapped('unapproved_comments')}}
	&nbsp;<a href='{$topic->url()->setQueryString( 'queued_posts', 1 )}' class='ipsType_warning ipsType_small ipsPos_right ipsResponsive_noFloat' data-ipsTooltip title='{lang="queued_posts_badge" pluralize="$topic->topic_queuedposts"}'><i class='fa fa-warning'></i> <strong>{$unapprovedComments}</strong></a>
	{{endif}}
	</span>
	{{endforeach}}
</div>
</div>

который должен выводить сначала два топика потом четыре (по аналогу Category 2 Column First Featured в Страницах).

Понимаю что нужно каким-то образом "подцепить" id топиков, но не могу понять как именно.Кто-нибудь подскажет решение?

Edited by AHristich
Link to comment
Share on other sites

Posted (edited)

Exception спасибо,конечно,за подсказку.Только не могу понять/разобраться что и где заменить,где именно использовать.

Edited by AHristich
Link to comment
Share on other sites

Exception понял что куда,но это не совсем то что надо. Я так понимаю что в первом коде $id означает не  id топика в таблице бд,а ,скажем так,порядковый номер .То есть,сначала выводится по порядку два топика (ipsGrid_span6) а потом остальные в колонку по  четыре (ipsGrid_span3).

Типа такого

Спойлер

100744826_2023-03-0511-38-27.png.510f4d55a6bb3f6f5d874c5ec04e0e55.png

 

Link to comment
Share on other sites

В первом примере $id - индекс массива, всё правильно, а для получения id можно использовать $topic->tid

Link to comment
Share on other sites

Desti во втором коде  $id и подцепляется из массива первого кода.Проблема всего лишь одна- я ноль в рнр и т.п,как говорится лаю на такое :) 

Link to comment
Share on other sites

58 минут назад, AHristich сказал:

Desti во втором коде  $id и подцепляется из массива первого кода.Проблема всего лишь одна- я ноль в рнр и т.п,как говорится лаю на такое :) 

я не понимаю что ты хочешь

Link to comment
Share on other sites

Exception в Страницах есть шаблон Category 2 Column First Featured ,в котором есть массив

Спойлер
	{{if \count($articles)}}
		{{foreach $articles as $id => $record}}
			{{if $id == 0}}
				<ul class='ipsGrid ipsGrid_collapsePhone'>
				{template="entry" app="cms" location="database" group="category_2_column_first_featured" params="$record, $database, 0"}
				</ul>
			{{else}}
				{{if $id % 2}}
					<ul class='ipsGrid ipsGrid_collapsePhone cmsCategory2col'>
				{{endif}}
				{template="entry" app="cms" location="database" group="category_2_column_first_featured" params="$record, $database, $id"}
				{{if  $id % 2 == 0 or ( \count( $articles ) == ( $id + 1) )}}
					</ul>
				{{endif}}
			{{endif}}
		{{endforeach}}
	{{endif}}

 

entry обернут в

<li class='{{if $id}}ipsGrid_span6{{else}}ipsGrid_span12{{endif}}'>
  ...
</li>

и на сайте выглядет так

976650778_2023-03-0511-38-27.png.42da32d04d3c56e07b8fe1c0bd6959bc.png

Вот я и пытаюсь использовать подобный массив для шаблона forums/front/global/row

Link to comment
Share on other sites

9 минут назад, AHristich сказал:

Вот я и пытаюсь использовать подобный массив для шаблона forums/front/global/row

так создай свой шаблон и передавай туда нужные переменные, в том числе $id

Link to comment
Share on other sites

6 часов назад, AHristich сказал:

во втором коде  $id и подцепляется из массива первого кода.

В "row" (во второй код) передается $topic, а не $id. $topic - это объект, у него есть поле tid. Ты его можешь получить напрямую, обращаясь к $topic->tid или накривую, обращаясь к статическому полю класса, в котором назначено поле базы для индекса ($topic::$databaseColumnId), как это сделано в "row".

Но пока ты не научишься задавать правильные вопросы, ты будешь получать правильные ответы, которые, однако, не отвечают на твои вопросы.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Ваша ссылка была автоматически строена.   Отображать как обычную ссылку

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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