User Tools

Site Tools


doc:tips:widgets

Advanced techniques: Widgets

Sticky posts

A very common question is if the “what's-the-name” blog supports sticky posts. Well, FlatPress does. Well, not really. It does not. “Oh, please NoWhereMan, stop with kidding, can we do that??”

As some of you may know (and if you still don't, get to the damn FAQ! :D) custom sidebar widgets are supported through the magical blockparser plugin. This plugin, gets as its input the name of a static page and spits out an usable sidebar widget.

Usually if you want a static page called “menu” to appear on the right sidebar as a widget, you go to the widget panel, you scroll to the “right” section and add the line 'blockparser:menu', .

Theme designers should be aware that they can be sure about at least two bars, left and right, which can they access in their themes templates using the tag

{widget pos=left}
    {$subject}
    {$content}
{/widget}

However, you are not forced to use only these positions, but you can define your own sections in the widget config panel.

For instance, you can define a new section, called, say, “sticky”:

$fp_widgets = array (
    'sticky'=>array(),  
    'top' = array(
    // here are then the other usual sections

which you will be able to access through

{widget pos=sticky}

For instance, here I have created a static page called “my_sticky_page”, and then I've edited the template index.tpl (so that the new widget set appeared only on the main page)

[img=images/fp-techniques-sticky.png scale=50%]

the widget panel entry looks like follows

$fp_widgets = array (
    'sticky'=>array('blockparser:my_sticky_page'),  
    'top'=>array(
    // etc...

index.tpl has been edited, adding after the div with id=“main” the following (notice the double class specification, there are both sticky and entry):

{widgets pos=sticky}
    <div id="sticky-{counter}" class="sticky entry">
        <h3>{$subject}</h3>
        {$content}
    </div>
{/widgets}

while in res/style.css we added this, at the end:

.sticky {
    padding: 4em; 
    background-color: #e4e6fe; 
    border: solid thin lightgrey
}

This technique can be applied to the other widgets, so if you want for instance to show a list of the latest entries using the lastentries plugin (please disable it from the sidebar, this plugin is a little slow :P) just edit the widget config like this

$fp_widgets = array (
    'sticky'=>array('lastentries'),  
    'top'=>array(
    // etc...

It will look then like this :

[img=images/fp-techniques-last.png scale=50%]

Yeah, I know, that's awesome, cool and whatever :D

doc/tips/widgets.txt · Last modified: 2019/01/12 17:53 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki