Skip to content

Instantly share code, notes, and snippets.

@mr-gradation
Created March 2, 2022 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mr-gradation/bd21b0bb6eb1fb13edb5c8f99d041062 to your computer and use it in GitHub Desktop.
Save mr-gradation/bd21b0bb6eb1fb13edb5c8f99d041062 to your computer and use it in GitHub Desktop.
a-blog cmsでエントリーIDをカンマ区切りで渡すモジュール

使用方法

  1. /extension/acms/GET/Entries4Loop.php になるように Entries4Loop.php をアップロードします。
  2. 下記のようにモジュールを利用します。
{
  "entries": [
<!-- BEGIN_MODULE Entries4Loop -->
<!-- BEGIN entry:loop -->
<!-- BEGIN_MODULE\ Entry_Summary ctx="bid/%{BID}/eid/{id}" -->
<!-- BEGIN\ unit:loop --><!-- BEGIN\ entry:loop -->
    \{
      "eid": "\{eid\}",
      "rcid": "\{cid\}[rcid]",
      "url": "\{url\}[abs2rel]",
      "thumbnail": "<!-- BEGIN_IF [\{thumbnail@path\}/nem/] -->%{ARCHIVES_DIR}\{thumbnail@path\}<!-- ELSE --><!-- BEGIN image:veil -->%{ROOT_DIR}\{path\}<!-- END image:veil --><!-- END_IF -->",
      "title": "\{title\}",
      "date": "\{date#Y\}.\{date#m\}.\{date#d\}",
      "pageview": "\{eid\}[count_pageview]",
      "summary": "\{summary\}"
    \}<!-- BEGIN glue -->,<!-- END glue -->
<!-- END\ entry:loop --><!-- END\ unit:loop -->
<!-- END_MODULE\ Entry_Summary -->
<!-- END entry:loop -->
<!-- END_MODULE Entries4Loop -->
  ]
}

<?php
namespace Acms\Custom\GET;
use ACMS_GET;
use Template;
use ACMS_Corrector;
/**
* field/entry_id/99,100 のようにコンテキストを渡すと、その数だけ繰り返すloopブロックを返す
* '<!-- BEGIN_MODULE Entries4Loop --><!--END_MODULE Entries4Loop -->' で呼び出されます。
*/
class Entries4Loop extends ACMS_GET
{
public $_scope = array(
'field' => 'global',
);
function get()
{
$Tpl = new Template($this->tpl, new ACMS_Corrector());
if( strpos($this->field, 'entry_id') !== false ){
$eids = $this->Field->_aryField['entry_id'][0];
$eidsArr = explode(',', $eids);
$eidsArr = array_filter($eidsArr, 'strlen');
if( $eids ){
$i = 1;
$count = count($eidsArr);
foreach($eidsArr as $eid){
if( $i < $count ){
$Tpl->add(array_merge(array('glue', 'entry:loop')));
}
$Tpl->add('entry:loop', array('id' => $eid));
$i++;
}
}
}
return $Tpl->get();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment