.

Pivot stuff - introductionSnippetsDownload statisticsPollTo Do listFor snippet authorsA heartfelt plea

For other snippet authors:

skeleton

I don't know if this is off any use to anyone...

I created it when I noticed that many of my snippets had similar core functionality. You can download it here.

You can treat it as an example, if you are just learning snippet coding - although I certainly do not claim to be any sort of expert.

Alternatively, you can use it as a basis for any similar snippet.

It accepts parameters to indicate desired weblog,a uthor  and category, allowing for wildcards, and loops through all entries selecting only published entries which match the desired weblog, author and category (feel free to add further checks, e.g. for date, etc).

Once you have located each entry, simply add your code; an example is given of how to generate an HTML URL with the text being the title of the post and the destination being the permalink of the post. (downloaded times so far)

snippet_conditional_begin and snippet_conditional_end. Basically, Bob told me how to code these. My big problem is where to show the (larger) output of some of my snippets. I could show the output on a new page, but I decided that I would like it in the 'frame' (centre column) of my blog's frontpage. Then I thought that if I had the output of a snippet there, I would rather not have the standard blog below it. I posted to the forum and Bob suggested this.

In my frontpage.html, I have:

  1. [[recent_months]]
  2. [[conditional_begin:no_subweblog]]
  3. [[subweblog:standard]]
  4. [[conditional_end:no_subweblog]]

as explained here:

  1. The snippet lists the titles of all posts in recent months, with links to each individual entry (permalink), in the frontage template. In the unlikely even that I have posted nothing in the last few months, it outputs no text, so I may as well show the standard blog. Thus, the snippet sets a global variable $conditional_output['no_subweblog'], which can be read by the "conditional" snippets.
  2. This snippet examines the variable in global array $conditional_output[] indexed by its parameter. If set to true, it will begin to suppress all output of all other PHP until step 4 is reached.
  3. This is the standard weblog, the snippet who's output I want to suppress (note that the snippet still runs, it just doesn't make any output). Note that we could have any number of snippets in stage 3 - but we should not, because they will all be suppressed if the snippet in step1 decides so. Best to repeat the grouping of 4 snippets, for each step 3.
  4. This snippet examines the variable in global array $conditional_output[] indexed by its parameter. If set to true, it will end the suppression of output of all other PHP which was begun in step 2. It will also reset the global variable. For obvious reasons, you are recommended not to forget this step.

You may also want to use get_posts_for_month, get_posts_for_category or get_posts as a building block for a new snippet, post-processing the output or presenting it in a different format.




Pivot stuff - introductionSnippetsDownload statisticsPollTo Do listFor snippet authorsA heartfelt plea

Valid HTML 4.0! Last modified: 17 April 2008    Page loaded in 0.004049 seconds.        This page has been visited 10 times since the great site reorganization of June 2005.