如何在 wordpress post 中显示 "Published on"-date 而不是 "Last edited"-date
How to show "Published on"-date instead of "Last edited"-date in wordpress post's
我有一个博客的主题,我正在尝试修改它,所以每次我编辑它时它总是显示 "published date" 而不是 "Edited on"...
我已将它钉在文件中 -> functions.php 显示日期的地方... "Posted On Function"
部分
但每次我尝试修改 if/else 时,我都会在页面上收到错误 500 :-(
在此非常感谢您的帮助...
提前致谢!
-最好的问候
我怀疑的部分是原因:
-------------------------------------------------------------------------------------------------------
Posted On Function
-------------------------------------------------------------------------------------------------------
*/
function swell_posted_on() {
if ( get_the_modified_time() != get_the_time() ) {
printf( __( '<span class="%1$s">Last Updated:</span> %2$s', 'organic-swell' ),
'meta-prep meta-prep-author',
sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
esc_url( get_permalink() ),
esc_attr( get_the_modified_time() ),
get_the_modified_date()
)
);
} else {
printf( __( '<span class="%1$s">Posted:</span> %2$s', 'organic-swell' ),
'meta-prep meta-prep-author',
sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
get_the_date()
)
);
}
}
/*
这是整个 functions.php 文件:
/*
-------------------------------------------------------------------------------------------------------
Theme Setup
-------------------------------------------------------------------------------------------------------
*/
if ( ! function_exists( 'swell_setup' ) ) :
function swell_setup() {
// Make theme available for translation.
load_theme_textdomain( 'organic-swell', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
// Enable support for Post Thumbnails.
add_theme_support( 'post-thumbnails' );
// Enable support for site title tag.
add_theme_support( 'title-tag' );
add_image_size( 'swell-featured-large', 1800, 1200, true ); // Large Featured Image.
add_image_size( 'swell-featured-medium', 1200, 800, true ); // Medium Featured Image.
add_image_size( 'swell-featured-small', 640, 640, true ); // Small Featured Image.
// Post Formats.
add_theme_support( 'post-formats', array(
'gallery',
'link',
'image',
'audio',
'status',
'quote',
'video',
)
);
// Create Menus.
register_nav_menus( array(
'fixed-menu' => esc_html__( 'Fixed Menu', 'organic-swell' ),
'main-menu' => esc_html__( 'Main Menu', 'organic-swell' ),
'social-menu' => esc_html__( 'Social Menu', 'organic-swell' ),
));
// Custom Header.
register_default_headers( array(
'default' => array(
'url' => get_template_directory_uri() . '/images/default-header.jpg',
'thumbnail_url' => get_template_directory_uri() . '/images/default-header.jpg',
'description' => esc_html__( 'Default Custom Header', 'organic-swell' ),
),
));
$defaults = array(
'width' => 1800,
'height' => 480,
'flex-height' => true,
'flex-width' => true,
'default-text-color' => 'ffffff',
'default-image' => get_template_directory_uri() . '/images/default-header.jpg',
'header-text' => false,
'uploads' => true,
);
add_theme_support( 'custom-header', $defaults );
// Custom Background.
$defaults = array(
'default-color' => 'eeeeee',
);
add_theme_support( 'custom-background', $defaults );
}
endif; // swell_setup
add_action( 'after_setup_theme', 'swell_setup' );
/*
-------------------------------------------------------------------------------------------------------
Theme Updater
-------------------------------------------------------------------------------------------------------
*/
function swell_theme_updater() {
require( get_template_directory() . '/updater/theme-updater.php' );
}
add_action( 'after_setup_theme', 'swell_theme_updater' );
/*
-------------------------------------------------------------------------------------------------------
Category ID to Name
-------------------------------------------------------------------------------------------------------
*/
function swell_cat_id_to_name( $id ) {
$cat = get_category( $id );
if ( is_wp_error( $cat ) ) {
return false; }
return $cat->cat_name;
}
/*
-------------------------------------------------------------------------------------------------------
Register Scripts
-------------------------------------------------------------------------------------------------------
*/
if ( ! function_exists( 'swell_enqueue_scripts' ) ) {
function swell_enqueue_scripts() {
// Enqueue Styles.
wp_enqueue_style( 'swell-style', get_stylesheet_uri() );
wp_enqueue_style( 'swell-style-mobile', get_template_directory_uri() . '/css/style-mobile.css', array( 'swell-style' ), '1.0' );
// Resgister Scripts.
wp_register_script( 'swell-fitvids', get_template_directory_uri() . '/js/jquery.fitvids.js', array( 'jquery' ), '20130729' );
wp_register_script( 'swell-hover', get_template_directory_uri() . '/js/hoverIntent.js', array( 'jquery' ), '20130729' );
wp_register_script( 'swell-superfish', get_template_directory_uri() . '/js/superfish.js', array( 'jquery', 'swell-hover' ), '20130729' );
// Enqueue Scripts.
wp_enqueue_script( 'swell-custom', get_template_directory_uri() . '/js/jquery.custom.js', array( 'jquery', 'swell-superfish', 'swell-fitvids', 'masonry' ), '20130729', true );
wp_enqueue_script( 'swell-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20130729', true );
// Load Flexslider on front page and slideshow page template.
if ( is_home() || is_front_page() || is_single() || is_page_template( 'template-slideshow.php' ) || is_page_template( 'template-featured-content.php' ) ) {
wp_enqueue_script( 'swell-flexslider', get_template_directory_uri() . '/js/jquery.flexslider.js', array( 'jquery' ), '20130729' );
}
// Load single scripts only on single pages.
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
}
add_action( 'wp_enqueue_scripts', 'swell_enqueue_scripts' );
/*
-------------------------------------------------------------------------------------------------------
Register Sidebars
-------------------------------------------------------------------------------------------------------
*/
function swell_widgets_init() {
register_sidebar(array(
'name' => esc_html__( 'Default Sidebar', 'organic-swell' ),
'id' => 'default-sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h6 class="title">',
'after_title' => '</h6>',
));
register_sidebar(array(
'name' => esc_html__( 'Blog Sidebar', 'organic-swell' ),
'id' => 'blog-sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h6 class="title">',
'after_title' => '</h6>',
));
register_sidebar(array(
'name' => esc_html__( 'Left Sidebar', 'organic-swell' ),
'id' => 'left-sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h6 class="title">',
'after_title' => '</h6>',
));
register_sidebar(array(
'name' => esc_html__( 'Footer Widgets', 'organic-swell' ),
'id' => 'footer',
'before_widget' => '<div id="%1$s" class="widget %2$s"><div class="footer-widget">',
'after_widget' => '</div></div>',
'before_title' => '<h6 class="title">',
'after_title' => '</h6>',
));
}
add_action( 'widgets_init', 'swell_widgets_init' );
/*
-------------------------------------------------------------------------------------------------------
Add Stylesheet To Visual Editor
-------------------------------------------------------------------------------------------------------
*/
add_action( 'widgets_init', 'swell_add_editor_styles' );
/**
* Apply theme's stylesheet to the visual editor.
*
* @uses add_editor_style() Links a stylesheet to visual editor
* @uses get_stylesheet_uri() Returns URI of theme stylesheet
*/
function swell_add_editor_styles() {
add_editor_style( 'css/style-editor.css' );
}
/*
-------------------------------------------------------------------------------------------------------
Posted On Function
-------------------------------------------------------------------------------------------------------
*/
function swell_posted_on() {
if ( get_the_modified_time() != get_the_time() ) {
printf( __( '<span class="%1$s">Last Updated:</span> %2$s', 'organic-swell' ),
'meta-prep meta-prep-author',
sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
esc_url( get_permalink() ),
esc_attr( get_the_modified_time() ),
get_the_modified_date()
)
);
} else {
printf( __( '<span class="%1$s">Posted:</span> %2$s', 'organic-swell' ),
'meta-prep meta-prep-author',
sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
get_the_date()
)
);
}
}
/*
-------------------------------------------------------------------------------------------------------
Post Format Meta Boxes
-------------------------------------------------------------------------------------------------------
*/
add_action( 'admin_init', 'create_metaboxes' );
add_action( 'save_post', 'save_metaboxes' );
$metaboxes = array(
'link_url' => array(
'title' => esc_html__( 'Link Information', 'organic-swell' ),
'applicableto' => 'post',
'location' => 'side',
'display_condition' => 'post-format-link',
'priority' => 'default',
'fields' => array(
'l_url' => array(
'title' => esc_html__( 'Link URL: ', 'organic-swell' ),
'type' => 'text',
'description' => '',
'size' => 20,
),
),
),
'quote_author' => array(
'title' => esc_html__( 'Quote Author', 'organic-swell' ),
'applicableto' => 'post',
'location' => 'side',
'display_condition' => 'post-format-quote',
'priority' => 'default',
'fields' => array(
'q_author' => array(
'title' => esc_html__( 'Author: ', 'organic-swell' ),
'type' => 'text',
'description' => '',
'size' => 20,
),
),
),
);
function create_metaboxes() {
global $metaboxes;
if ( ! empty( $metaboxes ) ) {
foreach ( $metaboxes as $id => $metabox ) {
add_meta_box( $id, $metabox['title'], 'show_metaboxes', $metabox['applicableto'], $metabox['location'], $metabox['priority'], $id );
}
}
}
function show_metaboxes( $post, $args ) {
global $metaboxes;
$custom = get_post_custom( $post->ID );
$fields = $tabs = $metaboxes[ $args['id'] ]['fields'];
/** Nonce */
$output = '<input type="hidden" name="post_format_meta_box_nonce" value="' . wp_create_nonce( basename( __FILE__ ) ) . '" />';
if ( sizeof( $fields ) ) {
foreach ( $fields as $id => $field ) {
switch ( $field['type'] ) {
default:
case 'text':
if ( isset( $custom[ $id ] ) ) {
$output .= '<label for="' . esc_attr( $id ) . '">' . $field['title'] . '</label><input id="' . esc_attr( $id ) . '" type="text" name="' . esc_attr( $id ) . '" value="' . $custom[ $id ][0] . '" size="' . $field['size'] . '" />';
} else {
$output .= '<label for="' . esc_attr( $id ) . '">' . $field['title'] . '</label><input id="' . esc_attr( $id ) . '" type="text" name="' . esc_attr( $id ) . '" value="" size="' . $field['size'] . '" />';
}
break;
}
}
}
echo $output;
}
function save_metaboxes( $post_id ) {
global $metaboxes;
// Verify nonce.
if ( isset( $_POST['post_format_meta_box_nonce'] ) && ! wp_verify_nonce( $_POST['post_format_meta_box_nonce'], basename( __FILE__ ) ) ) {
return $post_id; }
// Check autosave.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id; }
// Check permissions.
if ( 'page' == isset( $_POST['post_type'] ) ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return $post_id; }
} elseif ( ! current_user_can( 'edit_post', $post_id ) ) {
return $post_id;
}
$post_type = get_post_type();
// Loop through fields and save the data.
foreach ( $metaboxes as $id => $metabox ) {
// Check if metabox is applicable for current post type.
if ( $metabox['applicableto'] == $post_type ) {
$fields = $metaboxes[ $id ]['fields'];
foreach ( $fields as $id => $field ) {
$old = get_post_meta( $post_id, $id, true );
$new = $_POST[ $id ];
if ( $new && $new != $old ) {
update_post_meta( $post_id, $id, $new );
} elseif ( '' == $new && $old || ! isset( $_POST[ $id ] ) ) {
delete_post_meta( $post_id, $id, $old );
}
}
}
}
}
add_action( 'admin_print_scripts', 'display_metaboxes', 1000 );
function display_metaboxes() {
global $metaboxes;
if ( get_post_type() == 'post' ) :
?>
<script type="text/javascript"> // <![CDATA[
$ = jQuery;
<?php
$formats = $ids = array();
foreach ( $metaboxes as $id => $metabox ) {
array_push( $formats, "'" . $metabox['display_condition'] . "': '" . $id . "'" );
array_push( $ids, '#' . $id );
}
?>
var formats = { <?php echo implode( ',', $formats );?> };
var ids = "<?php echo implode( ',', $ids ); ?>";
function displayMetaboxes() {
// Hide all post format metaboxes.
$(ids).hide();
// Get current post format.
var selectedElt = $("input[name='post_format']:checked").attr("id");
// If exists, fade in current post format metabox.
if ( formats[selectedElt] )
$("#" + formats[selectedElt]).fadeIn();
}
$(function() {
// Show/hide metaboxes on page load
displayMetaboxes();
// Show/hide metaboxes on change event
$("input[name='post_format']").change(function() {
displayMetaboxes();
});
});
// ]]></script>
<?php
endif;
}
/*
-------------------------------------------------------------------------------------------------------
Content Width
-------------------------------------------------------------------------------------------------------
*/
if ( ! isset( $content_width ) ) {
$content_width = 640; }
/**
* Adjust content_width value based on the presence of widgets
*/
function swell_content_width() {
if ( ! is_active_sidebar( 'post-sidebar' ) || is_active_sidebar( 'page-sidebar' ) || is_active_sidebar( 'blog-sidebar' ) ) {
global $content_width;
$content_width = 960;
}
}
add_action( 'template_redirect', 'swell_content_width' );
/*
-------------------------------------------------------------------------------------------------------
Comments Function
-------------------------------------------------------------------------------------------------------
*/
if ( ! function_exists( 'swell_comment' ) ) :
function swell_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case 'pingback' :
case 'trackback' :
?>
<li class="post pingback">
<p><?php esc_html_e( 'Pingback:', 'organic-swell' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( esc_html__( 'Edit', 'organic-swell' ), '<span class="edit-link">', '</span>' ); ?></p>
<?php
break;
default :
?>
<li <?php comment_class(); ?> id="<?php echo esc_attr( 'li-comment-' . get_comment_ID() ); ?>">
<article id="<?php echo esc_attr( 'comment-' . get_comment_ID() ); ?>" class="comment">
<footer class="comment-meta">
<div class="comment-author vcard">
<?php
$avatar_size = 72;
if ( '0' != $comment->comment_parent ) {
$avatar_size = 48; }
echo get_avatar( $comment, $avatar_size );
/* translators: 1: comment author, 2: date and time */
printf( __( '%1$s <br/> %2$s <br/>', 'organic-swell' ),
sprintf( '<span class="fn">%s</span>', wp_kses_post( get_comment_author_link() ) ),
sprintf( '<a href="%1$s"><time pubdate datetime="%2$s">%3$s</time></a>',
esc_url( get_comment_link( $comment->comment_ID ) ),
get_comment_time( 'c' ),
/* translators: 1: date, 2: time */
sprintf( __( '%1$s', 'organic-swell' ), get_comment_date(), get_comment_time() )
)
);
?>
</div><!-- .comment-author .vcard -->
</footer>
<div class="comment-content">
<?php if ( $comment->comment_approved == '0' ) : ?>
<em class="comment-awaiting-moderation"><?php esc_html_e( 'Your comment is awaiting moderation.', 'organic-swell' ); ?></em>
<br />
<?php endif; ?>
<?php comment_text(); ?>
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'reply_text' => esc_html__( 'Reply', 'organic-swell' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div><!-- .reply -->
<?php edit_comment_link( esc_html__( 'Edit', 'organic-swell' ), '<span class="edit-link">', '</span>' ); ?>
</div>
</article><!-- #comment-## -->
<?php
break;
endswitch;
}
endif; // Ends check for swell_comment().
/*
-------------------------------------------------------------------------------------------------------
Disable Comments On Pages Default
-------------------------------------------------------------------------------------------------------
*/
function swell_default_comments_off( $data ) {
if ( $data['post_type'] == 'page' && $data['post_status'] == 'auto-draft' ) {
$data['comment_status'] = 0;
}
return $data;
}
add_filter( 'wp_insert_post_data', 'swell_default_comments_off' );
/*
-------------------------------------------------------------------------------------------------------
Custom Excerpt Length
-------------------------------------------------------------------------------------------------------
*/
function swell_excerpt_length( $length ) {
return 38;
}
add_filter( 'excerpt_length', 'swell_excerpt_length', 999 );
function swell_excerpt_more( $more ) {
return '... <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">'. esc_html__( 'Read More', 'organic-swell' ) .'</a>';
}
add_filter( 'excerpt_more', 'swell_excerpt_more' );
/*
-------------------------------------------------------------------------------------------------------
Add Excerpt To Pages
-------------------------------------------------------------------------------------------------------
*/
add_action( 'widgets_init', 'swell_add_excerpts_to_pages' );
function swell_add_excerpts_to_pages() {
add_post_type_support( 'page', 'excerpt' );
}
/*
-------------------------------------------------------------------------------------------------------
Custom Page Links
-------------------------------------------------------------------------------------------------------
*/
function swell_wp_link_pages_args_prevnext_add( $args ) {
global $page, $numpages, $more, $pagenow;
if ( ! $args['next_or_number'] == 'next_and_number' ) {
return $args; }
$args['next_or_number'] = 'number'; // Keep numbering for the main part
if ( ! $more ) {
return $args; }
if ( $page -1 ) { // There is a previous page
$args['before'] .= _wp_link_page( $page -1 )
. $args['link_before']. $args['previouspagelink'] . $args['link_after'] . '</a>'; }
if ( $page < $numpages ) { // There is a next page
$args['after'] = _wp_link_page( $page + 1 )
. $args['link_before'] . $args['nextpagelink'] . $args['link_after'] . '</a>'
. $args['after']; }
return $args;
}
add_filter( 'wp_link_pages_args', 'swell_wp_link_pages_args_prevnext_add' );
/*
-------------------------------------------------------------------------------------------------------
Featured Video Meta Box
-------------------------------------------------------------------------------------------------------
*/
add_action( 'admin_init', 'admin_init_featurevid' );
add_action( 'save_post', 'save_featurevid' );
function admin_init_featurevid() {
add_meta_box( 'featurevid-meta', esc_html__( 'Featured Video Embed Code', 'organic-swell' ), 'meta_options_featurevid', 'post', 'normal', 'high' );
}
function meta_options_featurevid() {
global $post;
$custom = get_post_custom( $post->ID );
$featurevid = isset( $custom['featurevid'] ) ? esc_attr( $custom['featurevid'][0] ) : '';
echo '<textarea name="featurevid" cols="60" rows="4" style="width:97.6%" />'.$featurevid.'</textarea>';
}
function save_featurevid( $post_id ) {
global $post;
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
if ( isset( $_POST['featurevid'] ) ) {
update_post_meta( $post->ID, 'featurevid', $_POST['featurevid'] );
}
}
/*
-------------------------------------------------------------------------------------------------------
Remove First Gallery
-------------------------------------------------------------------------------------------------------
*/
function swell_remove_gallery( $content ) {
if ( is_page_template( 'template-slideshow.php' ) || has_post_format( 'gallery' ) || ( is_singular( 'jetpack-portfolio' ) && get_theme_mod( 'display_project_slideshow', false ) ) ) {
$content = preg_replace( '/\[gallery(.*?)ids=[^\]]+\]/', '', $content, 1 );
}
return $content;
}
add_filter( 'the_content', 'swell_remove_gallery' );
/*
-------------------------------------------------------------------------------------------------------
Home Link In Custom Menu
-------------------------------------------------------------------------------------------------------
*/
function home_page_menu_args( $args ) {
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'home_page_menu_args' );
/*
-------------------------------------------------------------------------------------------------------
Body Class
-------------------------------------------------------------------------------------------------------
*/
function swell_body_class( $classes ) {
if ( is_singular() ) {
$classes[] = 'swell-singular'; }
if ( is_active_sidebar( 'right-sidebar' ) ) {
$classes[] = 'swell-right-sidebar'; }
if ( '' != get_theme_mod( 'background_image' ) ) {
// This class will render when a background image is set
// regardless of whether the user has set a color as well.
$classes[] = 'swell-background-image';
} else if ( ! in_array( get_background_color(), array( '', get_theme_support( 'custom-background', 'default-color' ) ) ) ) {
// This class will render when a background color is set
// but no image is set. In the case the content text will
// Adjust relative to the background color.
$classes[] = 'swell-relative-text';
}
return $classes;
}
add_action( 'body_class', 'swell_body_class' );
/*
-------------------------------------------------------------------------------------------------------
Includes
-------------------------------------------------------------------------------------------------------
*/
require_once( get_template_directory() . '/includes/jetpack.php' );
require_once( get_template_directory() . '/includes/customizer.php' );
require_once( get_template_directory() . '/includes/typefaces.php' );
require_once( get_template_directory() . '/includes/woocommerce-setup.php' );
require_once( get_template_directory() . '/includes/plugin-activation.php' );
require_once( get_template_directory() . '/includes/plugin-activation-class.php' );
更改此行
if ( get_the_modified_time() != get_the_time() ) {
至
if ( get_the_modified_time() != get_the_time() && false ) {
我有一个博客的主题,我正在尝试修改它,所以每次我编辑它时它总是显示 "published date" 而不是 "Edited on"...
我已将它钉在文件中 -> functions.php 显示日期的地方... "Posted On Function"
部分但每次我尝试修改 if/else 时,我都会在页面上收到错误 500 :-(
在此非常感谢您的帮助...
提前致谢!
-最好的问候
我怀疑的部分是原因:
-------------------------------------------------------------------------------------------------------
Posted On Function
-------------------------------------------------------------------------------------------------------
*/
function swell_posted_on() {
if ( get_the_modified_time() != get_the_time() ) {
printf( __( '<span class="%1$s">Last Updated:</span> %2$s', 'organic-swell' ),
'meta-prep meta-prep-author',
sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
esc_url( get_permalink() ),
esc_attr( get_the_modified_time() ),
get_the_modified_date()
)
);
} else {
printf( __( '<span class="%1$s">Posted:</span> %2$s', 'organic-swell' ),
'meta-prep meta-prep-author',
sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
get_the_date()
)
);
}
}
/*
这是整个 functions.php 文件:
/*
-------------------------------------------------------------------------------------------------------
Theme Setup
-------------------------------------------------------------------------------------------------------
*/
if ( ! function_exists( 'swell_setup' ) ) :
function swell_setup() {
// Make theme available for translation.
load_theme_textdomain( 'organic-swell', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
// Enable support for Post Thumbnails.
add_theme_support( 'post-thumbnails' );
// Enable support for site title tag.
add_theme_support( 'title-tag' );
add_image_size( 'swell-featured-large', 1800, 1200, true ); // Large Featured Image.
add_image_size( 'swell-featured-medium', 1200, 800, true ); // Medium Featured Image.
add_image_size( 'swell-featured-small', 640, 640, true ); // Small Featured Image.
// Post Formats.
add_theme_support( 'post-formats', array(
'gallery',
'link',
'image',
'audio',
'status',
'quote',
'video',
)
);
// Create Menus.
register_nav_menus( array(
'fixed-menu' => esc_html__( 'Fixed Menu', 'organic-swell' ),
'main-menu' => esc_html__( 'Main Menu', 'organic-swell' ),
'social-menu' => esc_html__( 'Social Menu', 'organic-swell' ),
));
// Custom Header.
register_default_headers( array(
'default' => array(
'url' => get_template_directory_uri() . '/images/default-header.jpg',
'thumbnail_url' => get_template_directory_uri() . '/images/default-header.jpg',
'description' => esc_html__( 'Default Custom Header', 'organic-swell' ),
),
));
$defaults = array(
'width' => 1800,
'height' => 480,
'flex-height' => true,
'flex-width' => true,
'default-text-color' => 'ffffff',
'default-image' => get_template_directory_uri() . '/images/default-header.jpg',
'header-text' => false,
'uploads' => true,
);
add_theme_support( 'custom-header', $defaults );
// Custom Background.
$defaults = array(
'default-color' => 'eeeeee',
);
add_theme_support( 'custom-background', $defaults );
}
endif; // swell_setup
add_action( 'after_setup_theme', 'swell_setup' );
/*
-------------------------------------------------------------------------------------------------------
Theme Updater
-------------------------------------------------------------------------------------------------------
*/
function swell_theme_updater() {
require( get_template_directory() . '/updater/theme-updater.php' );
}
add_action( 'after_setup_theme', 'swell_theme_updater' );
/*
-------------------------------------------------------------------------------------------------------
Category ID to Name
-------------------------------------------------------------------------------------------------------
*/
function swell_cat_id_to_name( $id ) {
$cat = get_category( $id );
if ( is_wp_error( $cat ) ) {
return false; }
return $cat->cat_name;
}
/*
-------------------------------------------------------------------------------------------------------
Register Scripts
-------------------------------------------------------------------------------------------------------
*/
if ( ! function_exists( 'swell_enqueue_scripts' ) ) {
function swell_enqueue_scripts() {
// Enqueue Styles.
wp_enqueue_style( 'swell-style', get_stylesheet_uri() );
wp_enqueue_style( 'swell-style-mobile', get_template_directory_uri() . '/css/style-mobile.css', array( 'swell-style' ), '1.0' );
// Resgister Scripts.
wp_register_script( 'swell-fitvids', get_template_directory_uri() . '/js/jquery.fitvids.js', array( 'jquery' ), '20130729' );
wp_register_script( 'swell-hover', get_template_directory_uri() . '/js/hoverIntent.js', array( 'jquery' ), '20130729' );
wp_register_script( 'swell-superfish', get_template_directory_uri() . '/js/superfish.js', array( 'jquery', 'swell-hover' ), '20130729' );
// Enqueue Scripts.
wp_enqueue_script( 'swell-custom', get_template_directory_uri() . '/js/jquery.custom.js', array( 'jquery', 'swell-superfish', 'swell-fitvids', 'masonry' ), '20130729', true );
wp_enqueue_script( 'swell-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20130729', true );
// Load Flexslider on front page and slideshow page template.
if ( is_home() || is_front_page() || is_single() || is_page_template( 'template-slideshow.php' ) || is_page_template( 'template-featured-content.php' ) ) {
wp_enqueue_script( 'swell-flexslider', get_template_directory_uri() . '/js/jquery.flexslider.js', array( 'jquery' ), '20130729' );
}
// Load single scripts only on single pages.
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
}
add_action( 'wp_enqueue_scripts', 'swell_enqueue_scripts' );
/*
-------------------------------------------------------------------------------------------------------
Register Sidebars
-------------------------------------------------------------------------------------------------------
*/
function swell_widgets_init() {
register_sidebar(array(
'name' => esc_html__( 'Default Sidebar', 'organic-swell' ),
'id' => 'default-sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h6 class="title">',
'after_title' => '</h6>',
));
register_sidebar(array(
'name' => esc_html__( 'Blog Sidebar', 'organic-swell' ),
'id' => 'blog-sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h6 class="title">',
'after_title' => '</h6>',
));
register_sidebar(array(
'name' => esc_html__( 'Left Sidebar', 'organic-swell' ),
'id' => 'left-sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h6 class="title">',
'after_title' => '</h6>',
));
register_sidebar(array(
'name' => esc_html__( 'Footer Widgets', 'organic-swell' ),
'id' => 'footer',
'before_widget' => '<div id="%1$s" class="widget %2$s"><div class="footer-widget">',
'after_widget' => '</div></div>',
'before_title' => '<h6 class="title">',
'after_title' => '</h6>',
));
}
add_action( 'widgets_init', 'swell_widgets_init' );
/*
-------------------------------------------------------------------------------------------------------
Add Stylesheet To Visual Editor
-------------------------------------------------------------------------------------------------------
*/
add_action( 'widgets_init', 'swell_add_editor_styles' );
/**
* Apply theme's stylesheet to the visual editor.
*
* @uses add_editor_style() Links a stylesheet to visual editor
* @uses get_stylesheet_uri() Returns URI of theme stylesheet
*/
function swell_add_editor_styles() {
add_editor_style( 'css/style-editor.css' );
}
/*
-------------------------------------------------------------------------------------------------------
Posted On Function
-------------------------------------------------------------------------------------------------------
*/
function swell_posted_on() {
if ( get_the_modified_time() != get_the_time() ) {
printf( __( '<span class="%1$s">Last Updated:</span> %2$s', 'organic-swell' ),
'meta-prep meta-prep-author',
sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
esc_url( get_permalink() ),
esc_attr( get_the_modified_time() ),
get_the_modified_date()
)
);
} else {
printf( __( '<span class="%1$s">Posted:</span> %2$s', 'organic-swell' ),
'meta-prep meta-prep-author',
sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
get_the_date()
)
);
}
}
/*
-------------------------------------------------------------------------------------------------------
Post Format Meta Boxes
-------------------------------------------------------------------------------------------------------
*/
add_action( 'admin_init', 'create_metaboxes' );
add_action( 'save_post', 'save_metaboxes' );
$metaboxes = array(
'link_url' => array(
'title' => esc_html__( 'Link Information', 'organic-swell' ),
'applicableto' => 'post',
'location' => 'side',
'display_condition' => 'post-format-link',
'priority' => 'default',
'fields' => array(
'l_url' => array(
'title' => esc_html__( 'Link URL: ', 'organic-swell' ),
'type' => 'text',
'description' => '',
'size' => 20,
),
),
),
'quote_author' => array(
'title' => esc_html__( 'Quote Author', 'organic-swell' ),
'applicableto' => 'post',
'location' => 'side',
'display_condition' => 'post-format-quote',
'priority' => 'default',
'fields' => array(
'q_author' => array(
'title' => esc_html__( 'Author: ', 'organic-swell' ),
'type' => 'text',
'description' => '',
'size' => 20,
),
),
),
);
function create_metaboxes() {
global $metaboxes;
if ( ! empty( $metaboxes ) ) {
foreach ( $metaboxes as $id => $metabox ) {
add_meta_box( $id, $metabox['title'], 'show_metaboxes', $metabox['applicableto'], $metabox['location'], $metabox['priority'], $id );
}
}
}
function show_metaboxes( $post, $args ) {
global $metaboxes;
$custom = get_post_custom( $post->ID );
$fields = $tabs = $metaboxes[ $args['id'] ]['fields'];
/** Nonce */
$output = '<input type="hidden" name="post_format_meta_box_nonce" value="' . wp_create_nonce( basename( __FILE__ ) ) . '" />';
if ( sizeof( $fields ) ) {
foreach ( $fields as $id => $field ) {
switch ( $field['type'] ) {
default:
case 'text':
if ( isset( $custom[ $id ] ) ) {
$output .= '<label for="' . esc_attr( $id ) . '">' . $field['title'] . '</label><input id="' . esc_attr( $id ) . '" type="text" name="' . esc_attr( $id ) . '" value="' . $custom[ $id ][0] . '" size="' . $field['size'] . '" />';
} else {
$output .= '<label for="' . esc_attr( $id ) . '">' . $field['title'] . '</label><input id="' . esc_attr( $id ) . '" type="text" name="' . esc_attr( $id ) . '" value="" size="' . $field['size'] . '" />';
}
break;
}
}
}
echo $output;
}
function save_metaboxes( $post_id ) {
global $metaboxes;
// Verify nonce.
if ( isset( $_POST['post_format_meta_box_nonce'] ) && ! wp_verify_nonce( $_POST['post_format_meta_box_nonce'], basename( __FILE__ ) ) ) {
return $post_id; }
// Check autosave.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id; }
// Check permissions.
if ( 'page' == isset( $_POST['post_type'] ) ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return $post_id; }
} elseif ( ! current_user_can( 'edit_post', $post_id ) ) {
return $post_id;
}
$post_type = get_post_type();
// Loop through fields and save the data.
foreach ( $metaboxes as $id => $metabox ) {
// Check if metabox is applicable for current post type.
if ( $metabox['applicableto'] == $post_type ) {
$fields = $metaboxes[ $id ]['fields'];
foreach ( $fields as $id => $field ) {
$old = get_post_meta( $post_id, $id, true );
$new = $_POST[ $id ];
if ( $new && $new != $old ) {
update_post_meta( $post_id, $id, $new );
} elseif ( '' == $new && $old || ! isset( $_POST[ $id ] ) ) {
delete_post_meta( $post_id, $id, $old );
}
}
}
}
}
add_action( 'admin_print_scripts', 'display_metaboxes', 1000 );
function display_metaboxes() {
global $metaboxes;
if ( get_post_type() == 'post' ) :
?>
<script type="text/javascript"> // <![CDATA[
$ = jQuery;
<?php
$formats = $ids = array();
foreach ( $metaboxes as $id => $metabox ) {
array_push( $formats, "'" . $metabox['display_condition'] . "': '" . $id . "'" );
array_push( $ids, '#' . $id );
}
?>
var formats = { <?php echo implode( ',', $formats );?> };
var ids = "<?php echo implode( ',', $ids ); ?>";
function displayMetaboxes() {
// Hide all post format metaboxes.
$(ids).hide();
// Get current post format.
var selectedElt = $("input[name='post_format']:checked").attr("id");
// If exists, fade in current post format metabox.
if ( formats[selectedElt] )
$("#" + formats[selectedElt]).fadeIn();
}
$(function() {
// Show/hide metaboxes on page load
displayMetaboxes();
// Show/hide metaboxes on change event
$("input[name='post_format']").change(function() {
displayMetaboxes();
});
});
// ]]></script>
<?php
endif;
}
/*
-------------------------------------------------------------------------------------------------------
Content Width
-------------------------------------------------------------------------------------------------------
*/
if ( ! isset( $content_width ) ) {
$content_width = 640; }
/**
* Adjust content_width value based on the presence of widgets
*/
function swell_content_width() {
if ( ! is_active_sidebar( 'post-sidebar' ) || is_active_sidebar( 'page-sidebar' ) || is_active_sidebar( 'blog-sidebar' ) ) {
global $content_width;
$content_width = 960;
}
}
add_action( 'template_redirect', 'swell_content_width' );
/*
-------------------------------------------------------------------------------------------------------
Comments Function
-------------------------------------------------------------------------------------------------------
*/
if ( ! function_exists( 'swell_comment' ) ) :
function swell_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case 'pingback' :
case 'trackback' :
?>
<li class="post pingback">
<p><?php esc_html_e( 'Pingback:', 'organic-swell' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( esc_html__( 'Edit', 'organic-swell' ), '<span class="edit-link">', '</span>' ); ?></p>
<?php
break;
default :
?>
<li <?php comment_class(); ?> id="<?php echo esc_attr( 'li-comment-' . get_comment_ID() ); ?>">
<article id="<?php echo esc_attr( 'comment-' . get_comment_ID() ); ?>" class="comment">
<footer class="comment-meta">
<div class="comment-author vcard">
<?php
$avatar_size = 72;
if ( '0' != $comment->comment_parent ) {
$avatar_size = 48; }
echo get_avatar( $comment, $avatar_size );
/* translators: 1: comment author, 2: date and time */
printf( __( '%1$s <br/> %2$s <br/>', 'organic-swell' ),
sprintf( '<span class="fn">%s</span>', wp_kses_post( get_comment_author_link() ) ),
sprintf( '<a href="%1$s"><time pubdate datetime="%2$s">%3$s</time></a>',
esc_url( get_comment_link( $comment->comment_ID ) ),
get_comment_time( 'c' ),
/* translators: 1: date, 2: time */
sprintf( __( '%1$s', 'organic-swell' ), get_comment_date(), get_comment_time() )
)
);
?>
</div><!-- .comment-author .vcard -->
</footer>
<div class="comment-content">
<?php if ( $comment->comment_approved == '0' ) : ?>
<em class="comment-awaiting-moderation"><?php esc_html_e( 'Your comment is awaiting moderation.', 'organic-swell' ); ?></em>
<br />
<?php endif; ?>
<?php comment_text(); ?>
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'reply_text' => esc_html__( 'Reply', 'organic-swell' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div><!-- .reply -->
<?php edit_comment_link( esc_html__( 'Edit', 'organic-swell' ), '<span class="edit-link">', '</span>' ); ?>
</div>
</article><!-- #comment-## -->
<?php
break;
endswitch;
}
endif; // Ends check for swell_comment().
/*
-------------------------------------------------------------------------------------------------------
Disable Comments On Pages Default
-------------------------------------------------------------------------------------------------------
*/
function swell_default_comments_off( $data ) {
if ( $data['post_type'] == 'page' && $data['post_status'] == 'auto-draft' ) {
$data['comment_status'] = 0;
}
return $data;
}
add_filter( 'wp_insert_post_data', 'swell_default_comments_off' );
/*
-------------------------------------------------------------------------------------------------------
Custom Excerpt Length
-------------------------------------------------------------------------------------------------------
*/
function swell_excerpt_length( $length ) {
return 38;
}
add_filter( 'excerpt_length', 'swell_excerpt_length', 999 );
function swell_excerpt_more( $more ) {
return '... <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">'. esc_html__( 'Read More', 'organic-swell' ) .'</a>';
}
add_filter( 'excerpt_more', 'swell_excerpt_more' );
/*
-------------------------------------------------------------------------------------------------------
Add Excerpt To Pages
-------------------------------------------------------------------------------------------------------
*/
add_action( 'widgets_init', 'swell_add_excerpts_to_pages' );
function swell_add_excerpts_to_pages() {
add_post_type_support( 'page', 'excerpt' );
}
/*
-------------------------------------------------------------------------------------------------------
Custom Page Links
-------------------------------------------------------------------------------------------------------
*/
function swell_wp_link_pages_args_prevnext_add( $args ) {
global $page, $numpages, $more, $pagenow;
if ( ! $args['next_or_number'] == 'next_and_number' ) {
return $args; }
$args['next_or_number'] = 'number'; // Keep numbering for the main part
if ( ! $more ) {
return $args; }
if ( $page -1 ) { // There is a previous page
$args['before'] .= _wp_link_page( $page -1 )
. $args['link_before']. $args['previouspagelink'] . $args['link_after'] . '</a>'; }
if ( $page < $numpages ) { // There is a next page
$args['after'] = _wp_link_page( $page + 1 )
. $args['link_before'] . $args['nextpagelink'] . $args['link_after'] . '</a>'
. $args['after']; }
return $args;
}
add_filter( 'wp_link_pages_args', 'swell_wp_link_pages_args_prevnext_add' );
/*
-------------------------------------------------------------------------------------------------------
Featured Video Meta Box
-------------------------------------------------------------------------------------------------------
*/
add_action( 'admin_init', 'admin_init_featurevid' );
add_action( 'save_post', 'save_featurevid' );
function admin_init_featurevid() {
add_meta_box( 'featurevid-meta', esc_html__( 'Featured Video Embed Code', 'organic-swell' ), 'meta_options_featurevid', 'post', 'normal', 'high' );
}
function meta_options_featurevid() {
global $post;
$custom = get_post_custom( $post->ID );
$featurevid = isset( $custom['featurevid'] ) ? esc_attr( $custom['featurevid'][0] ) : '';
echo '<textarea name="featurevid" cols="60" rows="4" style="width:97.6%" />'.$featurevid.'</textarea>';
}
function save_featurevid( $post_id ) {
global $post;
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
if ( isset( $_POST['featurevid'] ) ) {
update_post_meta( $post->ID, 'featurevid', $_POST['featurevid'] );
}
}
/*
-------------------------------------------------------------------------------------------------------
Remove First Gallery
-------------------------------------------------------------------------------------------------------
*/
function swell_remove_gallery( $content ) {
if ( is_page_template( 'template-slideshow.php' ) || has_post_format( 'gallery' ) || ( is_singular( 'jetpack-portfolio' ) && get_theme_mod( 'display_project_slideshow', false ) ) ) {
$content = preg_replace( '/\[gallery(.*?)ids=[^\]]+\]/', '', $content, 1 );
}
return $content;
}
add_filter( 'the_content', 'swell_remove_gallery' );
/*
-------------------------------------------------------------------------------------------------------
Home Link In Custom Menu
-------------------------------------------------------------------------------------------------------
*/
function home_page_menu_args( $args ) {
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'home_page_menu_args' );
/*
-------------------------------------------------------------------------------------------------------
Body Class
-------------------------------------------------------------------------------------------------------
*/
function swell_body_class( $classes ) {
if ( is_singular() ) {
$classes[] = 'swell-singular'; }
if ( is_active_sidebar( 'right-sidebar' ) ) {
$classes[] = 'swell-right-sidebar'; }
if ( '' != get_theme_mod( 'background_image' ) ) {
// This class will render when a background image is set
// regardless of whether the user has set a color as well.
$classes[] = 'swell-background-image';
} else if ( ! in_array( get_background_color(), array( '', get_theme_support( 'custom-background', 'default-color' ) ) ) ) {
// This class will render when a background color is set
// but no image is set. In the case the content text will
// Adjust relative to the background color.
$classes[] = 'swell-relative-text';
}
return $classes;
}
add_action( 'body_class', 'swell_body_class' );
/*
-------------------------------------------------------------------------------------------------------
Includes
-------------------------------------------------------------------------------------------------------
*/
require_once( get_template_directory() . '/includes/jetpack.php' );
require_once( get_template_directory() . '/includes/customizer.php' );
require_once( get_template_directory() . '/includes/typefaces.php' );
require_once( get_template_directory() . '/includes/woocommerce-setup.php' );
require_once( get_template_directory() . '/includes/plugin-activation.php' );
require_once( get_template_directory() . '/includes/plugin-activation-class.php' );
更改此行
if ( get_the_modified_time() != get_the_time() ) {
至
if ( get_the_modified_time() != get_the_time() && false ) {