You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+42-22Lines changed: 42 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,13 +4,13 @@
4
4
5
5
Updated code comments and separated the backend interface into its own folder from the main LSC files.
6
6
7
-
####June 3, 2016
7
+
### June 3, 2016
8
8
9
9
Added much in the way of documentation and improved the backend display a bit.
10
10
11
11
### TODO
12
12
* 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.
14
14
15
15
# Loop Shortcodes
16
16
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
35
35
36
36
These commands navigate the SSH shell to the plugin directory and initiate the submodules. Then, git will download Twig from the Twig repo.
37
37
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.
39
39
40
40
## Updates
41
41
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:
43
43
44
44
```
45
45
git pull
@@ -205,15 +205,15 @@ Optional arguments:
205
205
206
206
### Environments
207
207
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:
209
209
210
210
```
211
211
[loop query="my query" environment="main-posts"]
212
212
template
213
213
[/loop]
214
214
```
215
215
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:
217
217
218
218
```
219
219
[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:
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:
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*.
238
238
239
239
## Queries
240
240
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.
242
242
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:
244
244
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
248
248
```
249
249
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:
@@ -273,21 +273,21 @@ This is the equivalent of passing the following arguments into the WP_Query obje
273
273
);
274
274
```
275
275
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.
277
277
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.
279
279
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.
281
281
282
-
### Query Helpers
282
+
### Query String Helpers
283
283
284
284
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:
285
285
286
286
1. WordPress doesn't like you using brackets in your shortcodes at all. Even in quotations.
287
287
2. We need to strip out things that might mess up parsing your query string, like the `>=` symbol.
288
288
3. It's really useful to have a few date helpers to query things based on dates!
289
289
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:
291
291
292
292
```html
293
293
{{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.
301
301
{{environments}} // The custom environments string built by the plugin. This is not required for environments to work.
302
302
303
303
{{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
304
307
305
308
{0} // And finally, in the last step, all single curly braces are converted into brackets ([ and ])
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.
0 commit comments