Whale-kit

By | January 13, 2022

The plugin adds 3 shortcodes:
[wk_terms /] for displaying categories, tags, any other taxonomies, works through the WP_Term_Query class.
[wk_posts /] for displaying posts, pages and any other post types, WK_posts receives data through the WP_Query class
[wk_pages /] output of hierarchical structures of pages, posts and other types of posts, the data is obtained using the get_pages() function

Shortcodes pass all call parameters to the corresponding functions and receive the initial data set from them. Explore the basic parameters of calling source functions by following the links.
See many examples

When generating the final html code, the classes use micro-templates for example:
hint='$count entries in category «$name» id:$id'
At the right time, this template is processed – instead of $count, $name and $id, the number of entries in the category, the name of the category, and the id of the category will be substituted, respectively. As a result, we get hitn – tooltip. In turn, $hint can be used in another template el_tmpl – a list item.
This simple mechanism gives us a very powerful tool – you can output the list in the form of UL-LI or a variant of DIV-SPAN, or, as demonstrated in the example below, with the TABLE-TR table, in general, the choice is yours.
Working example of printing categories as a table:
[wk_terms hierarchical=0 taxonomy=category number = 5
lv_tmpl='<table>$elements\\n</table>' 
el_tmpl='<tr title="$hint"><td>id:$id</td><td><a href="$href">$name</a></td><td>count:$count</td></tr>' 
/]

id:9 A Caucus-Race count:3
id:12 A Mad Tea-Party count:2
id:6 ALICE’S count:5
id:7 Down the Rabbit-Hole count:0
id:5 Lewis Carroll count:1

\n – line feed character

[wk_terms/]

The wk_terms shortcode receives data through the WP_Term_Query class
for the main introductory information, see the link. In addition, the class implements additional functionality.
wk_terms works with categories, tags, and any other taxonomies. Supports tree (hierarchical parent-child structures), and its own handler, such structures, provides better performance than the standard Walker.

wk_terms – additional features and introductory

  • collapse – hide inactive tree branches – allows you to significantly shorten the list
  • hierarchical – display hierarchy (true)
  • current – you can specify the current taxonomy
  • depth – maximum level
  • show_count – display the number of posts in a category (taxonomy)
  • size_of_count – calculate the font size depending on. from the number of entries in a category (taxonomy)
  • smallest, largest – setting font sizes from small to large, each element in the link will be set to the font <a style=’font-size:8pt’> depending on the number of entries this taxonomy contains
  • unit – indicates the units of the font (pt)
  • lv_tag -html tag for level (ul)
  • el_tag – html tag for the list item (li)
  • count_tag – html tag for displaying the number of records in the taxonomy p.t. <sup> 67 </sup>
  • use_desc_for_hint – use category description for title tooltip
  • css_prefix – used when generating css classes of an element

wk_terms – micro-templates

  • hint_single – title text for a tag with one record: 1 record
  • hint_none – text if there are no entries
  • hint_fiw – text for multiple entries: 2 – 4
  • hint – text for a label with many records: 8 records, 1200 records, it is also used by default if hint_fiw and hint_single are not assigned

example:

  • hint_none = '’there are no entries in«$name» id:$id'
  • hint_single = '1 entry in category «$name» id:$id'
  • hint_few='$count entries in the «$name» id:$id'
  • hint='$count entries in the «$name» id:$id'

available variables for substitution in the hint group: ($count, $name, $id)

  • lv_tmpl – micro level template ($elements, $lv_tag, $taxonomy, $css_prefix, $el_count, $ind, $class, $depth )
  • t_count – micro template of the number of records  ( $count_tag, $id, $count )
  • el_tmpl – micro element template ($ind, $num, $href, $el_tag, $count_tag, $css_prefix, $id, $unit, $name, $count, $font_size, $class, $hint, $style, $t_count, $childs )

– variables available for substitution in this template are indicated in brackets
пример:
lv_tmpl='\n$ind<$lv_tag class="$class">\n$elements\n$ind</$lv_tag>'
*use only double quotes inside the template
* \n – line break for nicely styling html code

wk_terms – description of variables

  • $id – taxonomy id term_id
  • $num -the ordinal number of the element
  • $count – the number of records in the taxonomy
  • $name – taxonomy name
  • $href – url address
  • $ind – indentation for source code formatting is calculated based on element level
  • $font_size -if the size_of_count option is enabled – then the font size will be calculated here (font-size: 11pt;)
  • $class – a set of css classes calculated for this element and level
  • $hint – tooltip
  • $t_count – number of elements at this level
  • $depth – current nesting level
  • $taxonomy – taxonomy type (category, post_tag …)
  • $childs – child elements
  • $elements – ready-made element code for the level

wk_terms – examples

A working example is a string of introductory widgets:


[wk_terms taxonomy = category show_count = 1 hierarchical = 1 size_of_count = 1 smallest = 9 largest = 20
hint = '$name - $count entries'
hint_single = 'one $name'
hint_few = '$count $name entries'
/]

[wk_posts/] and [wk_pges/]

The [wk_posts/] shortcode is for displaying posts, static pages, any post type – whatever WP_Query can get. Just like WR_terms, the WK_posts class, when processing tree structures (pages), uses its own algorithm for constructing a multidimensional structure from a two-dimensional array.

[wk_pages/] differs from wk_posts in the data source – the data is obtained using the get_pages() function. Despite its name, this function can return any type of both pages and posts. You only need to specify the post_type = ‘post’ parameter. By default post_type = ‘page’.
get_pages() doesn’t seem to accept complex requests :). Use this code to get a set of static pages (page).
All props and micro-templates are the same as for the wk_posts shortcode.

wk_posts – Additional parameters:

  • collapse – hide inactive tree branches, allows you to significantly shorten the list (for static pages) (false)
  • hierarchical – display hierarchy (false)
  • show_count – show the number of comments (false)
  • size_of_count – calculate the font size in factory. from the number of comments
  • smallest,largest – setting the font size from small to large, each element in the link will be set to the font <a href="" style='font-size:8pt'> depending on the number of comments this entry/page contains
  • unit – indicates the units of measure of the font (pt)
  • css_prefix – used when generating css classes of an element
  • truncate_title – truncate title to size
  • truncate_content – truncate body text
  • date_format – date format for date() function
  • show_author – calculate the author, the $author variable will become available in templates

wk_posts, wk_pages – MICRO PATTERNS

  • hint_none – the text of the title of the page that has no comments
  • hint_single – title text of the page with 1 comment
  • hint_fiw – title text of the page with 2-4 comments
  • hint – the text of the title of the page with 5 or more comments, if the first 2 are not specified, hint is used

пример:

  • hint_none = 'no comments «$name» id:$id'
  • hint_single = '1 comment «$name» id:$id'
  • hint_few='$count comments «$name» id:$id'
  • hint='$count comments «$name» id:$id'

available variables for substitution in the hint group: ($count, $name, $id)

  • lv_tmpl – micro level template ($elements, $lv_tag, $taxonomy, $css_prefix, $el_count, $ind, $class, $depth)  
    '\n$ind<$lv_tag class="$class">\n$elements\n$ind</$lv_tag>'
  • с_tmpl – micro template of the number of records  ( $count_tag, $id, $count )
    '<$count_tag>$count</$count_tag>'
  • a_tmpl – author display template (author, a_url)
    'автор: <a href="$a_url">$author</a>' – this template is not set by default
  • cnt_tmpl – template for formatting content (main text) – not set ($content, $excerpt, $title, $post_type, $name, $ind, $id, $date)
  • el_tmpl – micro item template ( $id, $num, $ind, $name, $unit, $href, $date, $count, $title, $el_tag, $excerpt, $content, $post_type, $font_size, $count_tag, $css_prefix, $childs, $с_tmpl, $style, $cnt_tmpl, $hint, $a_tmpl, $class )
    '<$el_tag title="$hint"><a href="$href" style="$style"><b>$title</b></a>$с_tmpl$childs</$el_tag>'

*- available variables for substitution in the template are indicated in brackets

wk_posts, wk_pages – Variables to substitute

  • $id – post \ page ID
  • $num – the ordinal number of the element in the list
  • $ind – indentation for code formatting, calculated depending on the level
  • $name – post_name – url post title
  • $unit – font units
  • $href -link to post
  • $date – date (already formatted)
  • $count – number of comment
  • $title – title
  • $el_tag – tag for element decoration
  • $excerpt – post_excerpt – post announcement
  • $content – the main body of the post
  • $post_type – post type
  • $font_size – font size – calculated depending on the number of comments
  • $count_tag – tag for registration of the number of comments (sup)
  • $css_prefix – prefix – for generating css classes, if not set then post_type will be taken
  • $class – the list of classes for the current element
  • $style – the style is calculated depending on the number of comments
  • $a_tmpl – ready-made template with the author of the post
  • $hint – tooltip
  • $c_tmpl – ready-made template with the number of comments
  • $cnt_tmpl – ready-made template with content (main text)
  • $childs – the children of this element

wk_posts, wk_pges – Examples:

The shortcode displays posts in a simple table. Let’s print 10 posts from the WordPress category (id: 6 )

[wk_posts 
post_type = 'post' 
cat = 6
date_format = 'd-m-Y'
posts_per_page = 5
truncate_title = 50
lv_tmpl = '
<h2>Table</h2>
<table border=1 class="$class">
<tr><th>№<th>ID<th>Title<th>author<th>date<th>post_type<th>link</tr>
$elements
</table>

a_tmpl = 'author: <a href="$a_url">$author</a>'
el_tmpl = '$ind<tr><td>$num<td>$id<td>$title<td>$a_tmpl<td>$date<td>$post_type<td><a href="$href">go to</a></tr>\n' 
/]

Table

ID

Title

author

Date

post_type

link
1

93

Alice felt dreadfully puzzled.

author: YStepanov

13-01-2022

post

go to
2

91

A Mad Tea-Party

author: YStepanov

13-01-2022

post

go to
3

89

Alice glanced rather anxiously at the cook

author: YStepanov

13-01-2022

post

go to
4

87

There was certainly too much of it in the air

author: YStepanov

13-01-2022

post

go to
5

85

The door led right into a large kitchen

author: YStepanov

13-01-2022

post

go to

Complex query for WP_Query

Find posts tagged with ALICE AND NOT from category The Rabbit
ALICE tag has slug = alice, and category The Rabbit has slug = the-rabbit

[wk_posts
tax_query='array(
    "relation"=>"AND", 
     array(
       "taxonomy" => "category",
       "field" => "slug",
       "terms" => array("the-rabbit"),
       "operator" => "NOT IN"
     ),
     array(
        "taxonomy" => "post_tag",
        "field" => "slug",
        "terms" => array("alice")      
     ) 
)'
/]

Leave a Reply

Your email address will not be published.