Jump to content
Дизайн и модификация IPS Community IPBSkinsBETA
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
zigazaga

список записей категории в записи

Recommended Posts

Почти похожее можно организовать блоком, выбрав там в плагинах Страница->Лента записи, и там дается выбор из какой категории выводить или из всех. Соответственно если применить такой метод то мне нужно будет уже внутри записи применять к этому блоку категорию из которой нужно вывести записи, что не возможно сделать, так как ни у кода {block='key'} нету дополнительных параметров, ни в шаблоне блока нельзя применять категорию. Как быть?

Хочу что-то типа:

Новость "Ccc" из категории "C1" находится в базе "C1", в ней нужно вывести список записей из категории "C2" базы "C2" и т.д. задать значение из какой категории будут выводиться эти записи нужно как-то кодом, внутри шаблона 'record', так как записей много метод вставки блока не подходит.

Более простым языком: вывести из заданной в переменной $cats категории список последних 5-10 записей.

Share this post


Link to post
$value = \IPS\cms\Records1::load(1);

загружает 1 запись из базы, а как загрузить все записи из базы?

Share this post


Link to post
{{$dbId = 1;}}
{{$recordsClass = '\IPS\cms\Records' . $dbId;}}
{{$records = $recordsClass::getItemsWithPermission( array( array( 'category_id=?', 2 ) ) );}}

1 - ID базы, из которой выводить записи

2 - ID категории, из которой выводить записи

  • Like 1
  • Upvote 2

Share this post


Link to post
13.04.2020 в 10:21, newbie сказал:

{{$dbId = 1;}}
{{$recordsClass = '\IPS\cms\Records' . $dbId;}}
{{$records = $recordsClass::getItemsWithPermission( array( array( 'category_id=?', 2 ) ) );}}

1 - ID базы, из которой выводить записи

2 - ID категории, из которой выводить записи

А как мне выгрузить допустим только 5 самых новых записей? Просто я думаю, что если выгрузить разом несколько тысяч записей в переменную и потом её разбирать переменная просто лопнет

Share this post


Link to post

Смотрите метод getItemsWithPermission

	/**
	 * Get items with permission check
	 *
	 * @param	array		$where				Where clause
	 * @param	string		$order				MySQL ORDER BY clause (NULL to order by date)
	 * @param	int|array	$limit				Limit clause
	 * @param	string|NULL	$permissionKey		A key which has a value in the permission map (either of the container or of this class) matching a column ID in core_permission_index or NULL to ignore permissions
	 * @param	mixed		$includeHiddenItems	Include hidden items? NULL to detect if currently logged in member has permission, -1 to return public content only, TRUE to return unapproved content and FALSE to only return unapproved content the viewing member submitted
	 * @param	int			$queryFlags			Select bitwise flags
	 * @param	\IPS\Member	$member				The member (NULL to use currently logged in member)
	 * @param	bool		$joinContainer		If true, will join container data (set to TRUE if your $where clause depends on this data)
	 * @param	bool		$joinComments		If true, will join comment data (set to TRUE if your $where clause depends on this data)
	 * @param	bool		$joinReviews		If true, will join review data (set to TRUE if your $where clause depends on this data)
	 * @param	bool		$countOnly			If true will return the count
	 * @param	array|null	$joins				Additional arbitrary joins for the query
	 * @param	mixed		$skipPermission		If you are getting records from a specific container, pass the container to reduce the number of permission checks necessary or pass TRUE to skip container-based permission. You must still specify this in the $where clause
	 * @param	bool		$joinTags			If true, will join the tags table
	 * @param	bool		$joinAuthor			If true, will join the members table for the author
	 * @param	bool		$joinLastCommenter	If true, will join the members table for the last commenter
	 * @param	bool		$showMovedLinks		If true, moved item links are included in the results
	 * @return	\IPS\Patterns\ActiveRecordIterator|int
	 */
	public static function getItemsWithPermission( $where=array(), $order=NULL, $limit=10, $permissionKey='read', $includeHiddenItems=\IPS\Content\Hideable::FILTER_AUTOMATIC, $queryFlags=0, \IPS\Member $member=NULL, $joinContainer=FALSE, $joinComments=FALSE, $joinReviews=FALSE, $countOnly=FALSE, $joins=NULL, $skipPermission=FALSE, $joinTags=TRUE, $joinAuthor=TRUE, $joinLastCommenter=TRUE, $showMovedLinks=FALSE )
	{{$records = $recordsClass::getItemsWithPermission( array( array( 'category_id=?', 2 ) ), NULL, 5 );}}

 

  • Like 1

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...