Create reusable article card component and fix archive title prefixes
This commit is contained in:
178
functions.php
178
functions.php
@@ -3,15 +3,16 @@
|
||||
* Functions and definitions
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'wisdom1_setup' ) ) :
|
||||
function wisdom1_setup() {
|
||||
add_theme_support( 'automatic-feed-links' );
|
||||
add_theme_support( 'title-tag' );
|
||||
add_theme_support( 'post-thumbnails' );
|
||||
if (!function_exists('wisdom1_setup')):
|
||||
function wisdom1_setup()
|
||||
{
|
||||
add_theme_support('automatic-feed-links');
|
||||
add_theme_support('title-tag');
|
||||
add_theme_support('post-thumbnails');
|
||||
|
||||
register_nav_menus(
|
||||
array(
|
||||
'menu-1' => esc_html__( 'Primary', 'wisdom1' ),
|
||||
'menu-1' => esc_html__('Primary', 'wisdom1'),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -29,30 +30,32 @@ if ( ! function_exists( 'wisdom1_setup' ) ) :
|
||||
);
|
||||
}
|
||||
endif;
|
||||
add_action( 'after_setup_theme', 'wisdom1_setup' );
|
||||
add_action('after_setup_theme', 'wisdom1_setup');
|
||||
|
||||
/**
|
||||
* Enqueue scripts and styles.
|
||||
*/
|
||||
function wisdom1_scripts() {
|
||||
function wisdom1_scripts()
|
||||
{
|
||||
// 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)
|
||||
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)
|
||||
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.
|
||||
*/
|
||||
function wisdom1_reading_time() {
|
||||
$content = get_post_field( 'post_content', get_the_ID() );
|
||||
$word_count = str_word_count( strip_tags( $content ) );
|
||||
$reading_time = ceil( $word_count / 200 ); // Average 200 words per minute
|
||||
function wisdom1_reading_time()
|
||||
{
|
||||
$content = get_post_field('post_content', get_the_ID());
|
||||
$word_count = str_word_count(strip_tags($content));
|
||||
$reading_time = ceil($word_count / 200); // Average 200 words per minute
|
||||
|
||||
return $reading_time . ' min read';
|
||||
}
|
||||
@@ -60,99 +63,120 @@ function wisdom1_reading_time() {
|
||||
/**
|
||||
* Customizer additions.
|
||||
*/
|
||||
function wisdom1_customize_register( $wp_customize ) {
|
||||
function wisdom1_customize_register($wp_customize)
|
||||
{
|
||||
// Add Hero Section
|
||||
$wp_customize->add_section( 'wisdom1_hero_section', array(
|
||||
'title' => __( 'Hero Section', 'wisdom1' ),
|
||||
$wp_customize->add_section('wisdom1_hero_section', array(
|
||||
'title' => __('Hero Section', 'wisdom1'),
|
||||
'priority' => 30,
|
||||
) );
|
||||
));
|
||||
|
||||
// Headline Setting
|
||||
$wp_customize->add_setting( 'hero_headline', array(
|
||||
'default' => 'Ancient Wisdom for a Modern World.',
|
||||
$wp_customize->add_setting('hero_headline', array(
|
||||
'default' => 'Ancient Wisdom for a Modern World.',
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
) );
|
||||
$wp_customize->add_control( 'hero_headline', array(
|
||||
'label' => __( 'Hero Headline', 'wisdom1' ),
|
||||
'section' => 'wisdom1_hero_section',
|
||||
'type' => 'text',
|
||||
) );
|
||||
));
|
||||
$wp_customize->add_control('hero_headline', array(
|
||||
'label' => __('Hero Headline', 'wisdom1'),
|
||||
'section' => 'wisdom1_hero_section',
|
||||
'type' => 'text',
|
||||
));
|
||||
|
||||
// Subheadline Setting
|
||||
$wp_customize->add_setting( 'hero_subheadline', array(
|
||||
'default' => 'A collection of biblical insights curated for the thoughtful leader.',
|
||||
$wp_customize->add_setting('hero_subheadline', array(
|
||||
'default' => 'A collection of biblical insights curated for the thoughtful leader.',
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
) );
|
||||
$wp_customize->add_control( 'hero_subheadline', array(
|
||||
'label' => __( 'Hero Subheadline', 'wisdom1' ),
|
||||
'section' => 'wisdom1_hero_section',
|
||||
'type' => 'textarea',
|
||||
) );
|
||||
));
|
||||
$wp_customize->add_control('hero_subheadline', array(
|
||||
'label' => __('Hero Subheadline', 'wisdom1'),
|
||||
'section' => 'wisdom1_hero_section',
|
||||
'type' => 'textarea',
|
||||
));
|
||||
|
||||
// CTA Text Setting
|
||||
$wp_customize->add_setting( 'hero_cta_text', array(
|
||||
'default' => 'Start Reading',
|
||||
$wp_customize->add_setting('hero_cta_text', array(
|
||||
'default' => 'Start Reading',
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
) );
|
||||
$wp_customize->add_control( 'hero_cta_text', array(
|
||||
'label' => __( 'CTA Button Text', 'wisdom1' ),
|
||||
'section' => 'wisdom1_hero_section',
|
||||
'type' => 'text',
|
||||
) );
|
||||
));
|
||||
$wp_customize->add_control('hero_cta_text', array(
|
||||
'label' => __('CTA Button Text', 'wisdom1'),
|
||||
'section' => 'wisdom1_hero_section',
|
||||
'type' => 'text',
|
||||
));
|
||||
|
||||
// Hero Background Image Setting
|
||||
$wp_customize->add_setting( 'hero_background_image', array(
|
||||
'default' => get_template_directory_uri() . '/assets/images/hero-default.png',
|
||||
$wp_customize->add_setting('hero_background_image', array(
|
||||
'default' => get_template_directory_uri() . '/assets/images/hero-default.png',
|
||||
'sanitize_callback' => 'esc_url_raw',
|
||||
) );
|
||||
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'hero_background_image', array(
|
||||
'label' => __( 'Hero Background Image', 'wisdom1' ),
|
||||
'section' => 'wisdom1_hero_section',
|
||||
));
|
||||
$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'hero_background_image', array(
|
||||
'label' => __('Hero Background Image', 'wisdom1'),
|
||||
'section' => 'wisdom1_hero_section',
|
||||
'settings' => 'hero_background_image',
|
||||
) ) );
|
||||
)));
|
||||
}
|
||||
add_action( 'customize_register', 'wisdom1_customize_register' );
|
||||
add_action('customize_register', 'wisdom1_customize_register');
|
||||
|
||||
/**
|
||||
* Register Series Taxonomy
|
||||
*/
|
||||
function wisdom1_register_taxonomies() {
|
||||
function wisdom1_register_taxonomies()
|
||||
{
|
||||
$labels = array(
|
||||
'name' => _x( 'Series', 'taxonomy general name', 'wisdom1' ),
|
||||
'singular_name' => _x( 'Series', 'taxonomy singular name', 'wisdom1' ),
|
||||
'search_items' => __( 'Search Series', 'wisdom1' ),
|
||||
'all_items' => __( 'All Series', 'wisdom1' ),
|
||||
'parent_item' => __( 'Parent Series', 'wisdom1' ),
|
||||
'parent_item_colon' => __( 'Parent Series:', 'wisdom1' ),
|
||||
'edit_item' => __( 'Edit Series', 'wisdom1' ),
|
||||
'update_item' => __( 'Update Series', 'wisdom1' ),
|
||||
'add_new_item' => __( 'Add New Series', 'wisdom1' ),
|
||||
'new_item_name' => __( 'New Series Name', 'wisdom1' ),
|
||||
'menu_name' => __( 'Series', 'wisdom1' ),
|
||||
'name' => _x('Series', 'taxonomy general name', 'wisdom1'),
|
||||
'singular_name' => _x('Series', 'taxonomy singular name', 'wisdom1'),
|
||||
'search_items' => __('Search Series', 'wisdom1'),
|
||||
'all_items' => __('All Series', 'wisdom1'),
|
||||
'parent_item' => __('Parent Series', 'wisdom1'),
|
||||
'parent_item_colon' => __('Parent Series:', 'wisdom1'),
|
||||
'edit_item' => __('Edit Series', 'wisdom1'),
|
||||
'update_item' => __('Update Series', 'wisdom1'),
|
||||
'add_new_item' => __('Add New Series', 'wisdom1'),
|
||||
'new_item_name' => __('New Series Name', 'wisdom1'),
|
||||
'menu_name' => __('Series', 'wisdom1'),
|
||||
);
|
||||
|
||||
$args = array(
|
||||
'hierarchical' => true,
|
||||
'labels' => $labels,
|
||||
'show_ui' => true,
|
||||
'hierarchical' => true,
|
||||
'labels' => $labels,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => true,
|
||||
'query_var' => true,
|
||||
'rewrite' => array( 'slug' => 'series' ),
|
||||
'show_in_rest' => true,
|
||||
'query_var' => true,
|
||||
'rewrite' => array('slug' => 'series'),
|
||||
'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
|
||||
*/
|
||||
function wisdom1_menu_fallback() {
|
||||
function wisdom1_menu_fallback()
|
||||
{
|
||||
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( '/articles/' ) ) . '">Articles</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('/')) . '">Home</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('/about/')) . '">About</a></li>';
|
||||
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;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user