如何在WordPress父页面Sports的子页面Events中展示The Events Calendar?
Got it, let's tackle this issue with The Events Calendar on your Sports > Events subpage. The plugin's default setting only lets you specify a parent page slug, but we have a few reliable workarounds to get the calendar showing exactly where you want it:
1. Use the Built-in Shortcode (Quickest Fix)
The Events Calendar includes a simple shortcode you can drop directly into your subpage content—no coding required:
- Edit your Events subpage in WordPress.
- In the page editor, add the shortcode
[tribe_events]wherever you want the calendar to appear. - If you want to filter events to only show sports-related ones, add parameters like
[tribe_events category="sports"](replace "sports" with your actual event category slug).
This method is perfect if you need a fast, no-fuss solution that integrates seamlessly with your page's existing content.
2. Create a Custom Page Template (More Design Control)
If you want to match the calendar's layout to your subpage's theme or add custom elements around it, a custom template is the way to go:
- Copy your theme's
page.phpfile (access it via FTP or WordPress's built-in file editor). - Rename the copied file to
page-events.php(since your subpage slug is "events"). - Add this comment at the very top of the new file to let WordPress recognize it as a custom template:
<?php /** * Template Name: Sports Events Calendar */ ?> - Locate the main content area in the template (usually where
the_content()is called) and replace or add the calendar rendering function:<?php tribe_events(); ?> - Save the file and upload it back to your theme's folder (use a child theme if you haven't already—this prevents changes from being lost when your theme updates).
- Return to your Events subpage editor, under "Page Attributes" select the "Sports Events Calendar" template, then update the page.
3. Use a Filter Hook to Trick the Plugin (Advanced)
If you want the plugin to treat your subpage as its official event page (so all plugin styles, widgets, and functionality load properly), use this filter hook:
- Open your theme's
functions.phpfile (stick to a child theme to avoid breaking things during updates). - Add this code snippet:
add_filter( 'tribe_events_is_event_page', 'custom_tribe_events_subpage_check' ); function custom_tribe_events_subpage_check( $is_event_page ) { // Get the current page object $current_page = get_post(); // Verify we're on the Events subpage of Sports if ( $current_page && 'page' === $current_page->post_type ) { $parent_page = get_post( $current_page->post_parent ); if ( $parent_page && 'sports' === $parent_page->post_name && 'events' === $current_page->post_name ) { return true; } } // Return the original value if we're not on the target subpage return $is_event_page; } - Save the changes. Now the plugin will recognize your Sports > Events subpage as its official event page, loading all associated features automatically.
If you run into any snags—like the shortcode not rendering, or the template not matching your theme's style—feel free to ask for more specific tweaks!
内容的提问来源于stack exchange,提问作者Saroj Shrestha

