Templates and themes
Every page of Poly Community is a block template, with the community navigation at one side, the main column in the middle and widgets at the other side. With a block theme, a site owner changes each one in Appearance → Editor, as Themes and layouts shows. What a page holds before anyone edits it, how wide it is drawn and what goes beside it is set by Poly Community, and a plugin changes each of those with a filter. The four on this page are stable.
The examples on this page are run by the plugin tests in a must-use plugin, as printed here (tests/specs/templates-guide.spec.ts), on the members directory. With them in place the directory is still one drawing for every reader, as wp poly-community page-data check members says, which is what every change to a page must leave it (Pages drawn from data). The blocks a filter here adds follow the same rule: what every reader sees in their markup, what one reader sees as a part or a fact.
How wide a page is drawn
poly_community_content_width is given the width of a page and its view, and answers one of these:
| Width | What |
|---|---|
feed | The width of a feed, with widgets beside it. The activity, a post, notifications and search. |
list | Wider, for lists and pages with tabs, with widgets. The forum, questions, a profile and a space. |
form | A form and little else. Logging in, joining, a new space. |
grid | As wide as the layout allows, with widgets. A page that names none. |
full | The whole room, with no widgets. Messages. |
// The members directory as wide as a list.
function my_plugin_content_width( $width, $view ) {
return 'members' === $view ? 'list' : $width;
}
add_filter( 'poly_community_content_width', 'my_plugin_content_width', 10, 2 );
The main column then carries the class poly-main-list in place of poly-main-grid. A page of a component takes its width from width in its kit.json (Building a component).
The widgets beside a page
poly_community_sidebar_blocks is given the widgets beside a page, in order, and its view. Each widget is the name of a block, those of Poly Community without poly-community/, followed by its attributes as JSON after a space where it has some, such as popular-spaces {"sort":"newest"}:
// Beside the members directory: Popular spaces, then the footer of the community.
function my_plugin_sidebar_blocks( $blocks, $view ) {
return 'members' === $view ? array( 'popular-spaces', 'community-footer' ) : $blocks;
}
add_filter( 'poly_community_sidebar_blocks', 'my_plugin_sidebar_blocks', 10, 2 );
A widget of a part that is switched off (Popular spaces without spaces) is left out, and a page whose widgets all show nothing has no widgets column at all. By default the members directory has Online now, Who to follow and the footer, a profile has its details, Who to follow and the footer, and a page of a component without widgets of its own has those of its width. A component names the widgets of each of its pages with widgets in its kit.json, and an empty list for none.
The default blocks of a page
poly_community_main_markup is given the block markup of the main column of a page of Poly Community and its view, before anyone has edited it in the Site Editor, and answers the markup to use:
// A line above the members directory, in its default blocks.
function my_plugin_main_markup( $markup, $view ) {
if ( 'members' !== $view ) {
return $markup;
}
return '<!-- wp:paragraph {"className":"my-plugin-members-note"} --><p class="my-plugin-members-note">Everyone here lives within a walk of the river.</p><!-- /wp:paragraph -->' . "\n" . $markup;
}
add_filter( 'poly_community_main_markup', 'my_plugin_main_markup', 10, 2 );
It changes the default only. A template the owner saved in the Site Editor is drawn as they saved it, and their change wins. To change the markup inside a block instead, see Changing a component. A page of a component takes its default blocks from its own template, templates/{view}.html.
What is drawn around a page
poly_community_page_kind is given what is drawn around the main column of a page, and the route of the page (its view, section and status), and answers one of these:
| Kind | What |
|---|---|
app | The navigation, the main column and the widgets. Every page by default. |
account | The form alone, for logging in and joining. |
account-nav | The form with the navigation and no widgets, where the site chose to show the navigation on those pages. |
gate | Its login alone, for a visitor of a community open to members only. |
not-found | The navigation and the main column, no widgets. |
bleed | The whole column, no widgets. Messages. |
Any other answer is taken as app.
See also Building a component, Changing a component and Themes and layouts.