179 lines
7.1 KiB
PHP
179 lines
7.1 KiB
PHP
<?php
|
||
// این تابع برای برای منوی هدر میباشد
|
||
function hefz_header_menu(){
|
||
register_nav_menu('header-menu',__('هدر بالایی'));
|
||
}
|
||
add_action('init', 'hefz_header_menu');
|
||
//افزودن قابلیت های قالب
|
||
add_theme_support('post-thumbnails');
|
||
//پست تایپ اسلایدر
|
||
function Hefz_Slider_PostType(){
|
||
register_post_type('slider', array(
|
||
'labels' => array(
|
||
'name' => __('اسلایدرها') ,
|
||
'singular_name' => __('اسلایدر') ,
|
||
'add_new' => __( 'افزودن اسلایدر'),
|
||
'add_new_item' => __( 'افزودن اسلایدر'),
|
||
),
|
||
'public' => true ,
|
||
'has_archive' => false ,
|
||
'supports' => array('title','editor','thumbnail','link')
|
||
));
|
||
}
|
||
add_filter('init','Hefz_Slider_PostType');
|
||
|
||
//پست تایپ برند ها
|
||
function Hefz_Brand_PostType(){
|
||
register_post_type('Brands', array(
|
||
'labels' => array(
|
||
'name' => __('برند ها') ,
|
||
'singular_name' => __('برند') ,
|
||
'add_new' => __( 'افزودن برند'),
|
||
'add_new_item' => __( 'افزودن برند'),
|
||
|
||
),
|
||
'public' => true ,
|
||
'has_archive' => false ,
|
||
'supports' => array('title','editor','thumbnail','link'),
|
||
'menu_icon' => 'dashicons-tickets-alt',
|
||
));
|
||
}
|
||
add_filter('init','Hefz_Brand_PostType');
|
||
//ابزارک های فوتر
|
||
function Hefz_Register_Widget(){
|
||
register_sidebar( array(
|
||
'name' => __('فوتر حفظ 1'),
|
||
'id' => 'footer-1',
|
||
'description' => __( 'در این بخش شما میتونید ابزارک های فوتر ستون اول رو اضافه کنید'),
|
||
'before_widget' => '<div id="%1$s" class="widget %2$s">',
|
||
'after_widget' => "</div>\n"
|
||
) );
|
||
|
||
register_sidebar( array(
|
||
'name' => __('فوتر حفظ 2'),
|
||
'id' => 'footer-2',
|
||
'description' => __( 'در این بخش شما میتونید ابزارک های فوتر ستون دوم رو اضافه کنید'),
|
||
'before_widget' => '<div id="%1$s" class="widget %2$s">',
|
||
'after_widget' => "</div>\n"
|
||
) );
|
||
|
||
register_sidebar( array(
|
||
'name' => __('فوتر حفظ 3'),
|
||
'id' => 'footer-3',
|
||
'description' => __( 'در این بخش شما میتونید ابزارک های فوتر ستون سوم رو اضافه کنید'),
|
||
'before_widget' => '<div id="%1$s" class="widget %2$s">',
|
||
'after_widget' => "</div>\n",
|
||
) );
|
||
|
||
register_sidebar( array(
|
||
'name' => __('سایدر سایت'),
|
||
'id' => 'sidbar-widget',
|
||
'description' => __('این بخش مربوط به ساید بار سایت میباشد'),
|
||
'before_widget' => '<div id="%1$s" class="widget %2$s">',
|
||
'after_widget' => "</div>\n",
|
||
) );
|
||
}
|
||
add_action('widgets_init', 'Hefz_Register_Widget');
|
||
|
||
//مسیر راهنمای صفحهات
|
||
function custom_breadcrumbs() {
|
||
$delimiter = ' » ';
|
||
$home = 'خانه'; // نام صفحه اول سایت
|
||
global $post;
|
||
echo '<a href="' . home_url() . '">' . $home . '</a>' . $delimiter;
|
||
if (is_category() || is_single()) {
|
||
the_category(', ');
|
||
if (is_single()) {
|
||
echo $delimiter;
|
||
the_title();
|
||
}
|
||
} elseif (is_page() && $post->post_parent) {
|
||
$parent_id = $post->post_parent;
|
||
$breadcrumbs = array();
|
||
while ($parent_id) {
|
||
$page = get_page($parent_id);
|
||
$breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
|
||
$parent_id = $page->post_parent;
|
||
}
|
||
$breadcrumbs = array_reverse($breadcrumbs);
|
||
foreach ($breadcrumbs as $crumb) echo $crumb . $delimiter;
|
||
echo get_the_title();
|
||
} elseif (is_page()) {
|
||
echo get_the_title();
|
||
} elseif (is_search()) {
|
||
echo 'نتایج جستجو برای "' . get_search_query() . '"';
|
||
}
|
||
}
|
||
|
||
|
||
|
||
class Hefz_Register_Widget_Post extends WP_Widget {
|
||
|
||
function __construct() {
|
||
// Instantiate the parent object.
|
||
parent::__construct( false, __( 'حفظ | ابزارک آخرین مطالب') );
|
||
|
||
}
|
||
|
||
|
||
function widget( $args, $instance ) {
|
||
|
||
//شروع بخش آخرین مقالات
|
||
$args = array('post_type' => 'post',
|
||
'posts_per_page' => $instance['recentcont']
|
||
);
|
||
$query = new WP_Query($args);
|
||
// The Query.
|
||
$the_query = new WP_Query( $args );
|
||
?>
|
||
<div class="sidebar-related-post">
|
||
<span class="last-post-title"><?php echo $instance['recenttitle']?></span>
|
||
<?php
|
||
// The Loop.
|
||
if ( $the_query->have_posts() ) {
|
||
while ( $the_query->have_posts() ) {
|
||
$the_query->the_post();?>
|
||
<div class="item-post">
|
||
<a href="<?php the_permalink();?>"><?php the_post_thumbnail();?></a>
|
||
<a href="<?php the_permalink();?>"><h3 class="title-post"><?php the_title();?></h3></a>
|
||
</div>
|
||
<?php
|
||
}
|
||
} else {
|
||
esc_html_e( 'پستی برای نمایش وجود ندارد' );
|
||
}
|
||
// Restore original Post Data.
|
||
wp_reset_postdata();
|
||
//پایان آخرین مقالات
|
||
?>
|
||
</div>
|
||
<?php
|
||
}
|
||
|
||
|
||
function update( $new_instance, $old_instance ) {
|
||
$instance = $old_instance;
|
||
$instance ['recenttitle'] = $new_instance ['recenttitle'];
|
||
$instance ['recentcont'] = $new_instance ['recentcont'];
|
||
return $instance;
|
||
}
|
||
|
||
function form( $instance ) {
|
||
$title = !empty($instance['recenttitle']) ? $instance['recenttitle'] : 'آخرین مطالب';
|
||
$cont = !empty($instance['recentcont']) ? $instance['recentcont'] : 4;
|
||
?>
|
||
<label for="">عنوان پست ها</label>
|
||
<input type="text" name="<?php echo $this->get_field_name('recenttitle');?>" id="<?php echo $this->get_field_id('recenttitle');?>" value="<?php echo $title?>">
|
||
<label for="">تعداد پست ها</label>
|
||
<input type="number" name="<?php echo $this->get_field_name('recentcont');?>" id="<?php echo $this->get_field_id('recentcont');?>" value=<?php echo $cont?>>
|
||
<?php
|
||
return;
|
||
}
|
||
}
|
||
|
||
add_action( 'widgets_init', 'function_Hefz_Register_Widget_Post' );
|
||
|
||
|
||
function function_Hefz_Register_Widget_Post() {
|
||
register_widget('Hefz_Register_Widget_Post');
|
||
}
|