Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- =======================================================================================
- [style.css]
- =======================================================================================
- /*
- Template Name: News Reporter
- Template URI: http://amanweb.net
- Author: Aman Ullah
- Author URI: http://amanweb.net/aman
- Version: 1.0
- Description: This is News Template.
- */
- .alignnone{float:left}
- .alignleft{float:left;margin-right:15px}
- .alignright{float:right;margin-left:15px}
- .aligncenter{float:center}
- =======================================================================================
- /*----- REPLACE <title> TAG ------*/
- =======================================================================================
- <title><?php bloginfo('name'); ?><?php wp_title(); ?></title>
- DYNAMIC STYLE.CSS
- =======================================================================================
- <link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_url'); ?>" media="screen" />
- =======================================================================================
- /*----- NECESSARY CODES ------*/
- =======================================================================================
- <?php wp_head(); ?>
- <?php wp_footer(); ?>
- <?php bloginfo('name'); ?> [use in <title> tag]
- <?php bloginfo('home'); ?> [use for home menu (eg: logo)]
- <?php echo get_template_directory_uri(); ?>/
- <?php bloginfo('stylesheet_url'); ?>
- <?php bloginfo( 'description' ); ?> [for use the tagline "just another wordpress site"]
- <?php get_header(); ?>
- <?php get_footer(); ?>
- <?php get_sidebar(); ?>
- <?php get_template_part('file_name_without_extension'); ?>
- <?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?>
- <?php echo human_time_diff( get_comment_time('U'), current_time('timestamp') ) . ' ago'; ?>
- <?php the_permalink(); ?>
- <?php the_title(); ?>
- <?php the_content(); ?>
- <?php the_time('M d, Y') ?>
- <?php the_author();?>
- <?php the_excerpt(); ?>
- <?php the_category(', '); ?>
- <?php comments_popup_link('No Comment', '1 Comment', '% Comments'); ?>
- <?php the_ID(); ?>
- =======================================================================================
- [functions.php] /*----- DYNAMIC NAVIGATION MENU ------*/
- =======================================================================================
- add_action('init', 'wpj_register_menu');
- function wpj_register_menu() {
- if (function_exists('register_nav_menu')) {
- register_nav_menu( 'wpj_main_menu', __( 'Main Menu', 'brightpage' ) );
- }
- }
- function wpj_default_menu() {
- echo '<ul id="nav">';
- if ('page' != get_option('show_on_front')) {
- echo '<li><a href="'. home_url() . '/">Home</a></li>';
- }
- wp_list_pages('title_li=');
- echo '</ul>';
- }
- ---------------------------------------------------------------------------------------
- <?php
- if (function_exists('wp_nav_menu')) {
- wp_nav_menu(array('theme_location' => 'wpj_main_menu', 'menu_class' => 'nav pull-right', 'fallback_cb' => 'wpj_default_menu'));
- }
- else {
- wpj_default_menu();
- }
- ?>
- =======================================================================================
- [functions.php] /*----- WORDPRESS JQUERY ------*/
- =======================================================================================
- function wordpress_latest_jquery(){
- wp_enqueue_script('jquery');
- }
- add_action('init', 'wordpress_latest_jquery');
- =======================================================================================
- [functions.php] /*----- REGISTER SIDEBAR ------*/
- =======================================================================================
- function aman_widget_areas() {
- register_sidebar( array(
- 'name' => __( 'Left Menu', 'aman' ),
- 'id' => 'left_sidebar',
- 'before_widget' => '<div class="single_sidebar">',
- 'after_widget' => '</div>',
- 'before_title' => '<h2>',
- 'after_title' => '</h2>',
- ) );
- }
- add_action('widgets_init', 'aman_widget_areas');
- [Sidebar.php]
- -----------
- <?php if ( ! dynamic_sidebar( 'left_sidebar' ) ) : ?>
- your static data
- <?php endif; ?>
- =======================================================================================
- /*----- POST QUERY ------*/
- =======================================================================================
- <?php query_posts('post_type=post&post_status=publish&posts_per_page=10&paged='. get_query_var('paged')); ?>
- <?php $args = array(
- 'posts_per_page' => 5,
- 'offset' => 0,
- 'category' => '',
- 'orderby' => 'post_date',
- 'order' => 'DESC',
- 'include' => '',
- 'exclude' => '',
- 'meta_key' => '',
- 'meta_value' => '',
- 'post_type' => 'post',
- 'post_mime_type' => '',
- 'post_parent' => '',
- 'post_status' => 'publish',
- 'suppress_filters' => true ); ?>
- =======================================================================================
- [index.php] /*----- POST LOOP ------*/
- =======================================================================================
- <?php if(have_posts()):while(have_posts()):the_post(); ?>
- <!-- Your Post content here -->
- <?php endwhile; endif; ?>
- =======================================================================================
- /*----- STANDARD POST QUERY ------*/
- =======================================================================================
- <?php global $post;
- $args = array( 'posts_per_page' => 4, 'post_type'=> 'slider-items', 'category_name' => 'Featured');
- $myposts = get_posts( $args );
- foreach( $myposts as $post ) : setup_postdata($post); ?>
- data here
- <?php endforeach; ?>
- =======================================================================================
- /*----- CUSTOM POST IN MAIN QUERY ------*/
- =======================================================================================
- // Show posts of 'post', 'page' and 'movie' custom post types on home page
- function add_my_post_types_to_query( $query ) {
- if ( is_home() && $query->is_main_query() )
- $query->set( 'post_type', array( 'post', 'page', 'movie' ) );
- return $query;
- }
- add_action( 'pre_get_posts', 'add_my_post_types_to_query' );
- =======================================================================================
- /*----- PAGINATION ------*/
- =======================================================================================
- <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts') ); ?></div>
- <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>') ); ?></div>
- -------------
- <?php global $wp_query;
- $big = 999999999; // need an unlikely integer
- echo paginate_links( array(
- 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
- 'format' => '?paged=%#%',
- 'current' => max( 1, get_query_var('paged') ),
- 'total' => $wp_query->max_num_pages
- ) );
- ?>
- <?php $args = array(
- 'base' => '%_%',
- 'format' => '?page=%#%',
- 'total' => 1,
- 'current' => 0,
- 'show_all' => False,
- 'end_size' => 1,
- 'mid_size' => 2,
- 'prev_next' => True,
- 'prev_text' => __('« Previous'),
- 'next_text' => __('Next »'),
- 'type' => 'plain',
- 'add_args' => False,
- 'add_fragment' => ''
- ); ?>
- =======================================================================================
- [single.php]
- =======================================================================================
- <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
- <h2><?php the_title(); ?></h2>
- <?php the_content(); ?>
- <?php comments_template( '', true ); ?>
- <?php endwhile; else : ?>
- <h3><?php _e('404 Error: Not Found'); ?></h3>
- <?php endif; ?>
- =======================================================================================
- [archive.php]
- =======================================================================================
- <h1>
- <?php if (have_posts()) : ?>
- <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
- <?php /* If this is a category archive */ if (is_category()) { ?>
- <?php _e('Archive for the'); ?> '<?php echo single_cat_title(); ?>' <?php _e('Category'); ?>
- <?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
- <?php _e('Archive for the'); ?> <?php single_tag_title(); ?> Tag
- <?php /* If this is a daily archive */ } elseif (is_day()) { ?>
- <?php _e('Archive for'); ?> <?php the_time('F jS, Y'); ?>
- <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
- <?php _e('Archive for'); ?> <?php the_time('F, Y'); ?>
- <?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
- <?php _e('Archive for'); ?> <?php the_time('Y'); ?>
- <?php /* If this is a search */ } elseif (is_search()) { ?>
- <?php _e('Search Results'); ?>
- <?php /* If this is an author archive */ } elseif (is_author()) { ?>
- <?php _e('Author Archive'); ?>
- <?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
- <?php _e('Blog Archives'); ?>
- <?php } ?>
- </h1>
- <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
- <div class="index_post">
- <a href="<?php the_permalink()?>"><h2><?php the_title()?></h2></a>
- <div class="single_post_item">
- <?php the_content(); ?>
- </div>
- </div>
- <?php endwhile; endif; ?>
- <?php else : ?>
- <h3><?php _e('404 Error: Not Found'); ?></h3>
- <?php endif; ?>
- =======================================================================================
- [404.php]
- =======================================================================================
- <h2>404 Error: Not Found</h2>
- <p>Sorry, but the page you are trying to reach is unavailable or does not exist.</p>
- =======================================================================================
- [functions.php] /*----- FEATURED IMAGE SUPPORT ------*/
- =======================================================================================
- add_theme_support( 'post-thumbnails', array( 'post', 'slider-image' ) );
- add_image_size( 'post-image', 150, 150, true );
- set_post_thumbnail_size( 200, 200, true );
- //calling featured image
- <?php the_post_thumbnail('post_thumb', array('class' => 'post_thumb')); ?>
- <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID ), 'slider-thumb' ); echo $image[0]; ?>
- =======================================================================================
- /*----- POST EXCERPT ------*/
- =======================================================================================
- <p><?php echo wp_trim_words(get_the_content(), 25);?></p>
- functions.php [Read More]
- ---------------------------
- function excerpt($num) {
- $limit = $num+1;
- $excerpt = explode(' ', get_the_excerpt(), $limit);
- array_pop($excerpt);
- $excerpt = "<p>". implode(" ",$excerpt)." </p>"."<a href='" .get_permalink($post->ID) ." ' class='".readmore."'>Read More</a>";
- echo $excerpt;
- }
- use in instead of <?php the_content?> of post-loop.php
- --------------------------------------------------------
- <?php echo excerpt(50); ?>
- =======================================================================================
- [functions.php] /*----- CUSTOM POST REGISTER ------*/
- =======================================================================================
- add_action( 'init', 'create_post_type' );
- function create_post_type() {
- register_post_type( 'testimonial',
- array(
- 'labels' => array(
- 'name' => __( 'Testimonial' ),
- 'singular_name' => __( 'Testimonial' ),
- 'add_new' => __( 'Add New' ),
- 'add_new_item' => __( 'Add New Testimonial' ),
- 'edit_item' => __( 'Edit Testimonial' ),
- 'new_item' => __( 'New Testimonial' ),
- 'view_item' => __( 'View Testimonial' ),
- 'not_found' => __( 'Sorry, we couldn\'t find the Testimonial you are looking for.' )
- ),
- 'public' => true,
- 'publicly_queryable' => true,
- 'exclude_from_search' => true,
- 'menu_position' => 14,
- 'has_archive' => true,
- 'hierarchical' => false,
- 'capability_type' => 'page',
- 'rewrite' => array( 'slug' => 'testimonial' ),
- 'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail' )
- )
- );
- }
- shortform
- add_action( 'init', 'create_post_type' );
- function create_post_type() {
- register_post_type( 'testimonial',
- array(
- 'labels' => array(
- 'name' => __( 'Testimonial' ),
- 'singular_name' => __( 'Testimonial' ),
- 'add_new' => __( 'Add New' ),
- ),
- 'public' => true,
- 'has_archive' => true,
- 'rewrite' => array( 'slug' => 'testimonial' ),
- 'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail' )
- )
- );
- }
- =====================================================================================================
- /*----- REGISTER CUSTOM TAXONOMY ------*/
- =====================================================================================================
- <?php
- function pages_taxonomy() {
- register_taxonomy(
- 'testimonial_cat', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
- 'testimonial', //post type name
- array(
- 'hierarchical' => true,
- 'label' => 'testimonial Category', //Display name
- 'query_var' => true,
- 'show_admin_column' => true,
- 'rewrite' => array(
- 'slug' => 'testimonial-category', // This controls the base slug that will display before each term
- 'with_front' => false // Don't display the category base before
- )
- )
- );
- }
- add_action( 'init', 'pages_taxonomy');
- ?>
- =======================================================================================
- /*----- CUSTOM FIELD ------*/
- =======================================================================================
- Conditional
- -----------
- <?php $c_field = get_post_meta($post->ID, 'icon', true); if($c_field) : ?>
- <?php echo $icon ?>
- <?php else : ?>
- Static Data
- <?php endif; ?>
- Display custom field if exists
- ------------------------------
- <?php $image = get_post_meta($post->ID, 'url', true); if($image) : ?>
- <?php echo $image; ?>
- <?php endif; ?>
- =======================================================================================
- [functions.php] /*----- DYNAMIC BACKGROUND ------*/
- =======================================================================================
- $defaults = array(
- 'default-color' => '#000',
- 'default-image' => '',
- 'wp-head-callback' => '_custom_background_cb',
- 'admin-head-callback' => '',
- 'admin-preview-callback' => ''
- );
- add_theme_support( 'custom-background', $defaults );
- [header.php] replace the <body> tag with
- ---------------------------------------
- <body <?php body_class(); ?>>
- =======================================================================================
- [functions.php] /*----- ACTIVATE OPTION TREE ------*/
- =======================================================================================
- add_filter( 'ot_show_pages', '__return_false' );
- add_filter( 'ot_show_new_layout', '__return_false' );
- add_filter( 'ot_theme_mode', '__return_true' );
- include_once( 'option-tree/ot-loader.php' );
- include_once( 'inc/theme-options.php' );
- include_once( 'inc/meta-boxes.php' );
- GET OPTION TREE DATA
- ---------------------------------------------------------------------------------------
- <?php get_option_tree( 'facebook', '', 'true' ); ?>
- ----------------------------------------------------
- <?php if ( function_exists( 'get_option_tree') ) : if( get_option_tree( 'your_tree_id') ) : ?>
- <?php get_option_tree( 'your_tree_id', '', 'true' ); ?>
- <?php else : ?>
- Your Default Data
- <?php endif; endif; ?>
- =======================================================================================
- [functions.php] /*----- BREADCRUMB ------*/
- =======================================================================================
- function brightpage_the_breadcrumb() {
- if (!is_home()) {
- echo '<a href="';
- echo home_url('home');
- echo '">';
- echo ('Home');
- echo "</a> » ";
- if (is_single()) {
- the_title('');
- if (is_single()) {
- echo "";
- }
- } elseif (is_page()) {
- echo the_title();
- }
- }
- }
- [page.php]
- --------
- <?php brightpage_the_breadcrumb() ?>
- =======================================================================================
- /*----- SMOF THEME OPTIONS FRAMEWORK ------*/
- =======================================================================================
- SMOF activation
- ---------------
- add admin folder into themes root directory
- require_once ('admin/index.php');
- SMOF Options Framework use
- ---------------------------
- single data :
- <?php global $data; echo $data['your_option_id']; ?>
- conditional data :
- <?php global $data; if($data['your_option_id']): ?>
- <?php echo $data['your_option_id']; ?>
- <?php endif; ?>
- conditional data with default data :
- <?php global $data; if($data['your_option_id']): ?>
- <?php echo $data['your_option_id']; ?>
- <?php else: ?>
- My Default data
- <?php endif; ?>
- =====================================================================================================
- /*----- REGISTER CUSTOM TAXONOMY ------*/
- =====================================================================================================
- <?php
- function pages_taxonomy() {
- register_taxonomy(
- 'pages_cat', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
- 'staff', //post type name
- array(
- 'hierarchical' => true,
- 'label' => 'Page Category', //Display name
- 'query_var' => true,
- 'rewrite' => array(
- 'slug' => 'staff-category', // This controls the base slug that will display before each term
- 'with_front' => false // Don't display the category base before
- )
- )
- );
- }
- add_action( 'init', 'pages_taxonomy');
- ?>
- =====================================================================================================
- [funcitons.php] /*----- MOVE FEATURED IMAGES UNDER POST EDITOR IN DASHBOARD ------*/
- =====================================================================================================
- add_action('do_meta_boxes','change_image_box');
- function change_image_box() {
- remove_meta_box('postimagediv', 'gallery-page', 'side');
- add_meta_box('postimagediv', __('Upload Gallery Page Thumbnail.'), 'post_thumbnail_meta_box', 'gallery-page', 'normal', 'high');
- }
- =====================================================================================================
- [funcitons.php] /*----- BLOCK ACCESS IN DASBOARD EXCEPT ADMINISTRATOR ------*/
- =====================================================================================================
- add_action( 'admin_init', 'restrict_admin', 1 );
- function restrict_admin(){
- if ( ! current_user_can( 'manage_options' ) ) {
- wp_die( __('You are not allowed to access this part of the site') );
- }
- }
- =====================================================================================================
- [funcitons.php] /*----- HIDE DASHBOARD FOR ALL EXCEPT ADMINISTRATOR ------*/
- =====================================================================================================
- add_action('after_setup_theme', 'remove_admin_bar');
- function remove_admin_bar() {
- if (!current_user_can('administrator', 'editor') && !is_admin()) {
- show_admin_bar(false);
- }
- }
- =====================================================================================================
- [funcitons.php] /*----- REDIRECT AFTER LOGIN ------*/
- =====================================================================================================
- function redirect_after_login(){
- return admin_url("admin.php?page=functions.php");
- }
- add_filter("login_redirect", "redirect_after_login", 10, 3);
- =====================================================================================================
- [funcitons.php] /*----- REDIRECT AFTER ACTIVATE THEME ------*/
- =====================================================================================================
- global $pagenow;
- if ( is_admin() && isset( $_GET['activated'] ) && $pagenow == 'themes.php' )
- {
- wp_redirect( admin_url( 'admin.php?page=theme-settings-slug' ) );
- exit;
- }
- -------------------------------------------------------------
- if ($_GET['activated']){ wp_redirect(admin_url("admin.php?page=functions.php")); }
- =====================================================================================================
- /*----- GET ONLY TOP LEVEL CATEGORIES AS LISTS ------*/
- =====================================================================================================
- <?php $args = array(
- 'orderby' => 'name',
- 'parent' => 0
- );
- $categories = get_categories( $args );
- foreach ( $categories as $category ) {
- echo '<a href="' . get_category_link( $category->term_id ) . '">' . $category->name . '</a><br/>';
- }
- ?>
- =====================================================================================================
- /*----- SHOW ALL CATEGORIES AS LISTS ------*/
- =====================================================================================================
- <?php
- $category_ID = get_query_var('cat');
- $args = array(
- 'meta_key' => 'price',
- 'orderby' => 'meta_value_num',
- 'order' => 'ASC',
- 'tax_query' => array(
- array(
- 'taxonomy' => 'product-category',
- 'field' => 'slug',
- 'terms' => $slug,
- 'child_of' => $category_ID,
- )
- )
- );
- $categories = get_categories($args);
- foreach($categories as $category) {
- echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
- echo '<p> Description:'. $category->description . '</p>';
- echo '<p> Post Count: '. $category->count . '</p>'; }
- ?>
- =====================================================================================================
- /*----- GET ONLY TOP LEVEL CATEGORIES FROM CUSTOM POST ------*/
- =====================================================================================================
- <?php
- $customPostTaxonomies = get_object_taxonomies('product');
- if(count($customPostTaxonomies) > 0)
- { foreach($customPostTaxonomies as $tax)
- { $args = array(
- 'orderby' => 'name',
- 'show_count' => 0,
- 'pad_counts' => 0,
- 'parent' => 0,
- 'hierarchical' => 1,
- 'taxonomy' => $tax,
- 'title_li' => ''
- );
- wp_list_categories( $args );
- }
- }
- ?>
- =====================================================================================================
- /*----- IS USER LOGGED IN ------*/
- =====================================================================================================
- <?php if(is_user_logged_in()) : ?>
- <a href="<?php echo wp_logout_url( home_url() ); ?>" title="Logout">Logout</a>
- <?php else : ?>
- <a href="<?php echo wp_login_url( home_url() ); ?>" title="Login">Login</a> or <a href="<?php echo wp_registration_url(); ?>" title="Register">Register</a>
- <?php endif; ?>
- =====================================================================================================
- /*----- UPLOAD FLASH FILE (.SWF) IN WORDPRESS ------*/
- =====================================================================================================
- WordPress do not support flash files MIME type. If you still want to upload flash file (.swf) in WordPress then you have to apply a filter in wordpress ‘upload_mimes’
- Just add the bellow filter in your FUNCTIONS.PHP file :
- function demo($mimes) {
- if ( function_exists( 'current_user_can' ) )
- $unfiltered = $user ? user_can( $user, 'unfiltered_html' ) : current_user_can( 'unfiltered_html' );
- if ( !empty( $unfiltered ) ) {
- $mimes['swf'] = 'application/x-shockwave-flash';
- }
- return $mimes;
- }
- add_filter('upload_mimes','demo');
- =====================================================================================================
- /*----- META BOX WITH PLUGIN ------*/
- =====================================================================================================
- /*-------------------------- meta box activate ----------------------------- */
- // put meta-box folder in theme directory
- // Re-define meta box path and URL
- define( 'RWMB_URL', trailingslashit( get_stylesheet_directory_uri() . '/meta-box' ) );
- define( 'RWMB_DIR', trailingslashit( STYLESHEETPATH . '/meta-box' ) );
- // Include the meta box script
- require_once RWMB_DIR . 'meta-box.php';
- /*-------------------------- adding meta box ----------------------------- */
- add_action( 'admin_init', 'rw_register_meta_box' );
- function rw_register_meta_box(){
- // Check if plugin is activated or included in theme
- if ( !class_exists( 'RW_Meta_Box' ) )
- return;
- $prefix = 'rw-';
- $meta_box = array(
- 'id' => 'personal',
- 'title' => 'Personal Information',
- 'pages' => array( 'post', 'page', 'welcome' ),
- 'context' => 'normal',
- 'priority' => 'high',
- 'fields' => array(
- array(
- 'name' => 'Full name',
- 'id' => $prefix . 'calling_id',
- 'type' => 'text',
- 'class' => 'custom-class',
- ),
- )
- );
- new RW_Meta_Box( $meta_box );
- }
- // fetching data in front=end
- <?php echo get_post_meta($post->ID, 'rw-page_editor', true);?>
- help:
- http://www.deluxeblogtips.com/meta-box/
- =====================================================================================================
- /*----- EXCLUDE CATEGORY FROM MAIN POST QUEIRY ------*/
- =====================================================================================================
- function excludeCat($query) {
- if ( $query->is_home ) {
- $query->set('cat', '-3,-5,-23');
- }
- return $query;
- }
- add_filter('pre_get_posts', 'excludeCat');
- =====================================================================================================
- /*----- Attach a navigation menu to the admin bar ------*/
- =====================================================================================================
- add_action( 'admin_bar_menu', 'wpse15186_admin_bar_menu' );
- function wpse15186_admin_bar_menu( &$wp_admin_bar ){
- $menu = wp_get_nav_menu_object( 'WPSE 15186 test menu' );
- $menu_items = wp_get_nav_menu_items( $menu->term_id );
- $wp_admin_bar->add_menu( array(
- 'id' => 'wpse15186-menu-0',
- 'title' => 'WPSE 15186 menu',
- ) );
- foreach ( $menu_items as $menu_item ) {
- $wp_admin_bar->add_menu( array(
- 'id' => 'wpse15186-menu-' . $menu_item->ID,
- 'parent' => 'wpse15186-menu-' . $menu_item->menu_item_parent,
- 'title' => $menu_item->title,
- 'href' => $menu_item->url,
- 'meta' => array(
- 'title' => $menu_item->attr_title,
- 'target' => $menu_item->target,
- 'class' => implode( ' ', $menu_item->classes ),
- ),
- ) );
- }
- }
- =====================================================================================================
- /*----- [FUNCTIONS.PHP] Redirect back to referring page after login ------*/
- =====================================================================================================
- if ( (isset($_GET['action']) && $_GET['action'] != 'logout') || (isset($_POST['login_location']) && !empty($_POST['login_location'])) ) {
- add_filter('login_redirect', 'my_login_redirect', 10, 3);
- function my_login_redirect() {
- $location = $_SERVER['HTTP_REFERER'];
- wp_safe_redirect($location);
- exit();
- }
- }
- =====================================================================================================
- /*----- Add a login link to the wp_nav_menu ------*/
- =====================================================================================================
- add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
- function add_login_logout_link($items, $args) {
- $loginoutlink = wp_loginout('index.php', false);
- $items .= '<li>'. $loginoutlink .'</li>';
- return $items;
- }
- =====================================================================================================
- /*----- How to Display Only Child Category in your WordPress Post Loop ------*/
- =====================================================================================================
- //To display only Child Category in the post loop (mostly single.php), all you have to do is replace the following code:
- <?php the_category(', '); ?>
- //with this code:
- <?php
- foreach((get_the_category()) as $childcat) {
- if (cat_is_ancestor_of(10, $childcat)) {
- echo '<a href="'.get_category_link($childcat->cat_ID).'">';
- echo $childcat->cat_name . '</a>';
- }}
- ?>
- //Remember to change the number 10 to your parent category’s ID.
- =====================================================================================================
- /*----- creating theme customizer ------*/
- =====================================================================================================
- /* creating theme customizer */
- function aman_theme_customizer ($wp_customize){
- $wp_customize->add_section('aman_colors', array(
- 'title' => 'Color',
- 'description' => 'Modify the theme colors',
- ));
- $wp_customize->add_setting('background_colors', array(
- 'default' => '#0f7c01',
- ));
- $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'background_colors', array(
- 'label' => 'Background Color',
- 'section' => 'aman_colors',
- 'settings' => 'background_colors',
- )));
- }
- add_action('customize_register','aman_theme_customizer');
- function aman_theme_custom_css(){
- ?>
- <style type="text/css">
- body { background:<?php echo get_theme_mod('background_colors') ?> }
- </style>
- <?php
- }
- add_action('wp_head', 'aman_theme_custom_css');
- Class list:
- WP_Customize_Control()
- Creates a control that allows users to enter plain text. This is also the parent class for the classes that follow.
- WP_Customize_Color_Control()
- Creates a control that allows users to select a color from a color wheel.
- WP_Customize_Upload_Control()
- Creates a control that allows users to upload media.
- WP_Customize_Image_Control()
- Creates a control that allows users to select or upload an image.
- WP_Customize_Background_Image_Control()
- Creates a control that allows users to select a new background image.
- WP_Customize_Header_Image_Control()
- Creates a control that allows users to select a new header image.
- =====================================================================================================
- /*----- ------*/
- =====================================================================================================
- =====================================================================================================
- /*----- ------*/
- =====================================================================================================
- =====================================================================================================
- /*----- ------*/
- =====================================================================================================
- =====================================================================================================
- /*----- ------*/
- =====================================================================================================
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement