I’ll build this as a complete WordPress page template for RX Theme: safe checks, accessible layout, breadcrumbs, right sidebar, hooks, schema-ready areas, pagination, and fallback handling.
Dear friend, create this file:
rx-theme/templates/template-right-sidebar.php
Then paste this full advanced code:
<?php
/**
* Template Name: RX Right Sidebar
* Template Post Type: page, post
*
* Advanced right-sidebar template for RX Theme.
*
* @package RX_Theme
* @since 1.0.0
*/
defined( 'ABSPATH' ) || exit;
get_header();
/**
* Page/post ID.
*/
$rx_post_id = get_the_ID();
/**
* Template layout classes.
*/
$rx_wrapper_class = apply_filters(
'rx_theme_right_sidebar_wrapper_class',
'rx-container rx-template rx-template-right-sidebar'
);
$rx_content_class = apply_filters(
'rx_theme_right_sidebar_content_class',
'rx-content-area rx-main-content'
);
$rx_sidebar_class = apply_filters(
'rx_theme_right_sidebar_sidebar_class',
'rx-sidebar-area rx-right-sidebar'
);
/**
* Detect sidebar.
*/
$rx_has_sidebar = is_active_sidebar( 'right-sidebar' ) || is_active_sidebar( 'sidebar-1' );
/**
* Body layout modifier.
*/
$rx_layout_class = $rx_has_sidebar ? 'rx-layout-has-sidebar' : 'rx-layout-no-sidebar';
?>
<main id="primary" class="<?php echo esc_attr( $rx_content_class ); ?>" role="main">
<?php
/**
* Hook before template wrapper.
*
* Useful for:
* - ads
* - breadcrumbs
* - notification bars
* - custom hero sections
*/
do_action( 'rx_theme_before_right_sidebar_template' );
?>
<div class="<?php echo esc_attr( $rx_wrapper_class . ' ' . $rx_layout_class ); ?>">
<?php
/**
* Optional breadcrumb area.
*/
if ( function_exists( 'rx_theme_breadcrumbs' ) ) :
?>
<nav class="rx-breadcrumbs-wrap" aria-label="<?php echo esc_attr__( 'Breadcrumbs', 'rx-theme' ); ?>">
<?php rx_theme_breadcrumbs(); ?>
</nav>
<?php
elseif ( function_exists( 'yoast_breadcrumb' ) ) :
?>
<nav class="rx-breadcrumbs-wrap" aria-label="<?php echo esc_attr__( 'Breadcrumbs', 'rx-theme' ); ?>">
<?php yoast_breadcrumb( '<p id="breadcrumbs">', '</p>' ); ?>
</nav>
<?php
endif;
?>
<div class="rx-layout-grid rx-layout-grid-right-sidebar">
<section id="rx-main-column" class="rx-primary-column">
<?php
/**
* Hook before content.
*/
do_action( 'rx_theme_before_right_sidebar_content' );
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
/**
* Article classes.
*/
$rx_article_classes = array(
'rx-entry',
'rx-entry-right-sidebar',
'rx-entry-id-' . absint( get_the_ID() ),
);
if ( has_post_thumbnail() ) {
$rx_article_classes[] = 'rx-has-featured-image';
}
if ( is_singular( 'page' ) ) {
$rx_article_classes[] = 'rx-page-entry';
}
if ( is_singular( 'post' ) ) {
$rx_article_classes[] = 'rx-post-entry';
}
?>
<article id="post-<?php the_ID(); ?>" <?php post_class( $rx_article_classes ); ?> itemscope itemtype="https://schema.org/Article">
<?php
/**
* Hook before article header.
*/
do_action( 'rx_theme_before_entry_header', get_the_ID() );
?>
<header class="rx-entry-header">
<?php if ( is_singular( 'post' ) ) : ?>
<div class="rx-entry-meta rx-entry-meta-top">
<span class="rx-posted-on">
<?php echo esc_html__( 'Published on ', 'rx-theme' ); ?>
<time datetime="<?php echo esc_attr( get_the_date( DATE_W3C ) ); ?>" itemprop="datePublished">
<?php echo esc_html( get_the_date() ); ?>
</time>
</span>
<span class="rx-entry-author" itemprop="author" itemscope itemtype="https://schema.org/Person">
<?php echo esc_html__( ' by ', 'rx-theme' ); ?>
<a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" itemprop="url">
<span itemprop="name"><?php echo esc_html( get_the_author() ); ?></span>
</a>
</span>
</div>
<?php endif; ?>
<?php
if ( is_singular() ) {
the_title( '<h1 class="rx-entry-title" itemprop="headline">', '</h1>' );
} else {
the_title(
'<h2 class="rx-entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">',
'</a></h2>'
);
}
?>
<?php if ( has_excerpt() ) : ?>
<div class="rx-entry-summary-intro" itemprop="description">
<?php the_excerpt(); ?>
</div>
<?php endif; ?>
</header>
<?php
/**
* Hook after article header.
*/
do_action( 'rx_theme_after_entry_header', get_the_ID() );
?>
<?php if ( has_post_thumbnail() ) : ?>
<figure class="rx-featured-image" itemprop="image" itemscope itemtype="https://schema.org/ImageObject">
<?php
the_post_thumbnail(
'large',
array(
'class' => 'rx-featured-img',
'loading' => 'eager',
'decoding' => 'async',
'alt' => esc_attr( get_the_title() ),
)
);
?>
</figure>
<?php endif; ?>
<div class="rx-entry-content" itemprop="articleBody">
<?php
/**
* Hook before article body.
*/
do_action( 'rx_theme_before_entry_content', get_the_ID() );
the_content(
sprintf(
wp_kses(
__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'rx-theme' ),
array(
'span' => array(
'class' => array(),
),
)
),
wp_kses_post( get_the_title() )
)
);
wp_link_pages(
array(
'before' => '<nav class="rx-page-links" aria-label="' . esc_attr__( 'Page links', 'rx-theme' ) . '"><span class="rx-page-links-title">' . esc_html__( 'Pages:', 'rx-theme' ) . '</span>',
'after' => '</nav>',
'link_before' => '<span class="rx-page-link">',
'link_after' => '</span>',
)
);
/**
* Hook after article body.
*/
do_action( 'rx_theme_after_entry_content', get_the_ID() );
?>
</div>
<footer class="rx-entry-footer">
<?php if ( is_singular( 'post' ) ) : ?>
<div class="rx-entry-taxonomies">
<?php
$rx_categories = get_the_category_list( esc_html__( ', ', 'rx-theme' ) );
if ( $rx_categories ) :
?>
<div class="rx-entry-categories">
<strong><?php esc_html_e( 'Categories:', 'rx-theme' ); ?></strong>
<?php echo wp_kses_post( $rx_categories ); ?>
</div>
<?php
endif;
$rx_tags = get_the_tag_list( '', esc_html__( ', ', 'rx-theme' ) );
if ( $rx_tags ) :
?>
<div class="rx-entry-tags">
<strong><?php esc_html_e( 'Tags:', 'rx-theme' ); ?></strong>
<?php echo wp_kses_post( $rx_tags ); ?>
</div>
<?php
endif;
?>
</div>
<?php endif; ?>
<?php
edit_post_link(
esc_html__( 'Edit this content', 'rx-theme' ),
'<span class="rx-edit-link">',
'</span>'
);
?>
</footer>
<?php
/**
* Hook after article.
*/
do_action( 'rx_theme_after_entry_article', get_the_ID() );
?>
</article>
<?php
/**
* Author box for posts.
*/
if ( is_singular( 'post' ) && get_the_author_meta( 'description' ) ) :
?>
<section class="rx-author-box" aria-label="<?php echo esc_attr__( 'Author information', 'rx-theme' ); ?>">
<div class="rx-author-avatar">
<?php echo get_avatar( get_the_author_meta( 'ID' ), 96 ); ?>
</div>
<div class="rx-author-content">
<h2 class="rx-author-title">
<?php echo esc_html( get_the_author() ); ?>
</h2>
<p class="rx-author-description">
<?php echo esc_html( get_the_author_meta( 'description' ) ); ?>
</p>
<a class="rx-author-link" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>">
<?php esc_html_e( 'View all posts', 'rx-theme' ); ?>
</a>
</div>
</section>
<?php
endif;
?>
<?php
/**
* Previous / next post navigation.
*/
if ( is_singular( 'post' ) ) {
the_post_navigation(
array(
'prev_text' => '<span class="rx-nav-subtitle">' . esc_html__( 'Previous:', 'rx-theme' ) . '</span> <span class="rx-nav-title">%title</span>',
'next_text' => '<span class="rx-nav-subtitle">' . esc_html__( 'Next:', 'rx-theme' ) . '</span> <span class="rx-nav-title">%title</span>',
)
);
}
/**
* Related posts placeholder.
*
* You can later create function rx_theme_related_posts().
*/
if ( is_singular( 'post' ) && function_exists( 'rx_theme_related_posts' ) ) {
rx_theme_related_posts( get_the_ID() );
}
/**
* Comments.
*/
if ( comments_open() || get_comments_number() ) {
comments_template();
}
endwhile;
else :
?>
<section class="rx-no-content">
<h1><?php esc_html_e( 'Nothing found', 'rx-theme' ); ?></h1>
<p><?php esc_html_e( 'Sorry, no content is available here.', 'rx-theme' ); ?></p>
</section>
<?php
endif;
/**
* Hook after content.
*/
do_action( 'rx_theme_after_right_sidebar_content' );
?>
</section>
<?php if ( $rx_has_sidebar ) : ?>
<aside id="secondary" class="<?php echo esc_attr( $rx_sidebar_class ); ?>" role="complementary" aria-label="<?php echo esc_attr__( 'Right Sidebar', 'rx-theme' ); ?>">
<?php
/**
* Hook before sidebar.
*/
do_action( 'rx_theme_before_right_sidebar' );
if ( is_active_sidebar( 'right-sidebar' ) ) {
dynamic_sidebar( 'right-sidebar' );
} elseif ( is_active_sidebar( 'sidebar-1' ) ) {
dynamic_sidebar( 'sidebar-1' );
}
/**
* Hook after sidebar.
*/
do_action( 'rx_theme_after_right_sidebar' );
?>
</aside>
<?php endif; ?>
</div>
</div>
<?php
/**
* Hook after template wrapper.
*/
do_action( 'rx_theme_after_right_sidebar_template' );
?>
</main>
<?php
get_footer();
Now add/register the right sidebar in your functions.php or better in:
inc/core/sidebars.php
<?php
/**
* RX Theme sidebars.
*
* @package RX_Theme
*/
defined( 'ABSPATH' ) || exit;
if ( ! function_exists( 'rx_theme_register_sidebars' ) ) :
function rx_theme_register_sidebars() {
register_sidebar(
array(
'name' => esc_html__( 'Right Sidebar', 'rx-theme' ),
'id' => 'right-sidebar',
'description' => esc_html__( 'Widgets added here will appear in the right sidebar template.', 'rx-theme' ),
'before_widget' => '<section id="%1$s" class="widget rx-widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title rx-widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => esc_html__( 'Default Sidebar', 'rx-theme' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Default fallback sidebar for RX Theme.', 'rx-theme' ),
'before_widget' => '<section id="%1$s" class="widget rx-widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title rx-widget-title">',
'after_title' => '</h2>',
)
);
}
endif;
add_action( 'widgets_init', 'rx_theme_register_sidebars' );
Add this CSS in:
assets/css/templates/template-right-sidebar.css
/**
* RX Theme - Right Sidebar Template
*/
.rx-template-right-sidebar {
width: min(100% - 32px, 1200px);
margin-inline: auto;
}
.rx-layout-grid-right-sidebar {
display: grid;
grid-template-columns: minmax(0, 1fr) 320px;
gap: clamp(24px, 4vw, 48px);
align-items: start;
}
.rx-layout-no-sidebar .rx-layout-grid-right-sidebar {
grid-template-columns: minmax(0, 1fr);
}
.rx-primary-column {
min-width: 0;
}
.rx-right-sidebar {
position: relative;
min-width: 0;
}
.rx-entry {
background: var(--rx-color-surface, #ffffff);
border: 1px solid var(--rx-color-border, #e5e7eb);
border-radius: var(--rx-radius-lg, 16px);
padding: clamp(20px, 4vw, 40px);
box-shadow: var(--rx-shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.06));
}
.rx-entry-header {
margin-bottom: 24px;
}
.rx-entry-title {
margin: 0 0 16px;
font-size: clamp(2rem, 4vw, 3.25rem);
line-height: 1.15;
letter-spacing: -0.03em;
color: var(--rx-color-heading, #111827);
}
.rx-entry-title a {
color: inherit;
text-decoration: none;
}
.rx-entry-title a:hover,
.rx-entry-title a:focus {
color: var(--rx-color-primary, #2563eb);
}
.rx-entry-meta {
display: flex;
flex-wrap: wrap;
gap: 8px 16px;
font-size: 0.9375rem;
color: var(--rx-color-muted, #6b7280);
margin-bottom: 16px;
}
.rx-entry-meta a {
color: inherit;
text-decoration: underline;
text-underline-offset: 3px;
}
.rx-entry-summary-intro {
font-size: 1.125rem;
line-height: 1.8;
color: var(--rx-color-text, #374151);
margin-top: 16px;
}
.rx-featured-image {
margin: 0 0 28px;
overflow: hidden;
border-radius: var(--rx-radius-md, 12px);
}
.rx-featured-img {
display: block;
width: 100%;
height: auto;
}
.rx-entry-content {
font-size: 1.0625rem;
line-height: 1.85;
color: var(--rx-color-text, #374151);
}
.rx-entry-content > *:first-child {
margin-top: 0;
}
.rx-entry-content > *:last-child {
margin-bottom: 0;
}
.rx-entry-content h2,
.rx-entry-content h3,
.rx-entry-content h4 {
color: var(--rx-color-heading, #111827);
line-height: 1.3;
margin-top: 2em;
margin-bottom: 0.75em;
}
.rx-entry-content h2 {
font-size: clamp(1.6rem, 3vw, 2.25rem);
}
.rx-entry-content h3 {
font-size: clamp(1.35rem, 2.4vw, 1.75rem);
}
.rx-entry-content p {
margin-bottom: 1.4em;
}
.rx-entry-content a {
color: var(--rx-color-primary, #2563eb);
text-decoration: underline;
text-underline-offset: 3px;
}
.rx-entry-content img {
max-width: 100%;
height: auto;
border-radius: var(--rx-radius-sm, 8px);
}
.rx-entry-content blockquote {
border-left: 4px solid var(--rx-color-primary, #2563eb);
padding-left: 20px;
margin-left: 0;
color: var(--rx-color-muted, #4b5563);
font-style: italic;
}
.rx-entry-content table {
width: 100%;
border-collapse: collapse;
margin: 24px 0;
font-size: 0.95rem;
}
.rx-entry-content th,
.rx-entry-content td {
border: 1px solid var(--rx-color-border, #e5e7eb);
padding: 12px;
text-align: left;
}
.rx-entry-content th {
background: var(--rx-color-soft, #f9fafb);
color: var(--rx-color-heading, #111827);
}
.rx-page-links {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 32px;
}
.rx-page-links-title {
font-weight: 700;
margin-right: 8px;
}
.rx-page-link {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 36px;
min-height: 36px;
border: 1px solid var(--rx-color-border, #e5e7eb);
border-radius: 999px;
padding: 6px 12px;
}
.rx-entry-footer {
margin-top: 32px;
padding-top: 24px;
border-top: 1px solid var(--rx-color-border, #e5e7eb);
font-size: 0.95rem;
color: var(--rx-color-muted, #6b7280);
}
.rx-entry-taxonomies {
display: grid;
gap: 10px;
}
.rx-entry-taxonomies a {
color: var(--rx-color-primary, #2563eb);
text-decoration: none;
}
.rx-entry-taxonomies a:hover,
.rx-entry-taxonomies a:focus {
text-decoration: underline;
}
.rx-author-box {
display: flex;
gap: 20px;
margin-top: 32px;
padding: 24px;
background: var(--rx-color-soft, #f9fafb);
border: 1px solid var(--rx-color-border, #e5e7eb);
border-radius: var(--rx-radius-lg, 16px);
}
.rx-author-avatar img {
border-radius: 999px;
}
.rx-author-title {
margin: 0 0 8px;
font-size: 1.25rem;
}
.rx-author-description {
margin: 0 0 12px;
line-height: 1.7;
}
.rx-author-link {
color: var(--rx-color-primary, #2563eb);
font-weight: 600;
}
.rx-right-sidebar .widget {
margin-bottom: 24px;
padding: 24px;
background: var(--rx-color-surface, #ffffff);
border: 1px solid var(--rx-color-border, #e5e7eb);
border-radius: var(--rx-radius-lg, 16px);
box-shadow: var(--rx-shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.06));
}
.rx-widget-title,
.rx-right-sidebar .widget-title {
margin: 0 0 16px;
font-size: 1.25rem;
line-height: 1.3;
color: var(--rx-color-heading, #111827);
}
.rx-right-sidebar ul {
padding-left: 20px;
}
.rx-right-sidebar a {
color: var(--rx-color-primary, #2563eb);
text-decoration: none;
}
.rx-right-sidebar a:hover,
.rx-right-sidebar a:focus {
text-decoration: underline;
}
.rx-breadcrumbs-wrap {
margin-bottom: 24px;
font-size: 0.9375rem;
color: var(--rx-color-muted, #6b7280);
}
.rx-no-content {
padding: 40px;
background: var(--rx-color-soft, #f9fafb);
border-radius: var(--rx-radius-lg, 16px);
}
@media (max-width: 992px) {
.rx-layout-grid-right-sidebar {
grid-template-columns: 1fr;
}
.rx-right-sidebar {
margin-top: 32px;
}
}
@media (max-width: 640px) {
.rx-template-right-sidebar {
width: min(100% - 20px, 1200px);
}
.rx-entry {
padding: 20px;
}
.rx-author-box {
flex-direction: column;
}
}
Then enqueue this CSS only when this template is used. Add this in your enqueue file, for example:
inc/core/enqueue.php
<?php
/**
* RX Theme assets.
*
* @package RX_Theme
*/
defined( 'ABSPATH' ) || exit;
if ( ! function_exists( 'rx_theme_enqueue_right_sidebar_template_css' ) ) :
function rx_theme_enqueue_right_sidebar_template_css() {
if ( is_page_template( 'templates/template-right-sidebar.php' ) ) {
wp_enqueue_style(
'rx-template-right-sidebar',
get_template_directory_uri() . '/assets/css/templates/template-right-sidebar.css',
array(),
wp_get_theme()->get( 'Version' )
);
}
}
endif;
add_action( 'wp_enqueue_scripts', 'rx_theme_enqueue_right_sidebar_template_css' );
For your RX Theme, this is a strong advanced template because it supports:
Accessibility, right-sidebar fallback, breadcrumbs, featured image, post meta, schema markup, author box, comments, previous/next post navigation, related-post hook, custom action hooks, reusable CSS variables, mobile responsiveness, and widget-ready sidebar.