Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-10-09 18:28:10

Registered: 2019-12-12
Posts: 162

A tab for static pages?

Good afternoon everyone.

I would like to raise here some situations that in my opinion are interesting to think about, and also to know how you deal with such situations.

First, static pages (at least I call them that), those pages that usually have content like “About”, “Contact”, “Privacy Policy” and etc. I currently believe that there is no correct way to do this in Textpattern. You have several options, and in my opinion none of them are appropriate:

  1. We can create a section, assign a page and create articles within this section with the names “About”, “Contact” and etc. However, that content would be mixed with your publications. That’s not cool.
  2. We can create a form for this, give the name we want and ok. However, this results in some problems such as: if you want more than one page but with different content, you will have several forms that are the same, so if you want to change something, you have to change it all. There are ways to around this, but it is still not ideal. The second problem, of course, is having to write directly within HTML. The third is a link that is not very friendly: ?f=about, ?f=contact.

I would like to know how you handle this type of situation, and if there is any better way that I cannot think.

My suggestion: Create a tab of static pages where you can manage them. This is already done in most other CMS I used, including Wordpress. This also opens up a range of possibilities, I remember someone talking about an ecommerce plugin here, creating your login, registration, ordering pages and etc. through these static pages would be ideal, as WooCommerce does in wp.

I would like to raise a few more situations but I will leave for another topic, this is already getting big.


#2 2020-10-09 20:31:30

Registered: 2010-11-11
Posts: 5,067
Website GitHub

Re: A tab for static pages?

I think your option 1 is almost ok save for ‘that content would be mixed with your publications’? Indeed, even if sections can be easily excluded from search, frontpage and feeds, excluding them from custom constructions requires more attention, e.g.

<txp:article_custom section="static" exclude="section" />

Probably, we could introduce an option to automatically exclude some sections from all lists, like for pageless sections, but still keeping them accessible, unlike the pageless sections?


#3 2020-10-09 21:02:35

Registered: 2019-12-12
Posts: 162

Re: A tab for static pages?

About mixing the static pages and articles, I mean in the admin panel. In my opinion, a panel to manage static pages separately from articles would be interesting. Think of the ecommerce example, you would have to have some pages like “Orders”, “Cart” and “My Account” mixed with the products. Is not strange?


#4 2020-10-09 21:18:09

From: Leeds, UK
Registered: 2006-01-29
Posts: 11,285
Website GitHub

Re: A tab for static pages?

For this, I’m not sure why people want to exclude some of the ‘static’ content and not let site admins alter it. It’s content. It belongs in the content area. If your company phone number changes, or you move offices, why would you want to hire a designer to change your address that’s squirrelled away in a form? You can write it in your contact page or – better – use an adi_variable or at worst a shortcode that can then be called throughout your site and can thus be changed once to effect things site wide.

For ‘About, what if the scope of the company changes? Maybe you expand your horizons. Again, if that text is in the Content area, the client can change it without being bogged down with hunting through forms to find it. It’s Content, assigned to a Section.

I understand for some stuff like orders and cart, yeah, it’s not ideal to have those mixed up with content. There’s not really a solution for that right now. Certainly something we can think about.

For now, if you want to hide stuff, it’s easy with a plugin. Here’s a super simple plugin to hide the About section articles:

if (txpinterface == 'admin') {
    register_callback('abc_hide_section', 'admin_criteria', 'list_list');
    register_callback('abc_hide_section', 'txp.article', 'neighbour.criteria');

function abc_hide_section($evt, $stp) {
    return " AND Section != 'about'";

You might like to extend that a bit so Publishers are excluded from the filter. Or that only certain user levels are subjected to the filter. Season to taste.

Alternatively, a bit more involved, how about this:

register_callback('smd_filter_articles', 'admin_criteria', 'list_list');
register_callback('smd_filter_articles_ui', 'list');

function smd_filter_articles($evt, $stp)
    $smd_filter_articles = smd_filter_articles_check();
    $isPending = !empty($smd_filter_articles['pending']);

    return ($isPending) ? ' AND Status = 3' : '';

function smd_filter_articles_ui($evt, $stp)
    $smd_filter_articles = smd_filter_articles_check();

    $checkPending = !empty($smd_filter_articles['pending']) ? $smd_filter_articles['pending'] : '';

    echo script_js(<<<EOJS
jQuery(function() {
    jQuery('.txp-control-panel .txp-button').after('Filter: <input type="checkbox" id="smd_filter_articles_pending_cb" name="smd_filter_articles_pending_cb" class="smd_filter_articles_pending_cb"{$checkPending} /><label for="smd_filter_articles_pending_cb">Pending articles</label>');
    jQuery('.smd_filter_articles_pending_cb').on('change', function() {
        insertParam('smd_filter_articles_pending', jQuery(this).prop('checked'));

function insertParam(key, value)
    key = encodeURI(key);
    value = encodeURI(value);

    var kvp = document.location.search.substr(1).split('&');
    var i = kvp.length;
    var x;

    while (i--) {
        x = kvp[i].split('=');

        if (x[0]==key) {
            x[1] = value;
            kvp[i] = x.join('=');

    if (i < 0) {
        kvp[kvp.length] = [key,value].join('=');

    // Reload the page.
    document.location.search = kvp.join('&'); 

function smd_filter_articles_check()
    static $filters = null;

    if ($filters === null) {
        $pendingChecked = gps('smd_filter_articles_pending');

        if (empty($pendingChecked)) {
            $pendingChecked = get_pref('smd_filter_articles_pending_cb');

        set_pref('smd_filter_articles_pending_cb', $pendingChecked, 'smd_filter_articles', PREF_PLUGIN, 'text_input', 0, PREF_PRIVATE);
        $pendingAttr = ($pendingChecked == 'true') ? ' checked' : '';

        $filters['pending'] = $pendingAttr;

    return $filters;

That filters articles using checkboxes above them in the Articles panel. As an example, that plugin adds just one checkbox to filter out Pending articles. But you could easily change that and/or extend it to add a series of checkboxes to filter out whatever you wanted. Maybe even filter out all articles in ‘static’ sections using code from the first plugin, and then allow people to ‘opt in’ and display content from the checked sections.

The reason the plugin is so big (ha, uhh, comparatively!) is because it remembers the state of the checkbox via a per-user pref. Plus it is built so you can extend it fairly easily to check for other stuff by adding a checkbox to the _ui function and a corresponding pref setting to the _articles_check() function.

It’s quick and dirty, and could be cleaned up a whole lot more, but it’s a proof of concept rather than production plugin.

Finally, if you want to do this kind of thing in a more WordPress way, you could use smd_tabber.

Using the first plugin mentioned above, filter out the content of your ‘static’ sections for all users. Then create a tab under Content called ‘Static content’. Inside your nominated page template for that tab, you can then build a dropdown to pick one of the ‘static’ sections and a simple textarea beneath that loads in the article content when you change the dropdown.

Add a Save button and ensure that your page responds to this Save POST data, whereby it runs the content in the textarea through Textile and diverts both the textarea and post-processed content into the Body and Body_html fields of the corresponding article in the textpattern table. Job done.

Last edited by Bloke (2020-10-09 21:21:12)

The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp


Board footer

Powered by FluxBB