Instantly share code, notes, and snippets.
Created
October 31, 2017 18:22
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save Galibri/0652792a91f943872ed5666d6bdfb219 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//demo link: http://andproductionbd.com/galibweb/about/ | |
//codestar framework codes for custom title and breadcrumb | |
$options[] = array( | |
'id' => '_industry_apbd_global_page_options', | |
'title' => 'Slide Configuration', | |
'post_type' => 'page', | |
'context' => 'normal', | |
'priority' => 'default', | |
'sections' => array( | |
// begin: a section | |
array( | |
'name' => 'page_title', | |
'title' => 'Title Settings', | |
'icon' => 'fa fa-bars', | |
// begin: fields | |
'fields' => array( | |
// begin: a field | |
array( | |
'id' => 'enable_page_title', | |
'type' => 'switcher', | |
'title' => 'Enable Page Title', | |
'default' => 'true', | |
), | |
array( | |
'id' => 'custom_page_title', | |
'type' => 'textarea', | |
'title' => 'Custom Page Title', | |
'default' => false, | |
'dependency' => array( 'enable_page_title', '==', true ), | |
'default' => '', | |
), | |
array( | |
'id' => 'enable_breadcrumb', | |
'type' => 'switcher', | |
'title' => 'Enable Breadcrumb?', | |
'default' => 'true', | |
), | |
), | |
), | |
// begin: a section | |
array( | |
'name' => 'page_title_background_group', | |
'title' => 'Title Background', | |
'icon' => 'fa fa-image', | |
'fields' => array( | |
array( | |
'id' => 'page_title_background', | |
'type' => 'background', | |
'title' => 'Page title background settings', | |
'default' => array( | |
'image' => '', | |
'repeat' => '', | |
'position' => '', | |
'attachment'=> '', | |
'size' => '', | |
'color' => '#000', | |
), | |
), | |
), | |
), | |
// end: a section | |
), | |
); | |
//my custom breadcrumb function | |
if ( ! function_exists( 'the_breadcrumb' ) ) : | |
/** | |
* Breadcrumb function for our theme | |
*/ | |
function the_breadcrumb() { | |
$sep = ' > '; | |
if (!is_front_page()) { | |
// Start the breadcrumb with a link to your homepage | |
echo '<div class="breadcrumbs">'; | |
echo '<a href="'; | |
echo get_option('home'); | |
echo '">'; | |
bloginfo('name'); | |
echo '</a>' . $sep; | |
// Check if the current page is a category, an archive or a single page. If so show the category or archive name. | |
if (is_category() || is_single() ){ | |
the_category('title_li='); | |
} elseif (is_archive() || is_single()){ | |
if ( is_day() ) { | |
printf( __( '%s', 'text_domain' ), get_the_date() ); | |
} elseif ( is_month() ) { | |
printf( __( '%s', 'text_domain' ), get_the_date( _x( 'F Y', 'monthly archives date format', 'text_domain' ) ) ); | |
} elseif ( is_year() ) { | |
printf( __( '%s', 'text_domain' ), get_the_date( _x( 'Y', 'yearly archives date format', 'text_domain' ) ) ); | |
} else { | |
_e( 'Blog Archives', 'text_domain' ); | |
} | |
} | |
// If the current page is a single post, show its title with the separator | |
if (is_single()) { | |
echo $sep; | |
the_title(); | |
} | |
// If the current page is a static page, show its title. | |
if (is_page()) { | |
echo the_title(); | |
} | |
// if you have a static page assigned to be you posts list page. It will find the title of the static page and display it. i.e Home >> Blog | |
if (is_home()){ | |
global $post; | |
$page_for_posts_id = get_option('page_for_posts'); | |
if ( $page_for_posts_id ) { | |
$post = get_page($page_for_posts_id); | |
setup_postdata($post); | |
the_title(); | |
rewind_posts(); | |
} | |
} | |
echo '</div>'; | |
} | |
} | |
endif; | |
//codes inside page.php | |
if(get_post_meta($post->ID, '_industry_apbd_global_page_options', true)){ | |
$page_meta = get_post_meta($post->ID, '_industry_apbd_global_page_options', true); | |
} else{ | |
$page_meta = array(); | |
} | |
if(array_key_exists('enable_page_title', $page_meta)) { | |
$enable_page_title = $page_meta['enable_page_title']; | |
} else{ | |
$enable_page_title = true; | |
} | |
if(array_key_exists('custom_page_title', $page_meta)) { | |
$custom_page_title = trim($page_meta['custom_page_title']); | |
} else{ | |
$custom_page_title = ''; | |
} | |
if(array_key_exists('enable_breadcrumb', $page_meta)) { | |
$enable_breadcrumb = $page_meta['enable_breadcrumb']; | |
} else{ | |
$enable_breadcrumb = 'true'; | |
} | |
if(array_key_exists('page_title_background', $page_meta)) { | |
$page_title_background = $page_meta['page_title_background']; | |
} else{ | |
$page_title_background = '#000'; | |
} | |
get_header(); ?> | |
<?php while(have_posts()) : the_post(); ?> | |
<?php if($enable_page_title == true || $enable_breadcrumb == true) : ?> | |
<div class="page-title-area" style="background-image: url(<?php echo $page_title_background['image'] ?>); background-repeat: <?php echo $page_title_background['repeat'] ?>; background-position: <?php echo $page_title_background['position'] ?>; background-attachment: <?php echo $page_title_background['attachment'] ?>; background-size: <?php echo $page_title_background['size'] ?>; background-color: <?php echo $page_title_background['color'] ?>"> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-md-12"> | |
<?php if($enable_page_title == true) : ?> | |
<?php if(empty($custom_page_title)) : ?> | |
<h3><?php the_title(); ?></h3> | |
<?php else: ?> | |
<div class="page-custom-title"> | |
<?php echo wpautop($custom_page_title); ?> | |
</div> | |
<?php endif; ?> | |
<?php endif; ?> | |
<?php if($enable_breadcrumb == true) : ?> | |
<?php the_breadcrumb(); ?> | |
<?php endif; ?> | |
</div> | |
</div> | |
</div> | |
</div> | |
<?php endif; ?> | |
<div id="primary" class="content-area"> | |
<main id="main" class="site-main"> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-md-12"> | |
<?php | |
get_template_part( 'template-parts/content', 'page' ); | |
// If comments are open or we have at least one comment, load up the comment template. | |
if ( comments_open() || get_comments_number() ) : | |
comments_template(); | |
endif; | |
?> | |
</div> | |
</div> | |
</div> | |
</main><!-- #main --> | |
</div><!-- #primary --> | |
<?php | |
endwhile; // End of the loop. | |
get_footer(); | |
//demo link: http://andproductionbd.com/galibweb/about/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment