|
| 1 | +# Using ActivityPub Blocks in Classic Themes |
| 2 | + |
| 3 | +If you're using a classic (non-block) theme, you can still take advantage of the ActivityPub plugin's blocks by using Block Template Parts. This allows you to add features like reactions (likes and boosts) and follow buttons to your classic theme without switching to a block theme. |
| 4 | + |
| 5 | +## What are Block Template Parts? |
| 6 | + |
| 7 | +Block Template Parts allow you to use the block editor to create reusable template sections that can be embedded in classic themes. This gives you the flexibility of blocks while maintaining your classic theme. |
| 8 | + |
| 9 | +For a comprehensive guide on Block Template Parts, see the [WordPress Learn tutorial on Using Block Template Parts in Classic Themes](https://learn.wordpress.org/tutorial/using-block-template-parts-in-classic-themes/). |
| 10 | + |
| 11 | +## Enabling Block Template Parts in Your Theme |
| 12 | + |
| 13 | +Before you can create and use block template parts, your classic theme needs to declare support for this feature. |
| 14 | + |
| 15 | +Add the following code to your theme's `functions.php` file: |
| 16 | + |
| 17 | +```php |
| 18 | +add_action( 'after_setup_theme', 'my_theme_setup' ); |
| 19 | + |
| 20 | +function my_theme_setup() { |
| 21 | + add_theme_support( 'block-template-parts' ); |
| 22 | +} |
| 23 | +``` |
| 24 | + |
| 25 | +After adding this code, you'll see a **Template Parts** option in your WordPress admin under **Appearance**. This is where you'll create the template parts that contain your ActivityPub blocks. |
| 26 | + |
| 27 | +## How to Use Block Template Parts |
| 28 | + |
| 29 | +To use a block template part in your classic theme, use the `block_template_part()` function: |
| 30 | + |
| 31 | +```php |
| 32 | +<?php block_template_part( 'template-part-name' ); ?> |
| 33 | +``` |
| 34 | + |
| 35 | +## Example 1: Adding Reactions to Single Posts |
| 36 | + |
| 37 | +The ActivityPub Reactions block displays likes and boosts (shares) that your posts have received from the fediverse. Here's how to add it to your single post pages. |
| 38 | + |
| 39 | +### Step 1: Create a Block Template Part |
| 40 | + |
| 41 | +Create a directory called `parts` in your theme directory if it doesn't already exist. Then create a new file called `post-footer.html` in the `parts` directory: |
| 42 | + |
| 43 | +```html |
| 44 | +<!-- wp:activitypub/reactions /--> |
| 45 | +``` |
| 46 | + |
| 47 | +Once you've created the file, WordPress will automatically detect it. You can then edit it in the Site Editor under **Appearance > Editor > Template Parts** to customize the block settings or add additional content. |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | +### Step 2: Add to Your Theme |
| 52 | + |
| 53 | +Open your theme's `single.php` file (or whichever template file displays your single posts) and add the following code where you want the post footer to appear (typically after the post content): |
| 54 | + |
| 55 | +```php |
| 56 | +<?php |
| 57 | +if ( is_singular( 'post' ) && function_exists( 'block_template_part' ) ) { |
| 58 | + block_template_part( 'post-footer' ); |
| 59 | +} |
| 60 | +?> |
| 61 | +``` |
| 62 | + |
| 63 | +**Suggested placement locations:** |
| 64 | +- After `the_content()` in your post loop |
| 65 | +- Before or after the comments section |
| 66 | +- In a dedicated post meta section |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | +### Example: Full Implementation in single.php |
| 71 | + |
| 72 | +```php |
| 73 | +<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> |
| 74 | + <header class="entry-header"> |
| 75 | + <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?> |
| 76 | + </header> |
| 77 | + |
| 78 | + <div class="entry-content"> |
| 79 | + <?php the_content(); ?> |
| 80 | + </div> |
| 81 | + |
| 82 | + <?php |
| 83 | + if ( function_exists( 'block_template_part' ) ) { |
| 84 | + block_template_part( 'post-footer' ); |
| 85 | + } |
| 86 | + ?> |
| 87 | +</article> |
| 88 | +``` |
| 89 | + |
| 90 | +## Example 2: Adding Follow Button for Authors |
| 91 | + |
| 92 | +The ActivityPub Follow block allows visitors to follow authors directly from your site. This is useful on author archive pages or as author information within posts. |
| 93 | + |
| 94 | +### Option A: On Author Archive Pages |
| 95 | + |
| 96 | +#### Step 1: Create a Block Template Part |
| 97 | + |
| 98 | +Create a file called `author-header.html` in your theme's `parts` directory: |
| 99 | + |
| 100 | +```html |
| 101 | +<!-- wp:activitypub/follow /--> |
| 102 | +``` |
| 103 | + |
| 104 | +After creating the file, you can customize it in **Appearance > Editor > Template Parts** if needed. |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | +#### Step 2: Add to author.php |
| 109 | + |
| 110 | +Open your theme's `author.php` file and add the author header in the author bio section: |
| 111 | + |
| 112 | +```php |
| 113 | +<div class="author-info"> |
| 114 | + <?php |
| 115 | + if ( function_exists( 'block_template_part' ) ) { |
| 116 | + block_template_part( 'author-header' ); |
| 117 | + } |
| 118 | + ?> |
| 119 | +</div> |
| 120 | +``` |
| 121 | + |
| 122 | +### Option B: As Author Information in Posts |
| 123 | + |
| 124 | +You can also display the follow button as part of the author bio box that appears on individual posts. |
| 125 | + |
| 126 | +#### Step 1: Create the Template Part |
| 127 | + |
| 128 | +Create a file called `post-meta.html` in your theme's `parts` directory: |
| 129 | + |
| 130 | +```html |
| 131 | +<!-- wp:activitypub/follow /--> |
| 132 | +``` |
| 133 | + |
| 134 | +#### Step 2: Add to single.php |
| 135 | + |
| 136 | +Add the post meta box after your post content: |
| 137 | + |
| 138 | +```php |
| 139 | +<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> |
| 140 | + <div class="entry-content"> |
| 141 | + <?php the_content(); ?> |
| 142 | + </div> |
| 143 | + |
| 144 | + <?php |
| 145 | + if ( function_exists( 'block_template_part' ) ) { |
| 146 | + block_template_part( 'post-meta' ); |
| 147 | + } |
| 148 | + ?> |
| 149 | +</article> |
| 150 | + |
| 151 | +<?php comments_template(); ?> |
| 152 | + |
| 153 | +## Additional Tips |
| 154 | + |
| 155 | +### Conditional Display |
| 156 | + |
| 157 | +You can control when template parts are displayed using WordPress conditional tags: |
| 158 | + |
| 159 | +```php |
| 160 | +<?php |
| 161 | +// Only on single posts |
| 162 | +if ( is_singular( 'post' ) && function_exists( 'block_template_part' ) ) { |
| 163 | + block_template_part( 'post-footer' ); |
| 164 | +} |
| 165 | + |
| 166 | +// Only on author archives |
| 167 | +if ( is_author() && function_exists( 'block_template_part' ) ) { |
| 168 | + block_template_part( 'author-header' ); |
| 169 | +} |
| 170 | + |
| 171 | +// On both single posts and pages |
| 172 | +if ( is_singular( array( 'post', 'page' ) ) && function_exists( 'block_template_part' ) ) { |
| 173 | + block_template_part( 'post-meta' ); |
| 174 | +} |
| 175 | +?> |
| 176 | +``` |
| 177 | + |
| 178 | +## Available ActivityPub Blocks |
| 179 | + |
| 180 | +The ActivityPub plugin provides several blocks you can use in your template parts: |
| 181 | + |
| 182 | +- **Reactions**: Display likes and boosts from the fediverse |
| 183 | +- **Follow**: Allow visitors to follow authors |
| 184 | +- **Followers**: Display a list of followers |
| 185 | +- **Profile**: Display author profile information for the fediverse |
| 186 | + |
| 187 | +## Troubleshooting |
| 188 | + |
| 189 | +### Template Part Not Showing |
| 190 | + |
| 191 | +If your template part isn't displaying: |
| 192 | + |
| 193 | +1. Make sure you've created and saved the template part in the Site Editor |
| 194 | +2. Verify the name matches exactly (case-sensitive) |
| 195 | +3. Check that `block_template_part()` function exists (WordPress 6.3+) |
| 196 | +4. Ensure the ActivityPub plugin is activated |
| 197 | + |
| 198 | +### Styling Issues |
| 199 | + |
| 200 | +If the blocks don't match your theme's styling: |
| 201 | + |
| 202 | +1. Add custom CSS to your theme's stylesheet |
| 203 | +2. Use the block editor's design tools to adjust spacing, colors, and typography |
| 204 | +3. Check your theme's CSS specificity - you may need to use more specific selectors |
| 205 | + |
| 206 | +## Further Resources |
| 207 | + |
| 208 | +- [WordPress Learn: Using Block Template Parts in Classic Themes](https://learn.wordpress.org/tutorial/using-block-template-parts-in-classic-themes/) |
| 209 | +- [ActivityPub Plugin Documentation](https://github.com/Automattic/wordpress-activitypub) |
| 210 | +- [WordPress Block Editor Handbook](https://developer.wordpress.org/block-editor/) |
| 211 | + |
| 212 | +## Need Help? |
| 213 | + |
| 214 | +If you need assistance implementing these blocks in your classic theme, visit the [ActivityPub plugin support forum](https://wordpress.org/support/plugin/activitypub/) on WordPress.org. |
0 commit comments