Skip to content

Commit

Permalink
#92: Add theme option to show full post on archive pages
Browse files Browse the repository at this point in the history
  • Loading branch information
nielslange committed Jun 3, 2020
1 parent 2cdc961 commit 496de72
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 18 deletions.
106 changes: 90 additions & 16 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,22 @@ function smntcs_retro_skip_link() {
* @return void
*/
function smntcs_retro_customize_register( $wp_customize ) {
$wp_customize->add_section(
$wp_customize->add_panel(
'smntcs_retro_theme_options_section',
array(
'priority' => 50,
'title' => __( 'Theme Options', 'smntcs-retro' ),
)
);

$wp_customize->add_section(
'smntcs_retro_theme_general_section',
array(
'title' => __( 'General', 'smntcs-retro' ),
'panel' => 'smntcs_retro_theme_options_section',
)
);

$wp_customize->add_setting(
'smntcs_retro_centre_site',
array(
Expand All @@ -228,7 +236,7 @@ function smntcs_retro_customize_register( $wp_customize ) {
'smntcs_retro_centre_site',
array(
'label' => __( 'Centre site', 'smntcs-retro' ),
'section' => 'smntcs_retro_theme_options_section',
'section' => 'smntcs_retro_theme_general_section',
'type' => 'checkbox',
)
);
Expand All @@ -246,7 +254,7 @@ function smntcs_retro_customize_register( $wp_customize ) {
'smntcs_retro_show_post_pagination',
array(
'label' => __( 'Show pagination on post pages', 'smntcs-retro' ),
'section' => 'smntcs_retro_theme_options_section',
'section' => 'smntcs_retro_theme_general_section',
'type' => 'checkbox',
)
);
Expand All @@ -264,7 +272,7 @@ function smntcs_retro_customize_register( $wp_customize ) {
'smntcs_retro_site_width',
array(
'label' => __( 'Site width', 'smntcs-retro' ),
'section' => 'smntcs_retro_theme_options_section',
'section' => 'smntcs_retro_theme_general_section',
'type' => 'radio',
'choices' => array(
'580' => __( '580px', 'smntcs-retro' ),
Expand All @@ -275,6 +283,41 @@ function smntcs_retro_customize_register( $wp_customize ) {
)
);

$wp_customize->add_section(
'smntcs_retro_theme_archive_section',
array(
'title' => __( 'Archives', 'smntcs-retro' ),
'panel' => 'smntcs_retro_theme_options_section',
)
);

// ---------------------------------------------------------------------------

$wp_customize->add_setting(
'smntcs_retro_archive_show_posts_as',
array(
'default' => true,
'sanitize_callback' => 'smntcs_retro_sanitize_select',
'type' => 'theme_mod',
'default' => 'excerpt',
)
);

$wp_customize->add_control(
'smntcs_retro_archive_show_posts_as',
array(
'label' => __( 'Show post as', 'smntcs-retro' ),
'section' => 'smntcs_retro_theme_archive_section',
'type' => 'select',
'choices' => array(
'excerpt' => __( 'Excerpt' ),
'full' => __( 'Full post' ),
),
)
);

// ---------------------------------------------------------------------------

$wp_customize->add_setting(
'smntcs_retro_archive_show_author',
array(
Expand All @@ -288,7 +331,7 @@ function smntcs_retro_customize_register( $wp_customize ) {
'smntcs_retro_archive_show_author',
array(
'label' => __( 'Show author on archive page', 'smntcs-retro' ),
'section' => 'smntcs_retro_theme_options_section',
'section' => 'smntcs_retro_theme_archive_section',
'type' => 'checkbox',
)
);
Expand All @@ -306,7 +349,7 @@ function smntcs_retro_customize_register( $wp_customize ) {
'smntcs_retro_archive_show_date',
array(
'label' => __( 'Show date on archive page', 'smntcs-retro' ),
'section' => 'smntcs_retro_theme_options_section',
'section' => 'smntcs_retro_theme_archive_section',
'type' => 'checkbox',
)
);
Expand All @@ -324,7 +367,7 @@ function smntcs_retro_customize_register( $wp_customize ) {
'smntcs_retro_archive_show_tags',
array(
'label' => __( 'Show tags on archive page', 'smntcs-retro' ),
'section' => 'smntcs_retro_theme_options_section',
'section' => 'smntcs_retro_theme_archive_section',
'type' => 'checkbox',
)
);
Expand All @@ -342,11 +385,19 @@ function smntcs_retro_customize_register( $wp_customize ) {
'smntcs_retro_archive_show_categories',
array(
'label' => __( 'Show categories on archive page', 'smntcs-retro' ),
'section' => 'smntcs_retro_theme_options_section',
'section' => 'smntcs_retro_theme_archive_section',
'type' => 'checkbox',
)
);

$wp_customize->add_section(
'smntcs_retro_theme_post_section',
array(
'title' => __( 'Posts', 'smntcs-retro' ),
'panel' => 'smntcs_retro_theme_options_section',
)
);

$wp_customize->add_setting(
'smntcs_retro_post_show_author',
array(
Expand All @@ -360,7 +411,7 @@ function smntcs_retro_customize_register( $wp_customize ) {
'smntcs_retro_post_show_author',
array(
'label' => __( 'Show author on posts', 'smntcs-retro' ),
'section' => 'smntcs_retro_theme_options_section',
'section' => 'smntcs_retro_theme_post_section',
'type' => 'checkbox',
)
);
Expand All @@ -378,7 +429,7 @@ function smntcs_retro_customize_register( $wp_customize ) {
'smntcs_retro_post_show_date',
array(
'label' => __( 'Show date on posts', 'smntcs-retro' ),
'section' => 'smntcs_retro_theme_options_section',
'section' => 'smntcs_retro_theme_post_section',
'type' => 'checkbox',
)
);
Expand All @@ -396,7 +447,7 @@ function smntcs_retro_customize_register( $wp_customize ) {
'smntcs_retro_post_show_tags',
array(
'label' => __( 'Show tags on posts', 'smntcs-retro' ),
'section' => 'smntcs_retro_theme_options_section',
'section' => 'smntcs_retro_theme_post_section',
'type' => 'checkbox',
)
);
Expand All @@ -414,7 +465,7 @@ function smntcs_retro_customize_register( $wp_customize ) {
'smntcs_retro_post_show_categories',
array(
'label' => __( 'Show categories on posts', 'smntcs-retro' ),
'section' => 'smntcs_retro_theme_options_section',
'section' => 'smntcs_retro_theme_post_section',
'type' => 'checkbox',
)
);
Expand All @@ -428,11 +479,19 @@ function smntcs_retro_customize_register( $wp_customize ) {
)
);

$wp_customize->add_section(
'smntcs_retro_theme_page_section',
array(
'title' => __( 'Pages', 'smntcs-retro' ),
'panel' => 'smntcs_retro_theme_options_section',
)
);

$wp_customize->add_control(
'smntcs_retro_page_show_author',
array(
'label' => __( 'Show author on pages', 'smntcs-retro' ),
'section' => 'smntcs_retro_theme_options_section',
'section' => 'smntcs_retro_theme_page_section',
'type' => 'checkbox',
)
);
Expand All @@ -450,7 +509,7 @@ function smntcs_retro_customize_register( $wp_customize ) {
'smntcs_retro_page_show_date',
array(
'label' => __( 'Show date on pages', 'smntcs-retro' ),
'section' => 'smntcs_retro_theme_options_section',
'section' => 'smntcs_retro_theme_page_section',
'type' => 'checkbox',
)
);
Expand All @@ -468,7 +527,7 @@ function smntcs_retro_customize_register( $wp_customize ) {
'smntcs_retro_page_show_tags',
array(
'label' => __( 'Show tags on pages', 'smntcs-retro' ),
'section' => 'smntcs_retro_theme_options_section',
'section' => 'smntcs_retro_theme_page_section',
'type' => 'checkbox',
)
);
Expand All @@ -486,7 +545,7 @@ function smntcs_retro_customize_register( $wp_customize ) {
'smntcs_retro_page_show_categories',
array(
'label' => __( 'Show categories on pages', 'smntcs-retro' ),
'section' => 'smntcs_retro_theme_options_section',
'section' => 'smntcs_retro_theme_page_section',
'type' => 'checkbox',
)
);
Expand Down Expand Up @@ -520,6 +579,21 @@ function smntcs_retro_sanitize_radio( $input, $setting ) {
return ( array_key_exists( $input, $choices ) ? $input : $setting->default );
}

/**
* Sanitize radio field.
*
* @param mixed $input The input to sanitize.
* @param mixed $setting The settings object.
* @return bool True if select field is valid, othewise false
*/
function smntcs_retro_sanitize_select( $input, $setting ) {

$input = sanitize_key( $input );
$choices = $setting->manager->get_control( $setting->id )->choices;

return ( array_key_exists( $input, $choices ) ? $input : $setting->default );
}

/**
* Add custom CSS to the site.
*
Expand Down
8 changes: 6 additions & 2 deletions template-parts/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@
smntcs_retro_post_categories();
}

// Display the post excerpt.
the_excerpt( $post->ID );
// Display the post excerpt or the full post.
if ( 'full' == get_theme_mod( 'smntcs_retro_archive_show_posts_as' ) ) {
the_content( $post->ID );
} else {
the_excerpt( $post->ID );
}

// Display the post edit link.
smntcs_retro_post_edit_link();
Expand Down

0 comments on commit 496de72

Please sign in to comment.