Для отображения списка добавленных новостей для начала нужно в панели управления сайтом создать страницу новостей с адресом страницы /news
и с шаблоном страницы Новости (news.html)
. Затем добавить хотя бы одну новость через страницу "Новости сайта" в панели управления сайтом. Теперь в шаблоне news.html
в месте, где необходимо вывести новости прописываем следующий код:
{% set st = 0 %}
{% set newsCount = 15 %}
{% if xget('page') > 0 %}
{% set st = (xget('page') - 1) * newsCount %}
{% endif %}
{{widgetRenderByType(
'blog', {
widget_name: 'news',
start: st,
limit: newsCount,
}
)}}
CSS код для выводимых новостей:
.news_view1 {
padding: 15px 0 30px;
position: relative;
min-height: 110px;
}
.news_view1 .img_box1 {
height: 110px;
width: 200px;
float: left;
margin: 0 15px 0 0 ;
overflow: hidden;
}
.news_view1 .img_box1 img {
width: 100%;
}
.news_view1 h2 {
font-size: 14px;
font-weight: bold !important;
margin: 0 0 5px 0 !important;
padding: 0;
line-height: 15px;
text-align: left;
}
.news_view1 .link1 {
float: right;
font-size: 12px;
}
.h50 {
line-height: 18px;
font-size: 12px;
}
Или (без переключателей страниц и поиска):
{% set st = 0 %}
{% set newsCount = 10 %}
{% if xget('page') > 0 %}
{% set st = (xget('page') - 1) * newsCount %}
{% endif %}
{% set r = widgetDataByType(
'blog', {
widget_name: 'news',
start: st,
limit: newsCount,
filter: {
public: 1,
lang: (site.languages[currentlang] is defined ? currentlang : site.langdefault),
'<=ugmtimePublic': time(),
},
order: {
ugmtimePublic: 'desc',
},
}
) %}
{% set list = r.res %}
{% for data in list %}
<a class="popul_course" href="/news/?pkid={{data.pkid}}">
{% set data_image = template.path~'/images/noimage.png' %}
{% if data.image != '' %}
{% set data_image = '/files/sites/'~data.site_owner~'/'~data.widget_name~'/'~data.image %}
{% endif %}
<img src="{{data_image}}" />
<p>{{data.head}}</p>
</a>
{% endfor %}
Или (с переключателем страниц и поиском):
{% set widgetname = 'news' %}
{% set pkid = xget('pkid') %}
{% if pkid is not null %}
{% set addViews = ioCallAction(
'io.model.cms20.content.news.addViews', {
pkid: pkid,
}
) %}
{% set data = widgetDataByType(
'blog', {
widget_name: widgetname,
start: 0,
limit: 1,
filter: {
public: 1,
lang: (site.languages[currentlang] is defined ? currentlang : site.langdefault),
pkid: pkid,
'<=ugmtimePublic': time(),
},
viewall: 1,
}
).res.0 %}
{{setTitlePre(data.head~' - '~page.name)}}
{% if data.image is not null and data.image != '' %}
{{setMetaImage('//'~site.domain~'/files/sites/'~data.site_owner~'/'~data.widget_name~'/'~data.image)}}
{% endif %}
{% if data.tag %}
{{setMetaKeywordsPre(data.tag)}}
{% endif %}
{{writeMetaArticle(widgetname, pkid, currentlang)}}
<div class="news_p">
{% set dataimage = '/img/cms/no-img.jpg' %}
{% if data.image is not null and data.image != '' %}
{% set dataimage = '/files/sites/'~data.site_owner~'/'~data.widget_name~'/'~data.image %}
{% endif %}
<img src="{{dataimage}}" />
<h2>{{data.head}}</h2>
{{data.description | youTubeVideo | purify | raw}}
<span class="date">{{data.gmtimePublic | iostrtodate('d.m', 'Asia/Almaty')}}</span>
<div class="likes">{{data.likes}}</div>
<div class="comments">{{data.comments}}</div>
{% if data.domain is not null %}
{% set href = link('http://'~data.domain~'/news/?pkid='~data.pkid) %}
{% endif %}
<br/>
<p><a href="{{href}}" target="_blank">{{translate['eop.view_news_on_site']}}</a></p>
<p><a href="{{link('/news')}}">{{translate['eop.all_news']}}</a></p>
<!-- комментарии -->
<style type="text/css">
#comments .item{
padding-bottom:15px;
}
#comments .avatar{
width: 28px;
height: 25px;
display: inline;
float: left;
margin: 0 6px 0 0;
}
#comments textarea{
width:500px;
height:100px;
}
#comments .list .list{
background: url(http://astana-bilim.kz/custom/social/eop/images/idc-grey-0404.png) no-repeat -1533px -104px;
padding: 5px 0 0 18px;
}
#comments .owner{
background: url(http://astana-bilim.kz/custom/social/eop/images/idc-universal.png) 100% 0;
height: 32px;
margin: 0 0 8px;
line-height: 28px;
}
</style>
<div style="clear: both;"></div>
<h2 style="margin: 15px 0;">{{translate['eop.comment']}}</h2>
<div id="comments">
{{widgetCommentsRender({
foreignPkid: pkid,
order: {
gmtimeAdd: 'asc',
},
div: '<div class="item level" id="comment-%pkid%">
<div class="avatar">
<img src="%avatar%" />
</div>
<div class="data">
<div class="owner">%owner% | %datetime%
{% if (user.isAdmin or user.isSuperAdmin or permission2("self.cms.'~site.id~'.comments.manage")) and not user.isGuest %}
<a class="live-dialog cursor" data-href="/entity/io.model.social.comments.showDelete/?pkid=%pkid%&site_pkid={{site.id}}&jsEvent=jsEvent%CommentsID%&formResultType=json&formResponseOut=0">
<img src="/img/common/del.png">
</a>
{% endif %}
</div>
<div class="content">%text%</div>
{#<!--
{% if not user.isGuest %}
<div id="f_r">
<a class="live-answer" data-res="answer%pkid%" data-href="/entity/io.model.social.comments.showAdd/?foreignPkid=%foreignPkid%&parent_pkid=%pkid%" >Ответить</a>
</div>
{% endif %}
-->#}
</div>
<div style="clear: both;"></div>
</div>'
})}}
</div>
</div>
{% else %}
{% set filter = {public: 1, lang: (site.languages[currentlang] is defined ? currentlang : site.langdefault), '<=ugmtimePublic': time()} %}
{% if xget('category') is not null %}
{% set filter = xadd(filter, 'category', xget('category')) %}
{% endif %}
{% if xget('text') is not null %}
{% set filter = xadd(filter, 'text', xget('text')) %}
{% endif %}
{% if xget('city') is not null and neqi(xget('city'), '0') %}
{% set filter = xadd(filter, 'city', xget('city')) %}
{% elseif xget('region') is not null and neqi(xget('region'), '0') %}
{% set filter = xadd(filter, 'region', xget('region')) %}
{% elseif xget('country') is not null and neqi(xget('country'), '0') %}
{% set filter = xadd(filter, 'country', xget('country')) %}
{% endif %}
{% set onpage = 12 %}
{% set start = (xget('page', 1) - 1) * onpage %}
{% set r = widgetDataByType(
'blog', {
widget_name: widgetname,
start: start,
limit: onpage,
filter: filter,
order: {
ugmtimePublic: 'desc',
},
}
) %}
{% set list = r.res %}
{% set list_count = r.count %}
<form id="FormNews">
<input type="hidden" name="account" value="{{xget('account')}}" />
<input type="text" id="search-input" name="entitypost[news][text]" class="element" value="{{xget('text')}}" placeholder="{{translate['eop.poisk']}}" maxlength="140" />
<input id="search-button" type="submit" name="search_button" />
</form>
<div style="clear:both;"></div>
<script type="text/javascript">
function newsSearch(event, params){
if(event != 'before') return;
var url = window.location;
//console.log(params);
var formData = null;
if((typeof params.formData) != 'undefined') formData = params.formData;
for(var d in formData){
var str = new String(d);
var val = formData[d];
var key = str.substring(17, str.length - 1);
url = urlGetAdd(url, key, val);
}
//console.log(url);
window.location = url;
}
$('#search-input').keydown(function(e){
if(e.which == 13){
var formData = new Object();
$('#FormNews .element').each(function(){
var name = $(this).attr('name');
var val = $(this).val();
formData[name] = val;
});
newsSearch('before', {
div: null,
formData: formData,
jqForm: null,
options: null
});
e.preventDefault();
}
});
</script>
<div class="view_sp" data-widget-name="{{widgetname}}"{% if user.isAdmin %} data-href="{{link(urlGetAdd('/options/widget/settings/'~page.pkid~'/'~widgetname, 'account', user.adminAccount))}}"{% endif %}>
<div id="com_container">
{% for item in list %}
{% set href = link('/news/?pkid='~item.pkid) %}
{% if item.domain is not null %}
{% set href = link('http://'~item.domain~'/news/?pkid='~item.pkid) %}
{% endif %}
<div class="com_view">
<div class="img">
<a href="{{link("/news/?pkid="~item.pkid)}}">
{% set itemimage = '/img/cms/no-img.jpg' %}
{% if item.image is not null and item.image != '' %}
{% set itemimage = '/files/sites/'~item.site_owner~'/'~item.widget_name~'/'~item.image %}
{% endif %}
<img src="{{itemimage}}" />
</a>
</div>
<h2><a href="{{link("/news/?pkid="~item.pkid)}}">{{item.head}}</a></h2>
<div class="date">{{item.gmtimePublic | iostrtodate('d.m.Y', 'Asia/Almaty') }}</div>
<div class="likes">{{item.likes}}</div>
<div class="comments">{{item.comments}}</div>
<div class="description">{{cutString(item.about | purify, 200, '') | striptags}}</div>
<a href="{{link("/news/?pkid="~item.pkid)}}" class="link1">{{translate['eop.more']}} >></a>
</div>
{% endfor %}
</div>
{% set ppage = max(xget('page', 0), 1) %}
{% set alfa = 1 %}
{% set count = (list_count / onpage) | ceil %}
{% if count > 1 %}
<div class="pagination">
<center>
<ul>
<li class="cursor" data-page="{{max(ppage - 1, 1)}}"><a><<</a></li>
{% set class = 'cursor' %}
{% if 1 == ppage %}
{% set class = 'disabled' %}
{% endif %}
<li class="{{class}}" data-page="1">
<a href="{{link(urlGetAdd(site.fulluri, 'page', 1))}}">1</a>
</li>
{% if ppage - alfa > 2 %}
<li class="disabled"><a>...</a></li>
{% endif %}
{% set a1 = max(ppage - alfa, 2) %}
{% set a2 = min(ppage + alfa, count - 1) %}
{% if a2 >= a1 %}
{% for i in range(a1, a2) %}
{% set class = 'cursor' %}
{% if i == ppage %}
{% set class = 'disabled' %}
{% endif %}
<li class="{{class}}" data-page="{{i}}">
<a href="{{link(urlGetAdd(site.fulluri, 'page', i))}}">{{i}}</a>
</li>
{% endfor %}
{% endif %}
{% if ppage + alfa < count - 1 %}
<li class="disabled"><a>...</a></li>
{% endif %}
{% if count > 1 %}
{% set class = 'cursor' %}
{% if count == ppage %}
{% set class = 'disabled' %}
{% endif %}
<li class="{{class}}" data-page="{{count}}">
<a href="{{link(urlGetAdd(site.fulluri, 'page', count))}}">{{count}}</a>
</li>
{% endif %}
<li class="cursor" data-page="{{ppage + 1}}">
<a href="{{link(urlGetAdd(site.fulluri, 'page', ppage + 1))}}">>></a>
</li>
</ul>
</center>
</div>
{% endif %}
</div>
{% endif %}
Для отображения списка добавленных новостей какого либо другого сайта платформы, прописываем следующий код:
{% set r = widgetDataByType(
'blog', {
widget_name: 'news',
start: start,
limit: onpage,
filter: filter,
searchall: true,
order: {
site_owner: [000001],
ugmtimePublic: 'desc',
},
}
) %}
{% set list = r.res %}
{% set list_count = r.count %}
Где Для отображения списка добавленных новостей каких либо нескольких других сайтов платформы, прописываем следующий код:000001
это pkid сайта
{% set r = widgetDataByType(
'blog', {
widget_name: 'news',
start: start,
limit: onpage,
filter: filter,
searchall: true,
order: {
site_owner: [000001, 000002, 000003],
ugmtimePublic: 'desc',
},
}
) %}
{% set list = r.res %}
{% set list_count = r.count %}
Где 000001
, 000002
, 000003
это pkid сайтов