We are going to launch our website soon...

Forum


Sample code WP-20

- Md Moniruzzaman on 31 January 2025



   <?php
        add_action
("after_setup_theme""wplearntheme");
        
        if(!
function_exists("wplearntheme"))
        {
            function 
wplearntheme()
            {
                
add_theme_support("post-thumbnails");
                
load_theme_textdomain("learnwp"get_template_directory()."/languages");
                
                
//add_theme_support("post-thumbnails", array("post", "service", "page"));
                
add_theme_support("post-formats", array("aside""gallery""quate""image""video""audio"));
                
                
add_action("wp_enqueue_scripts""mywpscript");
                if(!
function_exists("mywpscript"))
                {
                    function 
mywpscript()
                    {
                        
wp_enqueue_style("bootstrap_css"get_parent_theme_file_uri("assets/css/bootstrap.min.css"), array(), wp_get_theme()->get("Version"), "all");
                        
wp_enqueue_style("nice_css"get_parent_theme_file_uri("assets/css/nice-select.css"), array(), wp_get_theme()->get("Version"), "all");
                        
wp_enqueue_style("awesome_css"get_parent_theme_file_uri("assets/css/font-awesome.min.css"), array(), wp_get_theme()->get("Version"), "all");
                        
wp_enqueue_style("icofont_css"get_parent_theme_file_uri("assets/css/icofont.css"), array(), wp_get_theme()->get("Version"), "all");
                        
wp_enqueue_style("slicknav_css"get_parent_theme_file_uri("assets/css/slicknav.min.css"), array(), wp_get_theme()->get("Version"), "all");
                        
wp_enqueue_style("owl_css"get_parent_theme_file_uri("assets/css/owl-carousel.css"), array(), wp_get_theme()->get("Version"), "all");
                        
wp_enqueue_style("datepicker_css"get_parent_theme_file_uri("assets/css/datepicker.css"), array(), wp_get_theme()->get("Version"), "all");
                        
wp_enqueue_style("animate_css"get_parent_theme_file_uri("assets/css/animate.min.css"), array(), wp_get_theme()->get("Version"), "all");
                        
wp_enqueue_style("magnific_css"get_parent_theme_file_uri("assets/css/magnific-popup.css"), array(), wp_get_theme()->get("Version"), "all");
                        
wp_enqueue_style("normalize_css"get_parent_theme_file_uri("assets/css/normalize.css"), array(), wp_get_theme()->get("Version"), "all");
                        
wp_enqueue_style("responsive_css"get_parent_theme_file_uri("assets/css/responsive.css"), array(), wp_get_theme()->get("Version"), "all");
                        
wp_enqueue_style("style_css"get_parent_theme_file_uri("assets/css/style.css"), array(), wp_get_theme()->get("Version"), "all");
        
                        
wp_enqueue_style("unique_id"get_stylesheet_uri());
                        
wp_enqueue_style("main_css"get_parent_theme_file_uri("assets/css/main.css"), array(), wp_get_theme()->get("Version"), "all");
                        
//wp_add_inline_style("unique_id", "body {background:yellow;}");
                        
wp_enqueue_script("main"get_template_directory_uri()."/assets/js/main.js", array(), wp_get_theme()->get("Version"), true);
                        
//wp_add_inline_script("main", "console.log("Allah Mohan");");
                        
                    
}
                }
                
                
add_action("add_meta_boxes""mymeta");
        
                if(!
function_exists("mymeta"))
                {
                    function 
mymeta()
                    {
                        
add_meta_box(
                            
"myfirstmetabox",
                            
"Add Iicon Class",
                            
"myinputhtml",
                            
"myownslider"
                        
);            
                    }
                }
                
                if(!
function_exists("myinputhtml"))
                {
                    function 
myinputhtml($post)
                    {
                        
$icon get_post_meta($post->ID"unique_key"true);
                        
?>
                            <label for="icon">Icon Class Name</labbel>
                            <input type="text" name="iconClass" value="<?php echo $icon?>">
                        <?php
                    
}
                }
                
                
add_action("save_post""mymetasave");
                
                if(!
function_exists("mymetasave"))
                {
                    function 
mymetasave($post_id)
                    {
                        
update_post_meta($post_id"unique_key"$_POST["iconClass"]);
                    }
                }
            }
        }
        
        
        
        require 
get_template_directory()."/inc/custompost/slider.php";






    
?>
    
    <?php
    add_action
("init""mycustompost");
    
    if(!
function_exists("mycustompost"))
    {
        function 
mycustompost()
        {
            
register_post_type("myownslider", array(
                
"labels" => array(
                    
"name" => __("My Service Help""learnwp"),
                    
"singular_name" => __("Slider""learnwp"),
                    
"menu_name" => __("My Service Help""learnwp"),
                    
"all_items" => __("My Service Help List""learnwp"),
                    
"view_item" => __("My Service Best Help""learnwp"),
                    
"add_new" => __("Add New Help Service""learnwp"),
                    
"edit_item" => __("Edit Service""learnwp"),
                    
"update_item" => __("Update Service""learnwp"),
                ),
                
"public" => true,
                
"supports" => array(
                    
"title""editor""thumbnail""author""comments""excerpt"
                
),
                
"capability_type" => "post",
                
"menu_position" => 5
            
));
        }
    }
    
    
?>

<!--
    There are 5 post types in Wordpress:
        1.    Post
        2.    Page
        3.    Revision
        4.    Attachment
        5.    Nav Menu
    
    
    Menu Position:
        2    Dashboard
        4    Seperator
        5     Posts
        10    Media
        15    Links
        20    Pages
        25    comments
        59    Seperator
        60    Appearance
        65    Plugins
        70    Users
        75    Tools
        80    Settings
        99    Seperator
        
    hierarchy for Blog
        1.    single-{post-type}-{slug}
        2.    siingle-{post-type}
        3.    single.php
        4.    singular.php
        5.    index.php
-->


<?php get_header(); ?>
        
        <!-- Breadcrumbs -->
        <div class="breadcrumbs overlay">
            <div class="container">
                <div class="bread-inner">
                    <div class="row">
                        <div class="col-12">
                            <h2>News</h2>
                            <ul class="bread-list">
                                <li><a href="index.html">Home</a></li>
                                <li><i class="icofont-simple-right"></i></li>
                                <li class="active">News</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- End Breadcrumbs -->
        
        <!-- Single News -->
        <section class="news-single section">
            <div class="container">
                <div class="row">
                    <div class="col-lg-8 col-12">
                        <div class="row">
                            <div class="col-12">
                                <div class="single-main">
                                    <!-- News Head -->
                                    <div class="news-head">
                                        <?php the_post_thumbnail(); ?>
                                    </div>
                                    <!-- News Title -->
                                    <h1 class="news-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                                    <!-- Meta -->
                                    <div class="meta">
                                        <div class="meta-left">
                                            <span class="author"><a href="#">
                                            <?php echo get_avatar(get_the_author_meta("ID"), 1); ?>
                                            </a> <?php the_author(); ?></span>
                                            <span class="date"><i class="fa fa-clock-o"></i><?php echo get_the_date(); ?></span>
                                        </div>
                                        <div class="meta-right">
                                            <span class="comments"><a href="#"><i class="fa fa-comments"></i>05 Comments</a></span>
                                            <span class="views"><i class="fa fa-eye"></i>33K Views</span>
                                        </div>
                                    </div>
                                    <!-- News Text -->
                                    <div class="news-text">
                                        <p><?php the_content(); ?></p>
                                        <p><?php the_content(); ?></p>
                                        <div class="image-gallery">
                                            <div class="row">
                                                <div class="col-lg-6 col-md-6 col-12">
                                                    <div class="single-image">
                                                        <img src="img/blog2.jpg" alt="#">
                                                    </div>
                                                </div>
                                                <div class="col-lg-6 col-md-6 col-12">
                                                    <div class="single-image">
                                                        <img src="img/blog3.jpg" alt="#">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <p><?php the_content(); ?></p>
                                        <blockquote class="overlay">
                                            <p><?php the_content(); ?></p>                    
                                        </blockquote>
                                        <p><?php the_content(); ?></p>
                                        <p><?php the_content(); ?></p>
                                    </div>
                                    <div class="blog-bottom">
                                        <!-- Social Share -->
                                        <ul class="social-share">
                                            <li class="facebook"><a href="#"><i class="fa fa-facebook"></i><span>Facebook</span></a></li>
                                            <li class="twitter"><a href="#"><i class="fa fa-twitter"></i><span>Twitter</span></a></li>
                                            <li class="google-plus"><a href="#"><i class="fa fa-google-plus"></i></a></li>
                                            <li class="linkedin"><a href="#"><i class="fa fa-linkedin"></i></a></li>
                                            <li class="pinterest"><a href="#"><i class="fa fa-pinterest"></i></a></li>
                                        </ul>
                                        <!-- Next Prev -->
                                        <ul class="prev-next">
                                            <li class="prev"><a href="#"><i class="fa fa-angle-double-left"></i></a></li>
                                            <li class="next"><a href="#"><i class="fa fa-angle-double-right"></i></a></li>
                                        </ul>
                                        <!--/ End Next Prev -->
                                    </div>
                                </div>
                            </div>
                            <div class="col-12">
                                <div class="blog-comments">
                                    <h2>All Comments</h2>
                                    <div class="comments-body">
                                        <!-- Single Comments -->
                                        <div class="single-comments">
                                            <div class="main">
                                                <div class="head">
                                                    <img src="img/author1.jpg" alt="#"/>
                                                </div>
                                                <div class="body">
                                                    <h4>Afsana Mimi</h4>
                                                    <div class="comment-meta"><span class="meta"><i class="fa fa-calendar"></i>March 05, 2019</span><span class="meta"><i class="fa fa-clock-o"></i>03:38 AM</span></div>
                                                    <p>Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas</p>
                                                    <a href="#"><i class="fa fa-reply"></i>replay</a>
                                                </div>
                                            </div>
                                        </div>        
                                        <!--/ End Single Comments -->
                                        <!-- Single Comments -->
                                        <div class="single-comments left">
                                            <div class="main">
                                                <div class="head">
                                                    <img src="img/author2.jpg" alt="#"/>
                                                </div>
                                                <div class="body">
                                                    <h4>Naimur Rahman</h4>
                                                    <div class="comment-meta"><span class="meta"><i class="fa fa-calendar"></i>March 05, 2019</span><span class="meta"><i class="fa fa-clock-o"></i>03:38 AM</span></div>
                                                    <p>Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas</p>
                                                    <a href="#"><i class="fa fa-reply"></i>replay</a>
                                                </div>
                                            </div>
                                        </div>        
                                        <!--/ End Single Comments -->
                                        <!-- Single Comments -->
                                        <div class="single-comments">
                                            <div class="main">
                                                <div class="head">
                                                    <img src="img/author3.jpg" alt="#"/>
                                                </div>
                                                <div class="body">
                                                    <h4>Suriya Molharta</h4>
                                                    <div class="comment-meta"><span class="meta"><i class="fa fa-calendar"></i>March 05, 2019</span><span class="meta"><i class="fa fa-clock-o"></i>03:38 AM</span></div>
                                                    <p>Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas</p>
                                                    <a href="#"><i class="fa fa-reply"></i>replay</a>
                                                </div>
                                            </div>
                                        </div>        
                                        <!--/ End Single Comments -->                                            
                                    </div>
                                </div>
                            </div>
                            <div class="col-12">
                                <div class="comments-form">
                                    <h2>Leave Comments</h2>
                                    <!-- Contact Form -->
                                    <form class="form" method="post" action="mail/mail.php">
                                        <div class="row">
                                            <div class="col-lg-4 col-md-4 col-12">
                                                <div class="form-group">
                                                    <i class="fa fa-user"></i>
                                                    <input type="text" name="first-name" placeholder="First name" required="required">
                                                </div>
                                            </div>
                                            <div class="col-lg-4 col-md-4 col-12">
                                                <div class="form-group">
                                                    <i class="fa fa-envelope"></i>
                                                    <input type="text" name="last-name" placeholder="Last name" required="required">
                                                </div>
                                            </div>
                                            <div class="col-lg-4 col-md-4 col-12">
                                                <div class="form-group">
                                                    <i class="fa fa-envelope"></i>
                                                    <input type="email" name="email" placeholder="Your Email" required="required">
                                                </div>
                                            </div>
                                            <div class="col-12">
                                                <div class="form-group message">
                                                    <i class="fa fa-pencil"></i>
                                                    <textarea name="message" rows="7" placeholder="Type Your Message Here" ></textarea>
                                                </div>
                                            </div>
                                            <div class="col-12">
                                                <div class="form-group button">    
                                                    <button type="submit" class="btn primary"><i class="fa fa-send"></i>Submit Comment</button>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                    <!--/ End Contact Form -->
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-4 col-12">
                        <div class="main-sidebar">
                            <!-- Single Widget -->
                            <div class="single-widget search">
                                <div class="form">
                                    <input type="email" placeholder="Search Here...">
                                    <a class="button" href="#"><i class="fa fa-search"></i></a>
                                </div>
                            </div>
                            <!--/ End Single Widget -->
                            <!-- Single Widget -->
                            <div class="single-widget category">
                                <h3 class="title">Blog Categories</h3>
                                <ul class="categor-list">
                                    <?php
                                        $allCat 
get_categories(array(
                                            
"orderby" => "name",
                                            
"order" => "ASC"
                                        
));
                                        foreach(
$allCat as $cat)
                                        {
                                    
?>
                                    <li><a href="#"><?php echo $cat->name?></a></li>
                                    <?php
                                        
}
                                    
?>
                                </ul>
                            </div>
                            <!--/ End Single Widget -->
                            <!-- Single Widget -->
                            <div class="single-widget recent-post">
                                <h3 class="title">Recent post</h3>
                                <!-- Single Post -->
                                <?php
                                    
if(have_posts()):
                                        while(
have_posts()): the_post();
                                
?>
                                <div class="single-post">
                                    <div class="image">
                                        <?php the_post_thumbnail(); ?>
                                    </div>
                                    <div class="content">
                                        <h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
                                        <ul class="comment">
                                            <li><i class="fa fa-calendar" aria-hidden="true"></i><?php echo get_the_date("M d, Y"); ?></li>
                                            <li><i class="fa fa-commenting-o" aria-hidden="true"></i>35</li>
                                        </ul>
                                    </div>
                                </div>
                                <?php
                                        
endwhile;
                                    endif;
                                
?>
                                <!-- End Single Post -->
                            </div>
                            <!--/ End Single Widget -->
                            <!-- Single Widget -->
                            <!--/ End Single Widget -->
                            <!-- Single Widget -->
                            <div class="single-widget side-tags">
                                <h3 class="title">Tags</h3>
                                <ul class="tag">
                                    <li><a href="#">business</a></li>
                                    <li><a href="#">wordpress</a></li>
                                    <li><a href="#">html</a></li>
                                    <li><a href="#">multipurpose</a></li>
                                    <li><a href="#">education</a></li>
                                    <li><a href="#">template</a></li>
                                    <li><a href="#">Ecommerce</a></li>
                                </ul>
                            </div>
                            <!--/ End Single Widget -->
                        </div>
                    </div>
                </div>
            </div>
        </section>
        <!--/ End Single News -->
        
        <?php get_footer(); ?>
        
            <?php get_header(); ?>
        
        <!-- Slider Area -->
        <?php get_template_part("template-parts/slider"); ?>
        <!--/ End Slider Area -->
        
        <!-- Start Schedule Area -->
        <?php get_template_part("template-parts/schedule"); ?>
        <!--/End Start schedule Area -->

        <!-- Start Feautes -->
        <?php get_template_part("template-parts/features"); ?>
        <!--/ End Feautes -->
        
        <!-- Start Fun-facts -->
        <?php get_template_part("template-parts/fun"); ?>
        <!--/ End Fun-facts -->
        
        <!-- Start Why choose -->
        <?php get_template_part("template-parts/why_choose"); ?>
        <!--/ End Why choose -->
        
        <!-- Start Call to action -->
        <?php get_template_part("template-parts/call_to_action"); ?>
        <!--/ End Call to action -->
        
        <!-- Start portfolio -->
        <?php get_template_part("template-parts/portfolio"); ?>
        <!--/ End portfolio -->
        
        <!-- Start service -->
        <?php get_template_part("template-parts/service"); ?>
        <!--/ End service -->
        
        <!-- Pricing Table -->
        <?php get_template_part("template-parts/pricing"); ?>    
        <!--/ End Pricing Table -->

        <!-- Start Blog Area -->
        <?php get_template_part("template-parts/blog_content"); ?>    
        <!-- End Blog Area -->
        
        <!-- Start clients -->
        <?php get_template_part("template-parts/clients"); ?>    
        <!--/Ens clients -->
        
        <!-- Start Appointment -->
        <?php get_template_part("template-parts/appointment"); ?>
        <!-- End Appointment -->
        
        <!-- Start Newsletter Area -->
        <?php get_template_part("template-parts/newsletter"); ?>
        <!-- /End Newsletter Area -->
    <?php get_footer(); ?>    
    

    



© Jamila 2025