php 示例函数文件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 示例函数文件相关的知识,希望对你有一定的参考价值。
<?php
//* Complete the initial theme setup right after Genesis's setup is complete
add_action('genesis_setup', 'olivia_setup', 15);
function olivia_setup() {
//* Child theme (do not remove)
define( 'CHILD_THEME_NAME', 'olivia' );
define( 'CHILD_THEME_URL', 'http://olivia.codedcreative.co/' );
define( 'CHILD_THEME_VERSION', '1.0.1' );
//* Add custom theme options
include_once( get_stylesheet_directory() . '/theme_customizer.php' );
include_once( get_stylesheet_directory() . '/customizer_styles.php' );
//* Load widget areas
include_once( get_stylesheet_directory() . '/widget-areas.php' );
//* Add HTML5 markup structure
add_theme_support( 'html5', array( '404-page', 'drop-down-menu', 'search-form', 'comment-form', 'comment-list' ) );
//* Add Accessibility support
add_theme_support( 'genesis-accessibility', array( 'headings', 'drop-down-menu', 'search-form', 'skip-links', 'rems' ) );
//* Add viewport meta tag for mobile browsers
add_theme_support( 'genesis-responsive-viewport' );
//* Add support for custom background
add_theme_support( 'custom-background' );
//* Add support for 3-column footer widgets
add_theme_support( 'genesis-footer-widgets', 3 );
//* Add support for custom header
add_theme_support( 'custom-header', array(
'flex-height' => true,
'width' => 430,
'height' => 200,
'header-selector' => '.site-title a',
'header-text' => false,
) );
//* Reposition the primary navigation menu
remove_action( 'genesis_after_header', 'genesis_do_nav' );
add_action( 'genesis_site_title', 'genesis_do_nav' );
//* Remove layouts that use secondary sidebar
genesis_unregister_layout( 'content-sidebar-sidebar' );
genesis_unregister_layout( 'sidebar-content-sidebar' );
genesis_unregister_layout( 'sidebar-sidebar-content' );
//* Unregister secondary navigation menu
add_theme_support( 'genesis-menus', array( 'primary' => __( 'Primary Navigation Menu', 'genesis' ) ) );
//* Remove secondary sidebar
unregister_sidebar( 'sidebar-alt' );
//* Remove the header right widget area
unregister_sidebar( 'header-right' );
//* Add new featured image size for the homepage widget
add_image_size( 'home-latest-posts', 367, 459, TRUE );
add_image_size( 'category_archive', 300, 300, TRUE );
//* Add support for after entry widget area
add_theme_support( 'genesis-after-entry-widget-area' );
}
//* Enqueue Scripts and Styles
add_action( 'wp_enqueue_scripts', 'olivia_enqueue_scripts_styles' );
function olivia_enqueue_scripts_styles() {
wp_enqueue_style( 'dashicons' );
wp_enqueue_style( 'google-fonts', '//fonts.googleapis.com/css?family=Open+Sans:400,700,400italic', array(), CHILD_THEME_VERSION );
wp_enqueue_script( 'olivia-responsive-menu', get_stylesheet_directory_uri() . '/js/responsive-menu.js', array( 'jquery' ), '1.0.0', true );
$output = array(
'mainMenu' => __( 'Menu', 'olivia' ),
'subMenu' => __( 'Menu', 'olivia' ),
);
wp_localize_script( 'olivia-responsive-menu', 'oliviaL10n', $output );
}
//* Enqueue Google Fonts and Font Awesome
add_action( 'wp_enqueue_scripts', 'olivia_google_fonts' );
function olivia_google_fonts() {
wp_enqueue_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css' );
}
//* Hook header CTA widget
add_action( 'genesis_before_content_sidebar_wrap', 'olivia_header_cta_widget_area' );
function olivia_header_cta_widget_area($content) {
// Get button link
$buttonLink = get_theme_mod( "header_button_link", "#" );
$content .= '<div class="header-cta">';
$content .= '<div class="header-cta-container">';
$content .= '<div class="header-headline">' . get_theme_mod( 'header_cta_text', 'Your CTA text goes here' ) . '</div>';
$content .= '<div class="header-secondary-cta">' . get_theme_mod( 'header_secondary_cta_text', 'Your secondary CTA text goes here' ) . '</div>';
$content .= '<div class="button">';
if ( get_theme_mod('header_link_new_tab') ) {
$content .= '<a href="' . $buttonLink . '" target="_blank">' . get_theme_mod( 'header_button_text', 'Your button text' ) . '</a>';
} else {
$content .= '<a href="' . $buttonLink . '">' . get_theme_mod( 'header_button_text', 'Your button text' ) . '</a>';
}
$content .= '</div></div></div>';
echo $content;
}
//* Customize the post info function
add_filter( 'genesis_post_info', 'olivia_post_info_filter' );
function olivia_post_info_filter($post_info) {
if ( !is_page() ) {
$post_info = '[post_date] | [post_categories before=""]';
return $post_info;
}
}
//* Show Comment Date with link but without the time
add_filter( 'genesis_show_comment_date', 'olivia_show_comment_date_with_link' );
function olivia_show_comment_date_with_link( $comment_date ) {
printf('<p %s><time %s>%s</time></p>',
genesis_attr( 'comment-meta' ),
genesis_attr( 'comment-time' ),
esc_html( get_comment_date() )
);
// Return false so that the parent function doesn't output the comment date, time and link
return false;
}
//* Customize theme credits
add_filter( 'genesis_footer_creds_text', 'olivia_footer_creds_text' );
function olivia_footer_creds_text () {
//* Credits
$content = '<div class="creds"><p>'.get_bloginfo( "name" ).' © ';
$content .= date('Y');
$content .= ' | Site By <a href="http://codedcreative.co/">Coded Creative</a>';
//* Terms and policies
if ( get_theme_mod( 'terms_policies_link', "" ) != "" ) {
$content .= '<a href="' . get_theme_mod( 'terms_policies_link', '') . '"> | Terms + Policies</a>';
}
$content .= '</p></div>';
//* Social icons
$content .= '<div class="footer-right social-icons">';
$content .= display_social_icons($c);
$content .= '</div>';
echo $content;
}
//* Customize the next page link
add_filter ( 'genesis_next_link_text' , 'olivia_next_page_link' );
function olivia_next_page_link ( $text ) {
return 'Older Posts <i class="fa fa-angle-double-right"/></i>';
}
//* Customize the previous page link
add_filter ( 'genesis_prev_link_text' , 'olivia_previous_page_link' );
function olivia_previous_page_link ( $text ) {
return '<i class="fa fa-angle-double-left"></i> Newer Posts';
}
//* Hide readmore link
add_filter('excerpt_more', 'olivia_get_read_more_link');
add_filter( 'the_content_more_link', 'olivia_get_read_more_link' );
function olivia_get_read_more_link() {
return '<div class="read-more"><a class="more-link" href="' . get_permalink() . '">Continue Reading</a></div>';
}
function olivia_category_posts_per_page( $query ) {
// do not alter the query on wp-admin pages and only alter it if it's the main query
if (!is_admin() && $query->is_main_query()){
// alter the query for the home and category pages
if(is_category()){
$query->set('posts_per_page', 8);
}
}
}
add_action( 'pre_get_posts', 'olivia_category_posts_per_page' );
//********* WooCommerce **********//
//* Add WooCommerce integration
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
add_action('woocommerce_before_main_content', 'my_theme_wrapper_start', 10);
add_action('woocommerce_after_main_content', 'my_theme_wrapper_end', 10);
function my_theme_wrapper_start() {
echo '<div class="content-sidebar-wrap">';
}
function my_theme_wrapper_end() {
echo '</div>';
}
//* Remove WC integration message
add_action( 'after_setup_theme', 'woocommerce_support' );
function woocommerce_support() {
add_theme_support( 'woocommerce' );
}
// Display 12 products per page
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 12;' ), 20 );
// Change number of products per row to 4
add_filter('loop_shop_columns', 'olivia_loop_columns');
if (!function_exists('olivia_loop_columns')) {
function olivia_loop_columns() {
return 4; // 4 products per row
}
}
// Remove Reviews tab
add_filter( 'woocommerce_product_tabs', 'olivia_woo_remove_reviews_tab', 98);
function olivia_woo_remove_reviews_tab($tabs) {
unset($tabs['reviews']);
return $tabs;
}
//* Change number of related products on single product page
add_filter( 'woocommerce_output_related_products_args', 'olivia_related_products_args' );
function olivia_related_products_args( $args ) {
$args['posts_per_page'] = 4; // 4 related products
$args['columns'] = 4; // arranged in 4 columns
return $args;
}
// Link to plugins
require_once ('includes/social-icons.php');
//* Add WooCommerce Gallery Options
add_action( 'after_setup_theme', 'olivia_woo_gallery' );
function olivia_woo_gallery() {
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
}
以上是关于php 示例函数文件的主要内容,如果未能解决你的问题,请参考以下文章