Create reusable article card component and fix archive title prefixes
This commit is contained in:
16
category.php
16
category.php
@@ -7,7 +7,7 @@ get_header(); ?>
|
|||||||
|
|
||||||
<div class="bg-light py-5 border-bottom mb-5">
|
<div class="bg-light py-5 border-bottom mb-5">
|
||||||
<div class="container text-center">
|
<div class="container text-center">
|
||||||
<h1 class="display-5 fw-bold mb-3">Archive: <?php single_cat_title(); ?></h1>
|
<h1 class="display-5 fw-bold mb-3"><?php single_cat_title(); ?></h1>
|
||||||
<?php if (category_description()): ?>
|
<?php if (category_description()): ?>
|
||||||
<div class="lead text-muted mx-auto w-75"><?php echo category_description(); ?></div>
|
<div class="lead text-muted mx-auto w-75"><?php echo category_description(); ?></div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
@@ -22,19 +22,7 @@ get_header(); ?>
|
|||||||
while (have_posts()):
|
while (have_posts()):
|
||||||
the_post();
|
the_post();
|
||||||
?>
|
?>
|
||||||
<div class="col-md-6 col-lg-4 d-flex align-items-stretch">
|
<?php get_template_part('template-parts/content', 'card'); ?>
|
||||||
<article id="post-<?php the_ID(); ?>" <?php post_class('card w-100 border-0 shadow-sm h-100'); ?>>
|
|
||||||
<div class="card-body d-flex flex-column">
|
|
||||||
<header class="entry-header mb-3">
|
|
||||||
<?php the_title('<h3 class="card-title h5 fw-bold"><a href="' . esc_url(get_permalink()) . '" class="text-dark text-decoration-none stretched-link">', '</a></h3>'); ?>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<div class="card-text text-muted flex-grow-1">
|
|
||||||
<?php the_excerpt(); ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
</div>
|
|
||||||
<?php
|
<?php
|
||||||
endwhile;
|
endwhile;
|
||||||
|
|
||||||
|
|||||||
@@ -35,37 +35,7 @@ $hero_bg = get_theme_mod('hero_background_image', get_template_directory_uri() .
|
|||||||
while (have_posts()):
|
while (have_posts()):
|
||||||
the_post();
|
the_post();
|
||||||
?>
|
?>
|
||||||
<div class="col-md-6 col-lg-4 d-flex align-items-stretch">
|
<?php get_template_part('template-parts/content', 'card'); ?>
|
||||||
<article id="post-<?php the_ID(); ?>" <?php post_class('card w-100 border-0 shadow-sm overflow-hidden h-100'); ?>>
|
|
||||||
<?php if (has_post_thumbnail()): ?>
|
|
||||||
<a href="<?php the_permalink(); ?>">
|
|
||||||
<?php the_post_thumbnail('large', array('class' => 'card-img-top img-fluid w-100', 'style' => 'height: 200px; object-fit: cover;')); ?>
|
|
||||||
</a>
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<div class="card-body d-flex flex-column p-4">
|
|
||||||
<header class="entry-header mb-3">
|
|
||||||
<div class="mb-2 text-uppercase small fw-bold text-muted tracking-wider">
|
|
||||||
<?php echo get_the_category_list(', '); ?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<?php the_title('<h3 class="card-title h5 fw-bold lh-base"><a href="' . esc_url(get_permalink()) . '" class="text-dark text-decoration-none stretched-link">', '</a></h3>'); ?>
|
|
||||||
|
|
||||||
<div class="text-muted small mt-2 d-flex align-items-center flex-wrap gap-2">
|
|
||||||
<span><?php echo get_the_date(); ?></span>
|
|
||||||
<span>•</span>
|
|
||||||
<span><?php echo wisdom1_reading_time(); ?></span>
|
|
||||||
<span>•</span>
|
|
||||||
<span><?php comments_number('0 comments', '1 comment', '% comments'); ?></span>
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<div class="card-text text-muted flex-grow-1">
|
|
||||||
<?php the_excerpt(); ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
</div>
|
|
||||||
<?php
|
<?php
|
||||||
endwhile;
|
endwhile;
|
||||||
|
|
||||||
|
|||||||
146
functions.php
146
functions.php
@@ -3,15 +3,16 @@
|
|||||||
* Functions and definitions
|
* Functions and definitions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! function_exists( 'wisdom1_setup' ) ) :
|
if (!function_exists('wisdom1_setup')):
|
||||||
function wisdom1_setup() {
|
function wisdom1_setup()
|
||||||
add_theme_support( 'automatic-feed-links' );
|
{
|
||||||
add_theme_support( 'title-tag' );
|
add_theme_support('automatic-feed-links');
|
||||||
add_theme_support( 'post-thumbnails' );
|
add_theme_support('title-tag');
|
||||||
|
add_theme_support('post-thumbnails');
|
||||||
|
|
||||||
register_nav_menus(
|
register_nav_menus(
|
||||||
array(
|
array(
|
||||||
'menu-1' => esc_html__( 'Primary', 'wisdom1' ),
|
'menu-1' => esc_html__('Primary', 'wisdom1'),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -29,30 +30,32 @@ if ( ! function_exists( 'wisdom1_setup' ) ) :
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
endif;
|
endif;
|
||||||
add_action( 'after_setup_theme', 'wisdom1_setup' );
|
add_action('after_setup_theme', 'wisdom1_setup');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enqueue scripts and styles.
|
* Enqueue scripts and styles.
|
||||||
*/
|
*/
|
||||||
function wisdom1_scripts() {
|
function wisdom1_scripts()
|
||||||
|
{
|
||||||
// Enqueue Bootstrap CSS
|
// Enqueue Bootstrap CSS
|
||||||
wp_enqueue_style( 'bootstrap-style', 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css', array(), '5.3.3' );
|
wp_enqueue_style('bootstrap-style', 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css', array(), '5.3.3');
|
||||||
|
|
||||||
// Enqueue Theme CSS (depends on Bootstrap so it loads after)
|
// Enqueue Theme CSS (depends on Bootstrap so it loads after)
|
||||||
wp_enqueue_style( 'wisdom1-style', get_stylesheet_uri(), array( 'bootstrap-style' ), '1.1.0' );
|
wp_enqueue_style('wisdom1-style', get_stylesheet_uri(), array('bootstrap-style'), '1.1.0');
|
||||||
|
|
||||||
// Enqueue Bootstrap JS Bundle (includes Popper)
|
// Enqueue Bootstrap JS Bundle (includes Popper)
|
||||||
wp_enqueue_script( 'bootstrap-script', 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js', array(), '5.3.3', true );
|
wp_enqueue_script('bootstrap-script', 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js', array(), '5.3.3', true);
|
||||||
}
|
}
|
||||||
add_action( 'wp_enqueue_scripts', 'wisdom1_scripts' );
|
add_action('wp_enqueue_scripts', 'wisdom1_scripts');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate estimated reading time.
|
* Calculate estimated reading time.
|
||||||
*/
|
*/
|
||||||
function wisdom1_reading_time() {
|
function wisdom1_reading_time()
|
||||||
$content = get_post_field( 'post_content', get_the_ID() );
|
{
|
||||||
$word_count = str_word_count( strip_tags( $content ) );
|
$content = get_post_field('post_content', get_the_ID());
|
||||||
$reading_time = ceil( $word_count / 200 ); // Average 200 words per minute
|
$word_count = str_word_count(strip_tags($content));
|
||||||
|
$reading_time = ceil($word_count / 200); // Average 200 words per minute
|
||||||
|
|
||||||
return $reading_time . ' min read';
|
return $reading_time . ' min read';
|
||||||
}
|
}
|
||||||
@@ -60,75 +63,77 @@ function wisdom1_reading_time() {
|
|||||||
/**
|
/**
|
||||||
* Customizer additions.
|
* Customizer additions.
|
||||||
*/
|
*/
|
||||||
function wisdom1_customize_register( $wp_customize ) {
|
function wisdom1_customize_register($wp_customize)
|
||||||
|
{
|
||||||
// Add Hero Section
|
// Add Hero Section
|
||||||
$wp_customize->add_section( 'wisdom1_hero_section', array(
|
$wp_customize->add_section('wisdom1_hero_section', array(
|
||||||
'title' => __( 'Hero Section', 'wisdom1' ),
|
'title' => __('Hero Section', 'wisdom1'),
|
||||||
'priority' => 30,
|
'priority' => 30,
|
||||||
) );
|
));
|
||||||
|
|
||||||
// Headline Setting
|
// Headline Setting
|
||||||
$wp_customize->add_setting( 'hero_headline', array(
|
$wp_customize->add_setting('hero_headline', array(
|
||||||
'default' => 'Ancient Wisdom for a Modern World.',
|
'default' => 'Ancient Wisdom for a Modern World.',
|
||||||
'sanitize_callback' => 'sanitize_text_field',
|
'sanitize_callback' => 'sanitize_text_field',
|
||||||
) );
|
));
|
||||||
$wp_customize->add_control( 'hero_headline', array(
|
$wp_customize->add_control('hero_headline', array(
|
||||||
'label' => __( 'Hero Headline', 'wisdom1' ),
|
'label' => __('Hero Headline', 'wisdom1'),
|
||||||
'section' => 'wisdom1_hero_section',
|
'section' => 'wisdom1_hero_section',
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
) );
|
));
|
||||||
|
|
||||||
// Subheadline Setting
|
// Subheadline Setting
|
||||||
$wp_customize->add_setting( 'hero_subheadline', array(
|
$wp_customize->add_setting('hero_subheadline', array(
|
||||||
'default' => 'A collection of biblical insights curated for the thoughtful leader.',
|
'default' => 'A collection of biblical insights curated for the thoughtful leader.',
|
||||||
'sanitize_callback' => 'sanitize_text_field',
|
'sanitize_callback' => 'sanitize_text_field',
|
||||||
) );
|
));
|
||||||
$wp_customize->add_control( 'hero_subheadline', array(
|
$wp_customize->add_control('hero_subheadline', array(
|
||||||
'label' => __( 'Hero Subheadline', 'wisdom1' ),
|
'label' => __('Hero Subheadline', 'wisdom1'),
|
||||||
'section' => 'wisdom1_hero_section',
|
'section' => 'wisdom1_hero_section',
|
||||||
'type' => 'textarea',
|
'type' => 'textarea',
|
||||||
) );
|
));
|
||||||
|
|
||||||
// CTA Text Setting
|
// CTA Text Setting
|
||||||
$wp_customize->add_setting( 'hero_cta_text', array(
|
$wp_customize->add_setting('hero_cta_text', array(
|
||||||
'default' => 'Start Reading',
|
'default' => 'Start Reading',
|
||||||
'sanitize_callback' => 'sanitize_text_field',
|
'sanitize_callback' => 'sanitize_text_field',
|
||||||
) );
|
));
|
||||||
$wp_customize->add_control( 'hero_cta_text', array(
|
$wp_customize->add_control('hero_cta_text', array(
|
||||||
'label' => __( 'CTA Button Text', 'wisdom1' ),
|
'label' => __('CTA Button Text', 'wisdom1'),
|
||||||
'section' => 'wisdom1_hero_section',
|
'section' => 'wisdom1_hero_section',
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
) );
|
));
|
||||||
|
|
||||||
// Hero Background Image Setting
|
// Hero Background Image Setting
|
||||||
$wp_customize->add_setting( 'hero_background_image', array(
|
$wp_customize->add_setting('hero_background_image', array(
|
||||||
'default' => get_template_directory_uri() . '/assets/images/hero-default.png',
|
'default' => get_template_directory_uri() . '/assets/images/hero-default.png',
|
||||||
'sanitize_callback' => 'esc_url_raw',
|
'sanitize_callback' => 'esc_url_raw',
|
||||||
) );
|
));
|
||||||
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'hero_background_image', array(
|
$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'hero_background_image', array(
|
||||||
'label' => __( 'Hero Background Image', 'wisdom1' ),
|
'label' => __('Hero Background Image', 'wisdom1'),
|
||||||
'section' => 'wisdom1_hero_section',
|
'section' => 'wisdom1_hero_section',
|
||||||
'settings' => 'hero_background_image',
|
'settings' => 'hero_background_image',
|
||||||
) ) );
|
)));
|
||||||
}
|
}
|
||||||
add_action( 'customize_register', 'wisdom1_customize_register' );
|
add_action('customize_register', 'wisdom1_customize_register');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register Series Taxonomy
|
* Register Series Taxonomy
|
||||||
*/
|
*/
|
||||||
function wisdom1_register_taxonomies() {
|
function wisdom1_register_taxonomies()
|
||||||
|
{
|
||||||
$labels = array(
|
$labels = array(
|
||||||
'name' => _x( 'Series', 'taxonomy general name', 'wisdom1' ),
|
'name' => _x('Series', 'taxonomy general name', 'wisdom1'),
|
||||||
'singular_name' => _x( 'Series', 'taxonomy singular name', 'wisdom1' ),
|
'singular_name' => _x('Series', 'taxonomy singular name', 'wisdom1'),
|
||||||
'search_items' => __( 'Search Series', 'wisdom1' ),
|
'search_items' => __('Search Series', 'wisdom1'),
|
||||||
'all_items' => __( 'All Series', 'wisdom1' ),
|
'all_items' => __('All Series', 'wisdom1'),
|
||||||
'parent_item' => __( 'Parent Series', 'wisdom1' ),
|
'parent_item' => __('Parent Series', 'wisdom1'),
|
||||||
'parent_item_colon' => __( 'Parent Series:', 'wisdom1' ),
|
'parent_item_colon' => __('Parent Series:', 'wisdom1'),
|
||||||
'edit_item' => __( 'Edit Series', 'wisdom1' ),
|
'edit_item' => __('Edit Series', 'wisdom1'),
|
||||||
'update_item' => __( 'Update Series', 'wisdom1' ),
|
'update_item' => __('Update Series', 'wisdom1'),
|
||||||
'add_new_item' => __( 'Add New Series', 'wisdom1' ),
|
'add_new_item' => __('Add New Series', 'wisdom1'),
|
||||||
'new_item_name' => __( 'New Series Name', 'wisdom1' ),
|
'new_item_name' => __('New Series Name', 'wisdom1'),
|
||||||
'menu_name' => __( 'Series', 'wisdom1' ),
|
'menu_name' => __('Series', 'wisdom1'),
|
||||||
);
|
);
|
||||||
|
|
||||||
$args = array(
|
$args = array(
|
||||||
@@ -137,22 +142,41 @@ function wisdom1_register_taxonomies() {
|
|||||||
'show_ui' => true,
|
'show_ui' => true,
|
||||||
'show_admin_column' => true,
|
'show_admin_column' => true,
|
||||||
'query_var' => true,
|
'query_var' => true,
|
||||||
'rewrite' => array( 'slug' => 'series' ),
|
'rewrite' => array('slug' => 'series'),
|
||||||
'show_in_rest' => true,
|
'show_in_rest' => true,
|
||||||
);
|
);
|
||||||
|
|
||||||
register_taxonomy( 'series', array( 'post' ), $args );
|
register_taxonomy('series', array('post'), $args);
|
||||||
}
|
}
|
||||||
add_action( 'init', 'wisdom1_register_taxonomies' );
|
add_action('init', 'wisdom1_register_taxonomies');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Menu fallback
|
* Menu fallback
|
||||||
*/
|
*/
|
||||||
function wisdom1_menu_fallback() {
|
function wisdom1_menu_fallback()
|
||||||
|
{
|
||||||
echo '<ul id="primary-menu" class="menu">';
|
echo '<ul id="primary-menu" class="menu">';
|
||||||
echo '<li><a href="' . esc_url( home_url( '/' ) ) . '">Home</a></li>';
|
echo '<li><a href="' . esc_url(home_url('/')) . '">Home</a></li>';
|
||||||
echo '<li><a href="' . esc_url( home_url( '/articles/' ) ) . '">Articles</a></li>';
|
echo '<li><a href="' . esc_url(home_url('/articles/')) . '">Articles</a></li>';
|
||||||
echo '<li><a href="' . esc_url( home_url( '/series/' ) ) . '">Series</a></li>';
|
echo '<li><a href="' . esc_url(home_url('/series/')) . '">Series</a></li>';
|
||||||
echo '<li><a href="' . esc_url( home_url( '/about/' ) ) . '">About</a></li>';
|
echo '<li><a href="' . esc_url(home_url('/about/')) . '">About</a></li>';
|
||||||
echo '</ul>';
|
echo '</ul>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter the archive title to remove prefixes
|
||||||
|
*/
|
||||||
|
add_filter('get_the_archive_title', function ($title) {
|
||||||
|
if (is_category()) {
|
||||||
|
$title = single_cat_title('', false);
|
||||||
|
} elseif (is_tag()) {
|
||||||
|
$title = single_tag_title('', false);
|
||||||
|
} elseif (is_author()) {
|
||||||
|
$title = '<span class="vcard">' . get_the_author() . '</span>';
|
||||||
|
} elseif (is_post_type_archive()) {
|
||||||
|
$title = post_type_archive_title('', false);
|
||||||
|
} elseif (is_tax()) {
|
||||||
|
$title = single_term_title('', false);
|
||||||
|
}
|
||||||
|
return $title;
|
||||||
|
});
|
||||||
|
|||||||
17
index.php
17
index.php
@@ -23,22 +23,7 @@ get_header(); ?>
|
|||||||
while (have_posts()):
|
while (have_posts()):
|
||||||
the_post();
|
the_post();
|
||||||
?>
|
?>
|
||||||
<div class="col-md-6 col-lg-4 d-flex align-items-stretch">
|
<?php get_template_part('template-parts/content', 'card'); ?>
|
||||||
<article id="post-<?php the_ID(); ?>" <?php post_class('card w-100 border-0 shadow-sm h-100'); ?>>
|
|
||||||
<div class="card-body d-flex flex-column">
|
|
||||||
<header class="entry-header mb-3">
|
|
||||||
<div class="entry-meta mb-2 small text-uppercase fw-bold text-muted">
|
|
||||||
<?php echo get_the_category_list(', '); ?>
|
|
||||||
</div>
|
|
||||||
<?php the_title('<h3 class="card-title h5 fw-bold"><a href="' . esc_url(get_permalink()) . '" class="text-dark text-decoration-none stretched-link">', '</a></h3>'); ?>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<div class="card-text text-muted flex-grow-1">
|
|
||||||
<?php the_excerpt(); ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
</div>
|
|
||||||
<?php
|
<?php
|
||||||
endwhile;
|
endwhile;
|
||||||
|
|
||||||
|
|||||||
37
template-parts/content-card.php
Normal file
37
template-parts/content-card.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<div class="col-md-6 col-lg-4 d-flex align-items-stretch">
|
||||||
|
<article id="post-<?php the_ID(); ?>" <?php post_class('card w-100 border-0 shadow-sm overflow-hidden h-100'); ?>>
|
||||||
|
<?php if (has_post_thumbnail()): ?>
|
||||||
|
<a href="<?php the_permalink(); ?>">
|
||||||
|
<?php the_post_thumbnail('large', array('class' => 'card-img-top img-fluid w-100', 'style' => 'height: 200px; object-fit: cover;')); ?>
|
||||||
|
</a>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<div class="card-body d-flex flex-column p-4">
|
||||||
|
<header class="entry-header mb-3">
|
||||||
|
<div class="mb-2 text-uppercase small fw-bold text-muted tracking-wider">
|
||||||
|
<?php echo get_the_category_list(', '); ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php the_title('<h3 class="card-title h5 fw-bold lh-base"><a href="' . esc_url(get_permalink()) . '" class="text-dark text-decoration-none stretched-link">', '</a></h3>'); ?>
|
||||||
|
|
||||||
|
<div class="text-muted small mt-2 d-flex align-items-center flex-wrap gap-2">
|
||||||
|
<span>
|
||||||
|
<?php echo get_the_date(); ?>
|
||||||
|
</span>
|
||||||
|
<span>•</span>
|
||||||
|
<span>
|
||||||
|
<?php echo function_exists('wisdom1_reading_time') ? wisdom1_reading_time() : ''; ?>
|
||||||
|
</span>
|
||||||
|
<span>•</span>
|
||||||
|
<span>
|
||||||
|
<?php comments_number('0 comments', '1 comment', '% comments'); ?>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="card-text text-muted flex-grow-1">
|
||||||
|
<?php the_excerpt(); ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
Reference in New Issue
Block a user