This is my code for the blog template, I hope it helps (I use 3 templates, one for each depth, blog template, category template, article template:
Ditto Call: for the "Blog template"
[!Ditto? &id=`a` &parents=`[*id*]` &depth=`2` &display=`15` &tpl=`blog-ditto` &orderBy=`createdon DESC` &hideFolders=`1` &paginateAlwaysShowLinks=`1` &paginate=`1`!]
<!-- [Pagination] -->
[!DittoPageSplit? &id=`a` &output=`1`!]
<!-- [/End Pagination] -->
Chunk: blog-ditto
<!-- [Blog Intro] -->
<article>
<header>
<h2><a href="[+url+]">[+longtitle+]</a></h2>
<!-- [Author Info, Comments, Category] -->
<p>
Post by <strong>[[author? &id_author=`[+createdby+]`]]</strong>, [+createdon:date=`%d/%m/%Y`+],
[+phx:if=`[[Jot? &action=`count-comments` &docid=`[+id+]`]]`:is=`0`:then=`[[Jot? &action=`count-comments` &docid=`[+id+]`]]`:else=`<a href="[(site_url)][~[+id+]~]#comments-link">[[Jot? &action=`count-comments` &docid=`[+id+]`]]</a>`+]</span>.
Category: <a href="[~[[getfield? &docid=`[+parent+]` &field=`id`]]~]">[[getfield? &docid=`[+parent+]` &field=`menutitle`]]</a>
</p>
<!-- [/End Author Info, Comments, Category] -->
</header>
<!-- [Introtext] -->
<p>[+content:character_limit=`260`+]...</p>
<!-- [/End Introtext] -->
<div class="clear"></div>
</article>
<!-- [/End Blog Intro] -->
Snippets I've been using:
DittoPageSplit: with this you can generate the pagination
<?php
//only for forum highlighting
// Place immediately following a Ditto call
// Based on the function written by Aaron Hall, evilwalrus.org
// Ditto 2.1 start page fix & PHx workaround: Eol ([email protected])
if (!function_exists("generatePagination")) {
function generatePagination($curPage, $totResults, $resultsPerPage) {
$totPages = ceil($totResults / $resultsPerPage);
$pagesBefore = $curPage - 1;
$pagesAfter = $totPages - $curPage;
$tabArr = array();
if ($totPages > 15) {
if ($pagesBefore > 7) {
$tabArr = array(1, 2, 0);
if ($pagesAfter > 7) {
for ($i=($curPage-4); $i<$curPage; $i++) { $tabArr[] = $i; }
} else {
for ($i=($totPages-11); $i<$curPage; $i++) { $tabArr[] = $i; }
}
} else {
for ($i=1; $i<$curPage; $i++) { $tabArr[] = $i; }
}
$tabArr[] = $curPage;
if ($pagesAfter > 7) {
if ($pagesBefore > 7) {
for ($i=($curPage+1); $i<=$curPage+4; $i++) { $tabArr[] = $i; }
} else {
for ($i=($curPage+1); $i<13; $i++) { $tabArr[] = $i; }
}
$tabArr[] = 0;
$tabArr[] = $totPages-1;
$tabArr[] = $totPages;
} else {
for ($i=($curPage+1); $i<=$totPages; $i++) { $tabArr[] = $i; }
}
} else {
for ($i=1; $i<=$totPages; $i++) { $tabArr[] = $i; }
}
return $tabArr;
}//function generatePagination end
}
$id = isset($id) ? $id.'_' : '';
$total = isset($total) ? $total : $modx->getPlaceholder($id."total");
$start = isset($start) ? $start : $modx->getPlaceholder($id."urlStart");
$summarize = isset($summarize) ? $summarize : $modx->getPlaceholder($id."perPage");
$currentPage = isset($currentPage) ? $currentPage : $modx->getPlaceholder($id."current");
$landing = isset($tagDocumentID) ? $tagDocumentID : $modx->documentObject['id'];
if ($total == 0 || $summarize == 0) {
return false;
}
$page = ($start/$summarize)+1;
$output = isset($output) ? $output : 0;
$paginationArray = generatePagination($page, $total, $summarize);
$ph = "";
$cInc = $_GET[$id.'start'];
foreach ($paginationArray as $page) {
$inc = ($page-1) * $summarize;
if ($page == 0) {
$ph .= ""; // represents pages that aren't displayed
} else if ($inc == $cInc) {
if ($total == 1) { $ph = ""; } else {
$ph .= "<span class=\"pagination-current\">{$page}</span>"; }
} else {
$ph .= "<a class=\"page\" href=\"".ditto::buildURL("start=".$inc, $landing, $id)."\">{$page}</a>\n";
}
}
$modx->setPlaceholder("{$id}pagesplit", $ph);
if ($output) {
if ($ph == "") return "";
return "<div class=\"pagination\"><span class=\"pagination-title\">Pages:</span> {$ph}</div>";
}
?>
author: with this you can display the author name
<?php
$editedby_id = empty($id_author) ?
$modx->documentObject['createdby'] : $id_author;
// sample conversion
$user_info = $modx->getUserInfo($editedby_id);
$editedby_name = ($user_info['fullname'] ? $user_info['fullname'] : $user_info['username']);
return $user_info['fullname'];
?>
phx:character_limit: with this you can crop the main content text and strip html tags
<?php
if (strlen($output) > $options) {
$output = $modx->stripTags($output, '');
$output_cutted = substr($output, 0, $options);
$last_space = strrpos($output_cutted, " ");
$output = substr($output_cutted, 0, $last_space) . "";
} else {
$output = $modx->stripTags($output, '');
}
return $output;
?>
getfield: with this you can get a value from a tv that is in another resource
<?php
/*
==================================================
GetField
==================================================
Returns any document field or template variable from any document or any of its parents.
Author: Grzegorz Adamiak [grad]
Version: 1.3 beta @2006-11-08 14:40:04
License: LGPL
MODx: 0.9.2.1+
See GetField.txt for instructions and version history.
--------------------------------------------------
*/
/* Parameters
----------------------------------------------- */
# $docid [ int ]
# ID of the document for which to get a field content.
# Default: current document
$gfIntDocId = (isset($docid)) ? $docid : $modx->documentIdentifier;
# $field [ string ]
# Name of the field for which to get the content:
# - any of the document object fields (http://modxcms.com/the-document-object.html)
# - template variable
# Default: 'pagetitle'
$gfStrDocField = (isset($field)) ? trim($field) : 'pagetitle';
# $parent [ 0 | 1 ]
# If set to 1, the snippet will return value for the document parent.
# Default: 0
$gfBoolParent = (isset($parent)) ? $parent : 0;
# $parentLevel [ int ]
# Specifies how high in the document tree to search for the parent of the document:
# - $parentLevel = 0 - returns the ultimate parent (right under site root)
# - $parentLevel = 1 - returns the direct parent
# Default: 0
$gfIntParentLevel = (isset($parentLevel) && is_int((int) $parentLevel)) ? $parentLevel : 0;
# $topid [ int ]
# Id of the topmost document in the document tree under which to search for a parent. Used only with $parent set to 1.
# Default: 0
$gfIntTopDocId = (isset($topid) && is_int((int) $topid)) ? $topid : 0;
/* Do not edit the code below!
----------------------------------------------- */
# Include logic
include_once('assets/snippets/getfield/getfield.inc.php');
# Get parent document ID
if ($gfBoolParent)
$gfIntDocId = gfGetParentId($modx, $gfIntDocId, $gfIntTopDocId, $gfIntParentLevel);
# Get content of the field
$output = gfGetFieldContent($modx,$gfIntDocId,$gfStrDocField);
unset($gfIntDocId, $gfStrDocField, $gfBoolParent, $gfIntParentLevel, $gfIntTopDocId);
return $output;
?>
PHx plugin for conditional comments:
http://modx.com/extras/package/phx
TemplateRules plugin to automatically change template depending on tree depth (As I said, I use a template for the blog page, another template for the category page, and another for the article page):
http://forums.modx.com/index.php?topic=38684.0
Ditto call: for the "Category template"
[!Ditto? &id=`a` &parents=`[*id*]` &depth=`1` &display=`10` &tpl=`blog-ditto` &orderBy=`createdon DESC` &paginateAlwaysShowLinks=`1` &paginate=`1`!]
<!-- [Pagination] -->
[!DittoPageSplit? &id=`a` &output=`1`!]
<!-- [/End Pagination] -->