more work on documentation, add new template tags

This commit is contained in:
John Bintz 2009-11-18 20:20:02 -05:00
parent b2410a2678
commit 2d03a4db01
5 changed files with 164 additions and 109 deletions

View File

@ -56,3 +56,27 @@
</p> </p>
<br style="clear: both" /> <br style="clear: both" />
<h2>Sorting and Attaching Comic Images</h2>
<p>
<img src="../images/comic-image-sorter.png" alt="Comic Image Sorter" class="alignright" />
Once images are attached to a post, you can arrange them and associate sub-image types (such as RSS and Archive images) to their parent image.
The order in which images are sorted determines how they are returned by the <code>M()</code> function, and attaching new sub-images to a parent
image causes that attached image to replace the original in calls to <code>EM()</code>.
</p>
<p>
To make them easier you see, you can adjust the image thumbnail size using the zoom slider on the left.
</p>
<p>
If you attach new images using the <em>Media Uploader</em>, click the <em>Refersh</em> button to reload the ordering. Any changes not saved via <em>Update post</em> will be lost.
</p>
<p>
The options shown are with the post attachment backend. Different backends may offer additional options from the ones presented here.
</p>
<br style="clear: both" />

View File

@ -3,9 +3,9 @@
<h2>R() and RT()</h2> <h2>R() and RT()</h2>
<p> <p>
<code>R()</code> and <code>RT()</code> find posts that are relative to the current or provided post. <code>R()</code> and <code>RT()</code> find posts that are relative to the current or provided post.
<code>R()</code> returns the found post, while <code>RT()</code> sets up the post so that you can use <code>R()</code> returns the found post, while <code>RT()</code> sets up the post so that you can use
standard WordPress template tags on the found posts as if it was part of the current Loop: standard WordPress template tags on the found posts as if it was part of the current Loop:
</p> </p>
<pre class="prettyprint lang-php"> <pre class="prettyprint lang-php">
@ -23,109 +23,109 @@ Restore(); // restore the saved Loop post
<h3>Basic Interactive Usage Sample</h3> <h3>Basic Interactive Usage Sample</h3>
<div style="overflow: hidden"> <div style="overflow: hidden">
<p><em>Mouse over each template tag on the right to see what post it will return relative to the <strong>Current Post</strong>.</em></p> <p><em>Mouse over each template tag on the right to see what post it will return relative to the <strong>Current Post</strong>.</em></p>
<div id="comicpress-relative-post-highlighter"> <div id="comicpress-relative-post-highlighter">
<ul> <ul>
<li><code class="highlight-1">R('first')</code></li> <li><code class="highlight-1">R('first')</code></li>
<li><code class="highlight-1">R('first', 'blog')</code></li> <li><code class="highlight-1">R('first', 'blog')</code></li>
<li><code class="highlight-2">R('first', 'comic')</code></li> <li><code class="highlight-2">R('first', 'comic')</code></li>
<li><code class="highlight-3">R('previous', 'blog')</code></li> <li><code class="highlight-3">R('previous', 'blog')</code></li>
<li><code class="highlight-4">R('previous', 'comic')</code></li> <li><code class="highlight-4">R('previous', 'comic')</code></li>
<li><code class="highlight-5">R('previous')</code></li> <li><code class="highlight-5">R('previous')</code></li>
<li><code class="highlight-6">R('current')</code></li> <li><code class="highlight-6">R('current')</code></li>
<li><code class="highlight-7">R('next')</code></li> <li><code class="highlight-7">R('next')</code></li>
<li><code class="highlight-8">R('next', 'comic')</code></li> <li><code class="highlight-8">R('next', 'comic')</code></li>
<li><code class="highlight-9">R('next', 'blog')</code></li> <li><code class="highlight-9">R('next', 'blog')</code></li>
<li><code class="highlight-10">R('last', 'comic')</code></li> <li><code class="highlight-10">R('last', 'comic')</code></li>
<li><code class="highlight-11">R('last', 'blog')</code></li> <li><code class="highlight-11">R('last', 'blog')</code></li>
<li><code class="highlight-11">R('last')</code></li> <li><code class="highlight-11">R('last')</code></li>
</ul> </ul>
</div> </div>
<table id="comicpress-relative-posts" cellspacing="0"> <table id="comicpress-relative-posts" cellspacing="0">
<tr> <tr>
<th>Post Name</th> <th>Post Name</th>
<th>Post Date</th> <th>Post Date</th>
<th>Post Category</th> <th>Post Category</th>
</tr> </tr>
<tr> <tr>
<td>First in Blog</td> <td>First in Blog</td>
<td>2009-01-01</td> <td>2009-01-01</td>
<td>Blog</td> <td>Blog</td>
</tr> </tr>
<tr> <tr>
<td>First in Comic</td> <td>First in Comic</td>
<td>2009-01-02</td> <td>2009-01-02</td>
<td>Comic</td> <td>Comic</td>
</tr> </tr>
<tr> <tr>
<td>Previous in Blog</td> <td>Previous in Blog</td>
<td>2009-01-03</td> <td>2009-01-03</td>
<td>Blog</td> <td>Blog</td>
</tr> </tr>
<tr> <tr>
<td>Previous in Comic</td> <td>Previous in Comic</td>
<td>2009-01-04</td> <td>2009-01-04</td>
<td>Comic</td> <td>Comic</td>
</tr> </tr>
<tr> <tr>
<td>A Previous Extra Post</td> <td>A Previous Extra Post</td>
<td>2009-01-05</td> <td>2009-01-05</td>
<td>Extra</td> <td>Extra</td>
</tr> </tr>
<tr> <tr>
<td><strong>Current Post</strong></td> <td><strong>Current Post</strong></td>
<td><strong>2009-01-06</strong></td> <td><strong>2009-01-06</strong></td>
<td><strong>Comic</strong></td> <td><strong>Comic</strong></td>
</tr> </tr>
<tr> <tr>
<td>A Next Extra Post</td> <td>A Next Extra Post</td>
<td>2009-01-07</td> <td>2009-01-07</td>
<td>Extra</td> <td>Extra</td>
</tr> </tr>
<tr> <tr>
<td>Next in Comic</td> <td>Next in Comic</td>
<td>2009-01-08</td> <td>2009-01-08</td>
<td>Comic</td> <td>Comic</td>
</tr> </tr>
<tr> <tr>
<td>Next in Blog</td> <td>Next in Blog</td>
<td>2009-01-09</td> <td>2009-01-09</td>
<td>Blog</td> <td>Blog</td>
</tr> </tr>
<tr> <tr>
<td>Last in Comic</td> <td>Last in Comic</td>
<td>2009-01-10</td> <td>2009-01-10</td>
<td>Comic</td> <td>Comic</td>
</tr> </tr>
<tr> <tr>
<td>Last in Blog</td> <td>Last in Blog</td>
<td>2009-01-11</td> <td>2009-01-11</td>
<td>Blog</td> <td>Blog</td>
</tr> </tr>
</table> </table>
<br style="clear: both" /> <br style="clear: both" />
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
$$('body').pop().observe('mouseover', function(e) { $$('body').pop().observe('mouseover', function(e) {
var all_rows = $$('#comicpress-relative-posts tr'); var all_rows = $$('#comicpress-relative-posts tr');
all_rows.invoke('removeClassName', 'highlighted'); all_rows.invoke('removeClassName', 'highlighted');
var target = e.findElement('#comicpress-relative-post-highlighter *[class*=highlight]'); var target = e.findElement('#comicpress-relative-post-highlighter *[class*=highlight]');
if (target) { if (target) {
target.className.replace(/highlight-/, '').split(',').each(function(row) { target.className.replace(/highlight-/, '').split(',').each(function(row) {
all_rows[row].addClassName('highlighted'); all_rows[row].addClassName('highlighted');
}); });
} }
}); });
</script> </script>
<h3>R() and RT() options</h3> <h3>R() and RT() options</h3>
<p> <p>
Both <code>R()</code> and <code>RT()</code> accept up to three parameters: Both <code>R()</code> and <code>RT()</code> accept up to three parameters:
</p> </p>
<pre class="prettyprint lang-php"> <pre class="prettyprint lang-php">
@ -149,25 +149,25 @@ R('previous', null, $other_post);
<h4>Valid strings</h4> <h4>Valid strings</h4>
<ul> <ul>
<li><strong><em>a category slug</em></strong>: Search for matching posts in the provided category and its children.</li> <li><strong><em>a category slug</em></strong>: Search for matching posts in the provided category and its children.</li>
<li><strong>from_post</strong>: Search for matching posts in the category this post belongs to.</li> <li><strong>from_post</strong>: Search for matching posts in the category this post belongs to.</li>
</ul> </ul>
<h4>Valid array keys and values</h4> <h4>Valid array keys and values</h4>
<p> <p>
If you want a more sophisticated search, you can provide an array that, with each match, will add the matching categories to the search list. If you want a more sophisticated search, you can provide an array that, with each match, will add the matching categories to the search list.
You can preface any of the keys with an exclamation point to remove matches from the list. You can preface any of the keys with an exclamation point to remove matches from the list.
</p> </p>
<ul> <ul>
<li><strong>child_of</strong> =&gt; <em>category slug</em>: Search for matching posts in the provided category and its children.</li> <li><strong>child_of</strong> =&gt; <em>category slug</em>: Search for matching posts in the provided category and its children.</li>
<li><strong>only</strong> =&gt; <em>category slug</em>: Search only the provided category.</li> <li><strong>only</strong> =&gt; <em>category slug</em>: Search only the provided category.</li>
<li><strong>root_of</strong> =&gt; <em>post ID or object</em>: Find the root category the post belongs to and search for posts from that category and in all children.</li> <li><strong>root_of</strong> =&gt; <em>post ID or object</em>: Find the root category the post belongs to and search for posts from that category and in all children.</li>
<li><strong>from_post</strong> =&gt; <em>post ID or object</em>: Search for matching posts in the category this post belongs to.</li> <li><strong>from_post</strong> =&gt; <em>post ID or object</em>: Search for matching posts in the category this post belongs to.</li>
<li><strong>previous</strong> =&gt; <em>category slug</em>: Search for matching posts in the category before the provided category as defined in the storyline structure.</li> <li><strong>previous</strong> =&gt; <em>category slug</em>: Search for matching posts in the category before the provided category as defined in the storyline structure.</li>
<li><strong>next</strong> =&gt; <em>category slug</em>: Search for matching posts in the category after the provided category as defined in the storyline structure.</li> <li><strong>next</strong> =&gt; <em>category slug</em>: Search for matching posts in the category after the provided category as defined in the storyline structure.</li>
<li><strong>level</strong> =&gt; <em>storyline level</em>: Search for posts in the categories defined at this level in the storyline structure, with level 1 being the topmost categories, level 2 being their direct children, etc.</i> <li><strong>level</strong> =&gt; <em>storyline level</em>: Search for posts in the categories defined at this level in the storyline structure, with level 1 being the topmost categories, level 2 being their direct children, etc.</i>
</ul> </ul>
<h2>Protect(), Unprotect(), and Restore()</h2> <h2>Protect(), Unprotect(), and Restore()</h2>
@ -198,7 +198,7 @@ Unprotect();
</pre> </pre>
<p> <p>
If you're using <code>RT()</code> tags to modify the current post, and need to work with the saved post, use <code>Restore()</code>: If you're using <code>RT()</code> tags to modify the current post, and need to work with the saved post, use <code>Restore()</code>:
</p> </p>
<pre class="prettyprint lang-php"> <pre class="prettyprint lang-php">
@ -235,3 +235,27 @@ if (apply_filters('comicpress-RT', 'last', array('child_of' => 'comic'))) {
do_action('comicpress-Unprotect'); do_action('comicpress-Unprotect');
</pre> </pre>
<h2>SL() and SC()</h2>
<p>
<code>SL()</code> and <code>SC()</code> give you access to the current storyline category information.
<code>SL()</code> lists all of the categories, in order, with the necessary metadata to traverse and understand the structure.
<code>SC()</code> lets you quickly traverse the storyline, returning category objects as it goes.
</p>
<pre class="prettyprint lang-php">
foreach (SL() as $category_id => $info) {
$category = get_category($category_id);
printf('Category %d is %d levels deep', $category->name, $info['level']);
}
// by default, SC() returns categories relative to the current post
$next = SC('next');
$previous = SC('previous');
$parent = SC('parent');
// or you can provide a category to be relative to
$next_from_three = SC('next', 3);
$previous_to_chapter_four = SC('previous', 'chapter-four');
</pre>

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB

View File

@ -174,7 +174,7 @@ function SL() {
return $storyline->_structure; return $storyline->_structure;
} }
function SC($which, $relative_to = null) { function SC($which = 'current', $relative_to = null) {
global $post; global $post;
$storyline = new ComicPressStoryline(); $storyline = new ComicPressStoryline();
@ -192,7 +192,12 @@ function SC($which, $relative_to = null) {
} }
if (!is_null($relative_to)) { if (!is_null($relative_to)) {
if ($result = $storyline->_get_field($which, $relative_to)) { if ($which == 'current') {
$result = $relative_to;
} else {
$result = $storyline->_get_field($which, $relative_to);
}
if ($result !== false) {
$category = get_category($result); $category = get_category($result);
if (!empty($category)) { if (!empty($category)) {
return $category; return $category;

View File

@ -195,6 +195,8 @@ class FunctionsTest extends PHPUnit_Framework_TestCase {
array('next', null, 3), array('next', null, 3),
array('next', 4, false), array('next', 4, false),
array('test', 4, false), array('test', 4, false),
array('current', 1, 1),
array('current', null, 2),
); );
} }