Question:
How can I emulate pMachine PRO’s pBlocks?
Introduction
Depending upon your needs, a pBlock might be emulated with either a global variable, a sub-template (a template that is to be embedded into another template), or using weblog entries.
To emulate a static pBlock that contains fixed test (or HTML), such as a copyright footer, a global variable would suffice. You could also use a fixed-reference (hard coded) single weblog entry (see example below). For a random pBlock, the most convenient replacement would be a weblog entry (see example below). If you need to include tags (or, new to EE, php), then you could use a sub-template.
(As of this writing, an example emulating a cycle forward or cycle backward pBlock is not available.)
Single fixed-reference weblog entry
To use a single weblog entry to emulate a static pBlock, the following section could be placed in your template where it is needed:
{exp:weblog:entries weblog="default_site" entry_id="1" dynamic="off"}
{body}
{/exp:weblog:entries}
where the weblog name, entry ID number, and type of field to use (e.g., {body}) would be determined by you.
random display
To accomplish the same behavior as a random pBlock, you could use the following:
{exp:weblog:entries weblog="default_site" orderby="random" limit="1" dynamic="off"}
{body}
{/exp:weblog:entries}
where, again, the weblog name and display field(s) would be changed to suit.
Using weblog entries
For this example, we’ll use the one that shows the latest 5 entries
* Go to Templates -> sote
* Create a new, blank template, call it “recent”
* Edit it, and add this code:
<ul>
{exp:weblog:entries weblog="default_site" limit="5" dynamic="off"}
<li><a href="{comment_url_title_auto_path}">{title}</a></li>
{/exp:weblog:entries}
</ul>
The above code shows the last 5 entries, in a list, for the weblog with the shortname “weblog1”.
* Save the template.
* Now, go edit your index template, and wherever you want these recent entries to appear, add:
{embed=site/recent}
You can add this on whatever pages you want it to appear (such as the comments page).
