OCMLABS/MODULE-WORDPRESS · SIDEBAR BLOCKS

Sidebar Blocks

  • Magento
  • Adobe Commerce
  • Hyvä

The module includes six blocks for the blog sidebar. They are already placed on the blog pages, and you can move, remove or add them with the blog layout handles. Whether the sidebar is on the left or right, or hidden, is set by Page Layout.

Default Sidebar

PageBlocks, top to bottom
Blog homeSearch, WordPress menu, Categories, Recent Posts, Tags, Archive
Single postSearch, WordPress menu, Categories, Recent Posts
CategorySearch, WordPress menu, Categories
TagSearch, WordPress menu, Tags
Search resultsSearch, WordPress menu
AuthorNo sidebar

The WordPress menu only shows when a Sidebar Menu is set.

Available Blocks

Categories Block

Displays a list of all WordPress categories with post counts.

Block class: OCMLabs\WordPressIntegration\Block\Sidebar\Categories Template: OCMLabs_WordPressIntegration::sidebar/categories.phtml

Tags Block

Displays a tag cloud of all WordPress tags.

Block class: OCMLabs\WordPressIntegration\Block\Sidebar\Tags Template: OCMLabs_WordPressIntegration::sidebar/tags.phtml

Archive Block

Displays a monthly archive list.

Block class: OCMLabs\WordPressIntegration\Block\Sidebar\Archive Template: OCMLabs_WordPressIntegration::sidebar/archive.phtml

Search Block

A search form targeting the blog search endpoint.

Block class: OCMLabs\WordPressIntegration\Block\Sidebar\Search Template: OCMLabs_WordPressIntegration::sidebar/search.phtml

WordPress Menu Block

The menu chosen in Menus > Sidebar Menu, as a vertical list with nested items indented. Placed after the search block (after="wp.sidebar.search") by the shared ocmlabs_sidebar_menu layout handle. Added in 2.1.0.

Block class: OCMLabs\WordPressIntegration\Block\Menu\WordPress Template: OCMLabs_WordPressIntegration::sidebar/menu.phtml Block name: wp.sidebar.menu

To remove it from one page type, add <referenceBlock name="wp.sidebar.menu" remove="true"/> to that page’s layout handle in your theme.

Recent Posts Block

A compact recent posts list for the sidebar.

Block class: OCMLabs\WordPressIntegration\Block\Sidebar\RecentPosts Template: OCMLabs_WordPressIntegration::sidebar/recent-posts.phtml

Arguments:

ArgumentDefaultDescription
post_count5Number of posts

Adding Sidebar Blocks via Layout XML

To add sidebar blocks to all blog pages, create a layout file in your theme:

app/design/frontend/Your/theme/OCMLabs_WordPressIntegration/layout/ocmlabs_blog_index.xml

XML LAYOUT
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="sidebar.main">
            <block class="OCMLabs\WordPressIntegration\Block\Sidebar\Categories"
                   name="blog.sidebar.categories"
                   template="OCMLabs_WordPressIntegration::sidebar/categories.phtml"/>
            <block class="OCMLabs\WordPressIntegration\Block\Sidebar\RecentPosts"
                   name="blog.sidebar.recent"
                   template="OCMLabs_WordPressIntegration::sidebar/recent-posts.phtml"/>
        </referenceContainer>
    </body>
</page>

To add blocks to all blog pages at once, use the default layout handle (sidebar blocks will appear on all pages) or apply the blocks to each blog layout handle individually.

See also

Related pages

In this module