FlatPress Wiki

Everything you need to know :)

User Tools

Site Tools


doc:tips:widgets

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

doc:tips:widgets [2019/01/12 17:53] (current)
Line 1: Line 1:
 +====== 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 [[doc:​faq|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
 +
 +<code smarty>
 +{widget pos=left}
 +    {$subject}
 +    {$content}
 +{/widget}
 +</​code>​
 +
 +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":​
 +
 +<code php>
 +$fp_widgets = array (
 +    '​sticky'​=>​array(),  ​
 +    '​top'​ = array(
 +    // here are then the other usual sections
 +</​code>​
 +
 +
 +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
 +
 +<code php>
 +$fp_widgets = array (
 +    '​sticky'​=>​array('​blockparser:​my_sticky_page'​),  ​
 +    '​top'​=>​array(
 +    // etc...
 +</​code>​
 +
 +**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):
 +
 +<code smarty>
 +{widgets pos=sticky}
 +    <div id="​sticky-{counter}"​ class="​sticky entry">​
 +        <​h3>​{$subject}</​h3>​
 +        {$content}
 +    </​div>​
 +{/widgets}
 +</​code>​
 +
 +while in ''​res/​style.css''​ we added this, at the end:
 +
 +<code css>
 +.sticky {
 +    padding: 4em; 
 +    background-color:​ #​e4e6fe; ​
 +    border: solid thin lightgrey
 +}
 +</​code>​
 +
 +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
 +
 +<code php>
 +$fp_widgets = array (
 +    '​sticky'​=>​array('​lastentries'​),  ​
 +    '​top'​=>​array(
 +    // etc...
 +</​code>​
 +
 +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 (external edit)