1
heyula
New Block for Publisher Module
  • 2021/11/27 11:11

  • heyula

  • Theme Designer

  • Posts: 548

  • Since: 2008/4/24


With this code, you can pull content added to the publisher module wherever you want in your theme. Add to your theme:
<{includeq file="$theme_name/random-news.tpl"}>
or 
<{
includeq file="$theme_name/date-news.tpl"}>
Code Content : Random News :
<{php}>
use 
XoopsModulesPublisher;
use 
XoopsModulesPublisherConstants;

$helper PublisherHelper::getInstance();
$myts =& MyTextSanitizer::getInstance();
$itemsObj $helper->getHandler('Item')->getItems($limit 3$start 0, [Constants::PUBLISHER_STATUS_PUBLISHED], -1$sort 'RAND()'$order=''''true$criteria null);
$totalItems count($itemsObj);

global 
$items;
$items = array();
if (
$itemsObj) {
    for ( 
$i 0$i $totalItems$i++ ) {
        
$newItems['itemid']       = $itemsObj[$i]->itemid();
        
$newItems['title']        = $itemsObj[$i]->title();
        
$newItems['body']         = $itemsObj[$i]->body();
        
$newItems['votes']        = $itemsObj[$i]->votes();
        
$newItems['image']        = XOOPS_URL '/uploads/blank.gif';
        
$images $itemsObj[$i]->getImages();
        if (
is_object($images['main'])) {
            
$newItems['image'] = XOOPS_URL '/uploads/' $images['main']->getVar('image_name');
        }
    
$items[] = $newItems;
    }
}
<{/
php}>
<!-- 
Slider -->
        
        
            <{
php}>
        foreach ( 
$GLOBALS['items'] as $myrow )
        {
            
$GLOBALS['xoopsTpl']->assign('itemid'$myrow['itemid']);
            
$GLOBALS['xoopsTpl']->assign('title'$myrow['title']);
            
$GLOBALS['xoopsTpl']->assign('body'$myrow['body']);
            
$GLOBALS['xoopsTpl']->assign('votes'$myrow['votes']);
            
$GLOBALS['xoopsTpl']->assign('image'$myrow['image']);
        <{/
php}>
<
div class="col-lg-4 col-md-12 col-xl-4">
<
div class="card">
                <
div class="img-fix-height cover-image">
                <
img src="<{$image}>">
                </
div>
                <
div class="card-body p-4">
                    <
a href="<{$xoops_url}>/modules/publisher/item.php?itemid=<{$itemid}>" class="text-dark"><h4 class="font-weight-semibold text-truncate mb-3"><{$title}></h4></a>
                    <
class="fix-max-height"><{$body|truncate:230}></p>
                    <
br>
                    <
class="btn btn-primary btn-teal" href="<{$xoops_url}>/modules/publisher/item.php?itemid=<{$itemid}>">Read more</a>
                </
div>
</
div>
</
div>
        <{
php}>
        }
        <{/
php}>
Date News :
<{php}>
use 
XoopsModulesPublisher;
use 
XoopsModulesPublisherConstants;

$helper PublisherHelper::getInstance();
$myts =& MyTextSanitizer::getInstance();
$itemsObj $helper->getHandler('Item')->getItems($limit 3$start 0, [Constants::PUBLISHER_STATUS_PUBLISHED], -1$sort 'datesub'$order='DESC'''true$criteria null);
$totalItems count($itemsObj);

global 
$items;
$items = array();
if (
$itemsObj) {
    for ( 
$i 0$i $totalItems$i++ ) {
        
$newItems['itemid']       = $itemsObj[$i]->itemid();
        
$newItems['title']        = $itemsObj[$i]->title();
        
$newItems['body']         = $itemsObj[$i]->body();
        
$newItems['votes']        = $itemsObj[$i]->votes();
        
$newItems['image']        = XOOPS_URL '/uploads/blank.gif';
        
$images $itemsObj[$i]->getImages();
        if (
is_object($images['main'])) {
            
$newItems['image'] = XOOPS_URL '/uploads/' $images['main']->getVar('image_name');
        }
    
$items[] = $newItems;
    }
}
<{/
php}>
<!-- 
Slider -->
        
        
            <{
php}>
        foreach ( 
$GLOBALS['items'] as $myrow )
        {
            
$GLOBALS['xoopsTpl']->assign('itemid'$myrow['itemid']);
            
$GLOBALS['xoopsTpl']->assign('title'$myrow['title']);
            
$GLOBALS['xoopsTpl']->assign('body'$myrow['body']);
            
$GLOBALS['xoopsTpl']->assign('votes'$myrow['votes']);
            
$GLOBALS['xoopsTpl']->assign('image'$myrow['image']);
        <{/
php}>
<
div class="col-lg-4 col-md-12 col-xl-4">
<
div class="card">
                <
div class="img-fix-height cover-image">
                <
img src="<{$image}>">
                </
div>
                <
div class="card-body p-4">
                    <
a href="<{$xoops_url}>/modules/publisher/item.php?itemid=<{$itemid}>" class="text-dark"><h4 class="font-weight-semibold text-truncate mb-3"><{$title}></h4></a>
                    <
class="fix-max-height"><{$body|truncate:230}></p>
                    <
br>
                    <
class="btn btn-primary btn-teal" href="<{$xoops_url}>/modules/publisher/item.php?itemid=<{$itemid}>">Read more</a>
                </
div>
</
div>
</
div>
        <{
php}>
        }
        <{/
php}>
Definitions in Code : 7th in line of code
$limit 3  How many articles are published
$start 
0  From which category (for all categories)
Template:
<{$title}> = Article Title
<{$itemid}> = Article ID
<{$body|truncate:230}> = Article Content
<{$xoops_url}>/modules/publisher/item.php?itemid=<{$itemid}> = Article Link
<{$image}> = Article Image
<{$votes}> = Article Votes
Sample: Resized Image
Download: https://erenyumak.com/modules/TDMDownloads/singlefile.php?lid=12

2
heyula
Re: New Block for Publisher Module
  • 2021/11/27 11:19

  • heyula

  • Theme Designer

  • Posts: 548

  • Since: 2008/4/24



3
Mamba
Re: New Block for Publisher Module
  • 2021/11/27 11:53

  • Mamba

  • Moderator

  • Posts: 11230

  • Since: 2004/4/23


AWESOME!!!!

BTW - you don't need to use the "q" in "includeq" anymore - just use "include"
Support XOOPS => DONATE
Use 2.5.10 | Docs | Modules | Bugs

4
liomj
Re: New Block for Publisher Module
  • 2021/11/27 23:04

  • liomj

  • Just popping in

  • Posts: 66

  • Since: 2012/4/10


nice

this somehow need to be integrate and merged to publisher module

5
heyula
Re: New Block for Publisher Module
  • 2021/11/28 10:36

  • heyula

  • Theme Designer

  • Posts: 548

  • Since: 2008/4/24


Quote:

liomj wrote:
nice

this somehow need to be integrate and merged to publisher module


+1

I asked zyspec
I asked if it would be possible to turn it into a Smarty plugin somehow.

class/smarty/xoops_plugins/function.publisher.block.php



In this way, we can make the blocks we want by using smart codes all over the theme.

Login

Username:
Password:

Lost Password? Register now!

Who's Online

51 user(s) are online (31 user(s) are browsing Support Forums)


Members: 0


Guests: 51


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Jan 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits