Skip to content

Commit 1f7f484

Browse files
committed
Update documentation
1 parent bf2dd70 commit 1f7f484

2 files changed

Lines changed: 49 additions & 23 deletions

File tree

README.md

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
Updated code comments and separated the backend interface into its own folder from the main LSC files.
66

7-
#### June 3, 2016
7+
### June 3, 2016
88

99
Added much in the way of documentation and improved the backend display a bit.
1010

1111
### TODO
1212
* Separate the admin menu markup and CSS in a more elegant manner
13-
* Update the way this plugin loads to use a global registry so that we don't pollute the global namespace, so we can load Twig only when we need it, and so we only have to load shortcodes we need. This is a fairly large project that is unnecessary with the use of caching, but it would be useful to do it for shared hosting environments with low memory and/or no caching abilities.
13+
* Update the way this plugin loads to use a global registry so that we don't pollute the global namespace, so we can load Twig only when we need it, and so we only have to load shortcodes we need, all while allowing us to continue sharing dependencies. This is a fairly large project that is unnecessary with the use of caching, but it would be useful to do it for shared hosting environments with low memory and/or no caching abilities.
1414

1515
# Loop Shortcodes
1616
This WordPress plugin gives you the ability to call the Loop from shortcodes and style them using the [Twig template engine](http://twig.sensiolabs.org/). It allows you to use WordPress in a very frankenstein-like manner as a fairly powerful CMS, using inline templates in pages and posts which query other posts, users, and taxonomies on the fly.
@@ -35,11 +35,11 @@ git submodule update
3535

3636
These commands navigate the SSH shell to the plugin directory and initiate the submodules. Then, git will download Twig from the Twig repo.
3737

38-
Once all that is done, you can then turn on the plugin in your WordPress plugin directory.
38+
Once all that is done, you can then activate the plugin in your WordPress plugin directory. To validate that it's working, navigate to the Templates page in your WordPress admin menu, located in Appearance -> Loop Shortcode.
3939

4040
## Updates
4141

42-
To update the plugin to the latest version, ssh into your ```wp-content/plugins/wp-twig-loop-shortcode/``` directory and simply type
42+
To update this plugin to the latest version, ssh into your ```wp-content/plugins/wp-twig-loop-shortcode/``` directory and type:
4343

4444
```
4545
git pull
@@ -205,15 +205,15 @@ Optional arguments:
205205

206206
### Environments
207207

208-
Environments are optional features that help you reduce post duplication on pages with multiple query strings. Every environment is defined in loop shortcode you use. For example:
208+
Environments are optional features that help you reduce post duplication on pages with multiple query strings by saving the posts into a global registry that you can access in order to exclude posts from subsequent queries. Environments are defined directly on the shortcode. For example:
209209

210210
```
211211
[loop query="my query" environment="main-posts"]
212212
template
213213
[/loop]
214214
```
215215

216-
This query parses `my query` (whatever you prefer here), and adds all of the post IDs it finds to an environment called `main-posts`. In the same page in another loop, you can recall this environment and exclude all posts already called up in that environment so that the posts you used before aren't duplicated elsewhere. To do so, you would use:
216+
This query parses `my query` (whatever you prefer here), and adds all of the post IDs it finds to an environment (a variable) called `main-posts`. In the same page in another loop, you can recall this environment and exclude all posts already called up in that environment, so that the posts you used before aren't duplicated elsewhere. To do so, you would use:
217217

218218
```
219219
[loop query="similar or same query to the above" environment="main-posts" recall_environment=1 recall_environment_type="post__not_in"]
@@ -228,26 +228,26 @@ In the backend, this means that each ID is added to a PHP associative array:
228228
environments['environment-name'] = array(post, ids, are, here, as_integers);
229229
```
230230

231-
Environments are created linearly (e.g., the first shortcode in the post code has first dibs on posts). You can also build environments without necessarily using them, as all posts are stored on a default environment called `loop_shortcode`. When you want to recall an environment, the plugin simply appends the following string to your query:
231+
Environments are created first-come-first-serve (e.g., the first shortcode in the post code has first dibs on posts). You can also build environments without necessarily using them, as all posts are stored on a default environment called `loop_shortcode`. When you want to recall an environment, the plugin simply appends the following string to your query:
232232

233233
```php
234234
$query .= "&{recall_environment_type}[]={environment_id}"
235235
```
236236

237-
It does this for each post in the environment. So, for example, if you want to exclude all the posts, you would use `recall_environment_type="post__not_in"` in your shortcode. Then, this query simply appends a bunch of posts for the WP_Query object to explicitly exclude from the current query.
237+
It does this for each post in the environment. So, for example, if you want to exclude all the posts, you would use `recall_environment_type="post__not_in"` in your shortcode. Then, this query simply appends a bunch of posts for the WP_Query object to *explicitly exclude from the current query*.
238238

239239
## Queries
240240

241-
For the basics of WordPress queries using the WP Query object, see [the WordPress manual on WP_Query](https://codex.wordpress.org/Class_Reference/WP_Query). The object basically takes both arrays and query strings as a valid query on the database. A query string is basically a URI resource string.
241+
For the basics of WordPress queries using the WP Query object, see [the WordPress manual on WP_Query](https://codex.wordpress.org/Class_Reference/WP_Query). The WP Query object takes both arrays and query strings as a valid query on the database. With this plugin, you will be working with query strings. A query string is a URI resource string that can be parsed into a set of variables and arrays in PHP.
242242

243-
Thus, `posts_per_page=10&cat=4,25,20,-410` is the PHP equivalent of:
243+
Thus, `posts_per_page=10&cat=4,25,20,-410` is the PHP equivalent of something like:
244244

245-
```php
246-
$posts_per_page = 10;
247-
$cat = '4,25,20,-410';
245+
```
246+
posts_per_page = 10
247+
cat = 4,25,20,-410
248248
```
249249

250-
Similarly, you can use arrays for more advanced queries. To get around the fact that wordpress doesn't play nice when you use brackets ([ and ]) inside shortcodes, even if in quotations (I know, right?), you can use curly-brackets ({ and }) instead. For example:
250+
Similarly, you can use arrays for more advanced queries. To get around the fact that wordpress doesn't play nice when you use brackets (`[` and `]`) inside shortcodes, even if in quotations (I know, right?), you can use curly-brackets (`{` and `}`) instead. For example:
251251

252252
```
253253
posts_per_page=5&post_type=event&order=ASC&orderby=meta_value_num&meta_key=date&meta_query{0}{key}=date&meta_query{0}{value}={{lastweek}}&meta_query{0}{compare}={{>=}}&meta_query{0}{type}=numeric
@@ -273,21 +273,21 @@ This is the equivalent of passing the following arguments into the WP_Query obje
273273
);
274274
```
275275

276-
In simple terms, this query grabs five posts of the type "event" with the custom key named "date" (which in the backend, WordPress calls the meta key named "date") of between last week and forever into the future.
276+
This query grabs five posts of the type "event" with the custom key named "date" (which in the backend, WordPress calls the meta key named "date") of between last week and forever into the future.
277277

278-
In real terms, this query loads five upcoming events, but keeps events for up to a week after they happen.
278+
In the above example, this query loads five upcoming events, but keeps events for up to a week after they happen.
279279

280-
Getting your query right might take a lot of trial and error. Just play with it.
280+
Getting your query right might take some trial and error.
281281

282-
### Query Helpers
282+
### Query String Helpers
283283

284284
In the example above, you may have noticed that we used {{lastweek}} and {{>=}} in our query. We have to do things like this for a few reasons:
285285

286286
1. WordPress doesn't like you using brackets in your shortcodes at all. Even in quotations.
287287
2. We need to strip out things that might mess up parsing your query string, like the `>=` symbol.
288288
3. It's really useful to have a few date helpers to query things based on dates!
289289

290-
So this plugin provides a few helpers you can use in your query strings.
290+
So this plugin provides a few helpers you can use in your query strings. The following are in the order that the yare parsed by Loop Shortcode:
291291

292292
```html
293293
{{now}} // Time helpers. Returns straight up UNIX time stamps
@@ -301,11 +301,14 @@ So this plugin provides a few helpers you can use in your query strings.
301301
{{environments}} // The custom environments string built by the plugin. This is not required for environments to work.
302302

303303
{{any odd characters}} // Any characters in double curly braces will be encoded using PHPs urlencode function
304+
// This includes things like equal signs that you don't want as part of the actual query string,
305+
// special characters, and anything else that you're afraid might not play nice with the way
306+
// PHP parses query strings
304307

305308
{0} // And finally, in the last step, all single curly braces are converted into brackets ([ and ])
306309
```
307310

308-
This allows this:
311+
These helpers allow complex queries, such as:
309312

310313
```
311314
posts_per_page=5&post_type=event&order=ASC&orderby=meta_value_num&meta_key=date&meta_query{0}{key}=date&meta_query{0}{value}={{lastweek}}&meta_query{0}{compare}={{>=}}&meta_query{0}{type}=numeric
@@ -317,9 +320,26 @@ To be passed into a query object as:
317320
posts_per_page=5&post_type=event&order=ASC&orderby=meta_value_num&meta_key=date&meta_query[0][key]=date&meta_query[0][value]=1456442898&meta_query[0][compare]=%3E%3D&meta_query[0][type]=numeric
318321
```
319322

320-
## Templates
323+
Which PHP parses into something like:
324+
325+
```
326+
posts_per_page = 5
327+
post_type = event
328+
order = ASC
329+
orderby = meta_value_num
330+
meta_key = date
331+
meta_query = [
332+
[ key => date
333+
value => 1456442898
334+
compare => >=
335+
type => numeric
336+
]
337+
]
338+
```
339+
340+
## Templates and Styling
321341

322-
You can put anything inside the shortcode as a template. But without helpers, that means nothing! So this plugin provides you with a host of assorted helpers to help you build posts from the loop output.
342+
You can put anything inside the shortcode tag as a template. This plugin provides you with a host of assorted variables and helpers to help you build posts from the loop output.
323343

324344
The default template is:
325345

wp-twig-loop-shortcode.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@
2222
require_once("menu/LoopShortcodeMenu.php");
2323

2424
/**
25-
* Trying not to polute the global space here.
25+
* TODO: Refactor so as to pollute the global namespace less
26+
*
27+
* Thoughts on doing this: inject an LSC registry into our shortcode constructor,
28+
* and the shortcode classes only call the dependencies and load Twig into memory
29+
* if those shortcodes are called. This way we can maintain our sharing of the
30+
* Twig environment and other things without having so much of this plugin
31+
* exposed to the global namespace.
2632
*/
2733

2834
$LoopShortcodeTemplates = new LoopShortcodeTemplates();

0 commit comments

Comments
 (0)