Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2013
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.66 KB | None | 0 0
  1. <?php
  2.  
  3. /* Bootstrap navigation setup */
  4. add_action( 'after_setup_theme', 'wpt_setup' );
  5.     if ( ! function_exists( 'wpt_setup' ) ):
  6.         function wpt_setup() {  
  7.             register_nav_menu( 'primary', __( 'Primary navigation', 'wptuts' ) );
  8.         } endif;
  9.        
  10.        
  11. function wpt_register_js() {
  12.     wp_register_script('jquery.bootstrap.min', get_template_directory_uri() . '/js/bootstrap.min.js', 'jquery');
  13.     wp_enqueue_script('jquery.bootstrap.min');
  14. }
  15. add_action( 'init', 'wpt_register_js' );
  16. function wpt_register_css() {
  17.     wp_register_style( 'bootstrap.min', get_template_directory_uri() . '/css/bootstrap.min.css' );
  18.     wp_enqueue_style( 'bootstrap.min' );
  19. }
  20. add_action( 'wp_enqueue_scripts', 'wpt_register_css' );
  21.  
  22. require_once('wp_bootstrap_navwalker.php');
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33. if ( ! isset( $content_width ) )
  34.     $content_width = 604;
  35.  
  36. /**
  37.  * Add support for a custom header image.
  38.  */
  39. require get_template_directory() . '/inc/custom-header.php';
  40.  
  41. /**
  42.  * Twenty Thirteen only works in WordPress 3.6 or later.
  43.  */
  44. if ( version_compare( $GLOBALS['wp_version'], '3.6-alpha', '<' ) )
  45.     require get_template_directory() . '/inc/back-compat.php';
  46.  
  47. /**
  48.  * Twenty Thirteen setup.
  49.  *
  50.  * Sets up theme defaults and registers the various WordPress features that
  51.  * Twenty Thirteen supports.
  52.  *
  53.  * @uses load_theme_textdomain() For translation/localization support.
  54.  * @uses add_editor_style() To add Visual Editor stylesheets.
  55.  * @uses add_theme_support() To add support for automatic feed links, post
  56.  * formats, and post thumbnails.
  57.  * @uses register_nav_menu() To add support for a navigation menu.
  58.  * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
  59.  *
  60.  * @since Twenty Thirteen 1.0
  61.  *
  62.  * @return void
  63.  */
  64. function twentythirteen_setup() {
  65.     /*
  66.      * Makes Twenty Thirteen available for translation.
  67.      *
  68.      * Translations can be added to the /languages/ directory.
  69.      * If you're building a theme based on Twenty Thirteen, use a find and
  70.      * replace to change 'twentythirteen' to the name of your theme in all
  71.      * template files.
  72.      */
  73.     load_theme_textdomain( 'twentythirteen', get_template_directory() . '/languages' );
  74.  
  75.     /*
  76.      * This theme styles the visual editor to resemble the theme style,
  77.      * specifically font, colors, icons, and column width.
  78.      */
  79.     add_editor_style( array( 'css/editor-style.css', 'fonts/genericons.css', twentythirteen_fonts_url() ) );
  80.  
  81.     // Adds RSS feed links to <head> for posts and comments.
  82.     add_theme_support( 'automatic-feed-links' );
  83.  
  84.     /*
  85.      * Switches default core markup for search form, comment form,
  86.      * and comments to output valid HTML5.
  87.      */
  88.     add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list' ) );
  89.  
  90.     /*
  91.      * This theme supports all available post formats by default.
  92.      * See http://codex.wordpress.org/Post_Formats
  93.      */
  94.     add_theme_support( 'post-formats', array(
  95.         'aside', 'audio', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video'
  96.     ) );
  97.  
  98.     // This theme uses wp_nav_menu() in one location.
  99.     register_nav_menu( 'primary', __( 'Navigation Menu', 'twentythirteen' ) );
  100.  
  101.     /*
  102.      * This theme uses a custom image size for featured images, displayed on
  103.      * "standard" posts and pages.
  104.      */
  105.     add_theme_support( 'post-thumbnails' );
  106.     set_post_thumbnail_size( 604, 270, true );
  107.  
  108.     // This theme uses its own gallery styles.
  109.     add_filter( 'use_default_gallery_style', '__return_false' );
  110. }
  111. add_action( 'after_setup_theme', 'twentythirteen_setup' );
  112.  
  113. /**
  114.  * Return the Google font stylesheet URL, if available.
  115.  *
  116.  * The use of Source Sans Pro and Bitter by default is localized. For languages
  117.  * that use characters not supported by the font, the font can be disabled.
  118.  *
  119.  * @since Twenty Thirteen 1.0
  120.  *
  121.  * @return string Font stylesheet or empty string if disabled.
  122.  */
  123. function twentythirteen_fonts_url() {
  124.     $fonts_url = '';
  125.  
  126.     /* Translators: If there are characters in your language that are not
  127.      * supported by Source Sans Pro, translate this to 'off'. Do not translate
  128.      * into your own language.
  129.      */
  130.     $source_sans_pro = _x( 'on', 'Source Sans Pro font: on or off', 'twentythirteen' );
  131.  
  132.     /* Translators: If there are characters in your language that are not
  133.      * supported by Bitter, translate this to 'off'. Do not translate into your
  134.      * own language.
  135.      */
  136.     $bitter = _x( 'on', 'Bitter font: on or off', 'twentythirteen' );
  137.  
  138.     if ( 'off' !== $source_sans_pro || 'off' !== $bitter ) {
  139.         $font_families = array();
  140.  
  141.         if ( 'off' !== $source_sans_pro )
  142.             $font_families[] = 'Source Sans Pro:300,400,700,300italic,400italic,700italic';
  143.  
  144.         if ( 'off' !== $bitter )
  145.             $font_families[] = 'Bitter:400,700';
  146.  
  147.         $query_args = array(
  148.             'family' => urlencode( implode( '|', $font_families ) ),
  149.             'subset' => urlencode( 'latin,latin-ext' ),
  150.         );
  151.         $fonts_url = add_query_arg( $query_args, "//fonts.googleapis.com/css" );
  152.     }
  153.  
  154.     return $fonts_url;
  155. }
  156.  
  157. /**
  158.  * Enqueue scripts and styles for the front end.
  159.  *
  160.  * @since Twenty Thirteen 1.0
  161.  *
  162.  * @return void
  163.  */
  164. function twentythirteen_scripts_styles() {
  165.     /*
  166.      * Adds JavaScript to pages with the comment form to support
  167.      * sites with threaded comments (when in use).
  168.      */
  169.     if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
  170.         wp_enqueue_script( 'comment-reply' );
  171.  
  172.     // Adds Masonry to handle vertical alignment of footer widgets.
  173.     if ( is_active_sidebar( 'sidebar-1' ) )
  174.         wp_enqueue_script( 'jquery-masonry' );
  175.  
  176.     // Loads JavaScript file with functionality specific to Twenty Thirteen.
  177.     wp_enqueue_script( 'twentythirteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '2013-07-18', true );
  178.  
  179.     // Add Source Sans Pro and Bitter fonts, used in the main stylesheet.
  180.     wp_enqueue_style( 'twentythirteen-fonts', twentythirteen_fonts_url(), array(), null );
  181.  
  182.     // Add Genericons font, used in the main stylesheet.
  183.     wp_enqueue_style( 'genericons', get_template_directory_uri() . '/fonts/genericons.css', array(), '2.09' );
  184.  
  185.     // Loads our main stylesheet.
  186.     wp_enqueue_style( 'twentythirteen-style', get_stylesheet_uri(), array(), '2013-07-18' );
  187.  
  188.     // Loads the Internet Explorer specific stylesheet.
  189.     wp_enqueue_style( 'twentythirteen-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentythirteen-style' ), '2013-07-18' );
  190.     wp_style_add_data( 'twentythirteen-ie', 'conditional', 'lt IE 9' );
  191. }
  192. add_action( 'wp_enqueue_scripts', 'twentythirteen_scripts_styles' );
  193.  
  194. /**
  195.  * Filter the page title.
  196.  *
  197.  * Creates a nicely formatted and more specific title element text for output
  198.  * in head of document, based on current view.
  199.  *
  200.  * @since Twenty Thirteen 1.0
  201.  *
  202.  * @param string $title Default title text for current view.
  203.  * @param string $sep   Optional separator.
  204.  * @return string The filtered title.
  205.  */
  206. function twentythirteen_wp_title( $title, $sep ) {
  207.     global $paged, $page;
  208.  
  209.     if ( is_feed() )
  210.         return $title;
  211.  
  212.     // Add the site name.
  213.     $title .= get_bloginfo( 'name' );
  214.  
  215.     // Add the site description for the home/front page.
  216.     $site_description = get_bloginfo( 'description', 'display' );
  217.     if ( $site_description && ( is_home() || is_front_page() ) )
  218.         $title = "$title $sep $site_description";
  219.  
  220.     // Add a page number if necessary.
  221.     if ( $paged >= 2 || $page >= 2 )
  222.         $title = "$title $sep " . sprintf( __( 'Page %s', 'twentythirteen' ), max( $paged, $page ) );
  223.  
  224.     return $title;
  225. }
  226. add_filter( 'wp_title', 'twentythirteen_wp_title', 10, 2 );
  227.  
  228. /**
  229.  * Register two widget areas.
  230.  *
  231.  * @since Twenty Thirteen 1.0
  232.  *
  233.  * @return void
  234.  */
  235. function twentythirteen_widgets_init() {
  236.     register_sidebar( array(
  237.         'name'          => __( 'Main Widget Area', 'twentythirteen' ),
  238.         'id'            => 'sidebar-1',
  239.         'description'   => __( 'Appears in the footer section of the site.', 'twentythirteen' ),
  240.         'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  241.         'after_widget'  => '</aside>',
  242.         'before_title'  => '<h3 class="widget-title">',
  243.         'after_title'   => '</h3>',
  244.     ) );
  245.  
  246.     register_sidebar( array(
  247.         'name'          => __( 'Secondary Widget Area', 'twentythirteen' ),
  248.         'id'            => 'sidebar-2',
  249.         'description'   => __( 'Appears on posts and pages in the sidebar.', 'twentythirteen' ),
  250.         'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  251.         'after_widget'  => '</aside>',
  252.         'before_title'  => '<h3 class="widget-title">',
  253.         'after_title'   => '</h3>',
  254.     ) );
  255. }
  256. add_action( 'widgets_init', 'twentythirteen_widgets_init' );
  257.  
  258. if ( ! function_exists( 'twentythirteen_paging_nav' ) ) :
  259. /**
  260.  * Display navigation to next/previous set of posts when applicable.
  261.  *
  262.  * @since Twenty Thirteen 1.0
  263.  *
  264.  * @return void
  265.  */
  266. function twentythirteen_paging_nav() {
  267.     global $wp_query;
  268.  
  269.     // Don't print empty markup if there's only one page.
  270.     if ( $wp_query->max_num_pages < 2 )
  271.         return;
  272.     ?>
  273.     <nav class="navigation paging-navigation" role="navigation">
  274.         <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentythirteen' ); ?></h1>
  275.         <div class="nav-links">
  276.  
  277.             <?php if ( get_next_posts_link() ) : ?>
  278.             <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentythirteen' ) ); ?></div>
  279.             <?php endif; ?>
  280.  
  281.             <?php if ( get_previous_posts_link() ) : ?>
  282.             <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentythirteen' ) ); ?></div>
  283.             <?php endif; ?>
  284.  
  285.         </div><!-- .nav-links -->
  286.     </nav><!-- .navigation -->
  287.     <?php
  288. }
  289. endif;
  290.  
  291. if ( ! function_exists( 'twentythirteen_post_nav' ) ) :
  292. /**
  293.  * Display navigation to next/previous post when applicable.
  294. *
  295. * @since Twenty Thirteen 1.0
  296. *
  297. * @return void
  298. */
  299. function twentythirteen_post_nav() {
  300.     global $post;
  301.  
  302.     // Don't print empty markup if there's nowhere to navigate.
  303.     $previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
  304.     $next     = get_adjacent_post( false, '', false );
  305.  
  306.     if ( ! $next && ! $previous )
  307.         return;
  308.     ?>
  309.     <nav class="navigation post-navigation" role="navigation">
  310.         <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'twentythirteen' ); ?></h1>
  311.         <div class="nav-links">
  312.  
  313.             <?php previous_post_link( '%link', _x( '<span class="meta-nav">&larr;</span> %title', 'Previous post link', 'twentythirteen' ) ); ?>
  314.             <?php next_post_link( '%link', _x( '%title <span class="meta-nav">&rarr;</span>', 'Next post link', 'twentythirteen' ) ); ?>
  315.  
  316.         </div><!-- .nav-links -->
  317.     </nav><!-- .navigation -->
  318.     <?php
  319. }
  320. endif;
  321.  
  322. if ( ! function_exists( 'twentythirteen_entry_meta' ) ) :
  323. /**
  324.  * Print HTML with meta information for current post: categories, tags, permalink, author, and date.
  325.  *
  326.  * Create your own twentythirteen_entry_meta() to override in a child theme.
  327.  *
  328.  * @since Twenty Thirteen 1.0
  329.  *
  330.  * @return void
  331.  */
  332. function twentythirteen_entry_meta() {
  333.     if ( is_sticky() && is_home() && ! is_paged() )
  334.         echo '<span class="featured-post">' . __( 'Sticky', 'twentythirteen' ) . '</span>';
  335.  
  336.     if ( ! has_post_format( 'link' ) && 'post' == get_post_type() )
  337.         twentythirteen_entry_date();
  338.  
  339.     // Translators: used between list items, there is a space after the comma.
  340.     $categories_list = get_the_category_list( __( ', ', 'twentythirteen' ) );
  341.     if ( $categories_list ) {
  342.         echo '<span class="categories-links">' . $categories_list . '</span>';
  343.     }
  344.  
  345.     // Translators: used between list items, there is a space after the comma.
  346.     $tag_list = get_the_tag_list( '', __( ', ', 'twentythirteen' ) );
  347.     if ( $tag_list ) {
  348.         echo '<span class="tags-links">' . $tag_list . '</span>';
  349.     }
  350.  
  351.     // Post author
  352.     if ( 'post' == get_post_type() ) {
  353.         printf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
  354.             esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
  355.             esc_attr( sprintf( __( 'View all posts by %s', 'twentythirteen' ), get_the_author() ) ),
  356.             get_the_author()
  357.         );
  358.     }
  359. }
  360. endif;
  361.  
  362. if ( ! function_exists( 'twentythirteen_entry_date' ) ) :
  363. /**
  364.  * Print HTML with date information for current post.
  365.  *
  366.  * Create your own twentythirteen_entry_date() to override in a child theme.
  367.  *
  368.  * @since Twenty Thirteen 1.0
  369.  *
  370.  * @param boolean $echo (optional) Whether to echo the date. Default true.
  371.  * @return string The HTML-formatted post date.
  372.  */
  373. function twentythirteen_entry_date( $echo = true ) {
  374.     if ( has_post_format( array( 'chat', 'status' ) ) )
  375.         $format_prefix = _x( '%1$s on %2$s', '1: post format name. 2: date', 'twentythirteen' );
  376.     else
  377.         $format_prefix = '%2$s';
  378.  
  379.     $date = sprintf( '<span class="date"><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a></span>',
  380.         esc_url( get_permalink() ),
  381.         esc_attr( sprintf( __( 'Permalink to %s', 'twentythirteen' ), the_title_attribute( 'echo=0' ) ) ),
  382.         esc_attr( get_the_date( 'c' ) ),
  383.         esc_html( sprintf( $format_prefix, get_post_format_string( get_post_format() ), get_the_date() ) )
  384.     );
  385.  
  386.     if ( $echo )
  387.         echo $date;
  388.  
  389.     return $date;
  390. }
  391. endif;
  392.  
  393. if ( ! function_exists( 'twentythirteen_the_attached_image' ) ) :
  394. /**
  395.  * Print the attached image with a link to the next attached image.
  396.  *
  397.  * @since Twenty Thirteen 1.0
  398.  *
  399.  * @return void
  400.  */
  401. function twentythirteen_the_attached_image() {
  402.     /**
  403.      * Filter the image attachment size to use.
  404.      *
  405.      * @since Twenty thirteen 1.0
  406.      *
  407.      * @param array $size {
  408.      *     @type int The attachment height in pixels.
  409.      *     @type int The attachment width in pixels.
  410.      * }
  411.      */
  412.     $attachment_size     = apply_filters( 'twentythirteen_attachment_size', array( 724, 724 ) );
  413.     $next_attachment_url = wp_get_attachment_url();
  414.     $post                = get_post();
  415.  
  416.     /*
  417.      * Grab the IDs of all the image attachments in a gallery so we can get the URL
  418.      * of the next adjacent image in a gallery, or the first image (if we're
  419.      * looking at the last image in a gallery), or, in a gallery of one, just the
  420.      * link to that image file.
  421.      */
  422.     $attachment_ids = get_posts( array(
  423.         'post_parent'    => $post->post_parent,
  424.         'fields'         => 'ids',
  425.         'numberposts'    => -1,
  426.         'post_status'    => 'inherit',
  427.         'post_type'      => 'attachment',
  428.         'post_mime_type' => 'image',
  429.         'order'          => 'ASC',
  430.         'orderby'        => 'menu_order ID'
  431.     ) );
  432.  
  433.     // If there is more than 1 attachment in a gallery...
  434.     if ( count( $attachment_ids ) > 1 ) {
  435.         foreach ( $attachment_ids as $attachment_id ) {
  436.             if ( $attachment_id == $post->ID ) {
  437.                 $next_id = current( $attachment_ids );
  438.                 break;
  439.             }
  440.         }
  441.  
  442.         // get the URL of the next image attachment...
  443.         if ( $next_id )
  444.             $next_attachment_url = get_attachment_link( $next_id );
  445.  
  446.         // or get the URL of the first image attachment.
  447.         else
  448.             $next_attachment_url = get_attachment_link( array_shift( $attachment_ids ) );
  449.     }
  450.  
  451.     printf( '<a href="%1$s" title="%2$s" rel="attachment">%3$s</a>',
  452.         esc_url( $next_attachment_url ),
  453.         the_title_attribute( array( 'echo' => false ) ),
  454.         wp_get_attachment_image( $post->ID, $attachment_size )
  455.     );
  456. }
  457. endif;
  458.  
  459. /**
  460.  * Return the post URL.
  461.  *
  462.  * @uses get_url_in_content() to get the URL in the post meta (if it exists) or
  463.  * the first link found in the post content.
  464.  *
  465.  * Falls back to the post permalink if no URL is found in the post.
  466.  *
  467.  * @since Twenty Thirteen 1.0
  468.  *
  469.  * @return string The Link format URL.
  470.  */
  471. function twentythirteen_get_link_url() {
  472.     $content = get_the_content();
  473.     $has_url = get_url_in_content( $content );
  474.  
  475.     return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() );
  476. }
  477.  
  478. /**
  479.  * Extend the default WordPress body classes.
  480.  *
  481.  * Adds body classes to denote:
  482.  * 1. Single or multiple authors.
  483.  * 2. Active widgets in the sidebar to change the layout and spacing.
  484.  * 3. When avatars are disabled in discussion settings.
  485.  *
  486.  * @since Twenty Thirteen 1.0
  487.  *
  488.  * @param array $classes A list of existing body class values.
  489.  * @return array The filtered body class list.
  490.  */
  491. function twentythirteen_body_class( $classes ) {
  492.     if ( ! is_multi_author() )
  493.         $classes[] = 'single-author';
  494.  
  495.     if ( is_active_sidebar( 'sidebar-2' ) && ! is_attachment() && ! is_404() )
  496.         $classes[] = 'sidebar';
  497.  
  498.     if ( ! get_option( 'show_avatars' ) )
  499.         $classes[] = 'no-avatars';
  500.  
  501.     return $classes;
  502. }
  503. add_filter( 'body_class', 'twentythirteen_body_class' );
  504.  
  505. /**
  506.  * Adjust content_width value for video post formats and attachment templates.
  507.  *
  508.  * @since Twenty Thirteen 1.0
  509.  *
  510.  * @return void
  511.  */
  512. function twentythirteen_content_width() {
  513.     global $content_width;
  514.  
  515.     if ( is_attachment() )
  516.         $content_width = 724;
  517.     elseif ( has_post_format( 'audio' ) )
  518.         $content_width = 484;
  519. }
  520. add_action( 'template_redirect', 'twentythirteen_content_width' );
  521.  
  522. /**
  523.  * Add postMessage support for site title and description for the Customizer.
  524.  *
  525.  * @since Twenty Thirteen 1.0
  526.  *
  527.  * @param WP_Customize_Manager $wp_customize Customizer object.
  528.  * @return void
  529.  */
  530. function twentythirteen_customize_register( $wp_customize ) {
  531.     $wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
  532.     $wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
  533.     $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
  534. }
  535. add_action( 'customize_register', 'twentythirteen_customize_register' );
  536.  
  537. /**
  538.  * Enqueue Javascript postMessage handlers for the Customizer.
  539.  *
  540.  * Binds JavaScript handlers to make the Customizer preview
  541.  * reload changes asynchronously.
  542.  *
  543.  * @since Twenty Thirteen 1.0
  544.  *
  545.  * @return void
  546.  */
  547. function twentythirteen_customize_preview_js() {
  548.     wp_enqueue_script( 'twentythirteen-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20130226', true );
  549. }
  550. add_action( 'customize_preview_init', 'twentythirteen_customize_preview_js' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement