Remove woo image from sidebar of showoff

Recently I had to customize “Showoff” woo theme for a customer. And one of his requirement was to remove woo image from sidebar and the copyright text from footer and add a custom copyright text. I spent hours finding from which file I can do that. Finally I found that it can be easily done on theme options page in wordpress admin area. Here is the way you can do it if some one interested.

Setting Custom Copyright Content

There is an option to select “Enable Custom Text Area” at the bottom of the theme options page’s Settings->Layout tab. Tick it and enter your custom content in the text area bellow to that with “Custom Text” as the label.

copyright-showoff

Think this would helpful for you in any kind. Thank you very much for following this article

Develop Simple PHP MVC framework

Pointing all the requests to a central location

.htaccess file can be used to do that. Here is an example where all the requests to a certain website is pointed to index.php in the root directory.

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^([^?]*)$ index.php?url=$1 [NC,L,QSA]

place the .htaccess file in your root directory and create a file index.php in the same directory with some dummy content. And access the site using different urls like

your-domail.com/
your-domail.com/about/us
your-domail.com/product/234/view

You will still see that all the requests to the website goes directly to the index.php

Process all URL’s from a single file

Processing all the requests to the website using a single file/function is required. Routes.php is used in this example.

<?php
class Router{
    function __construct(){
        if(isset($_GET['url'])){
            $raw_url = $_GET['url'];
            $urlTrim = rtrim($raw_url, "/");
            /** making an array of parts of url ( seperated by / ) */
            $url = explode("/", $urlTrim);
            $controller_name = $url[0];
            if(file_exists(ABSPATH."Controller/".$controller_name.".php")){
                /**
                 * if controller file is there, mc-autoload.php will load it
                 * here the controller is actually created/instantiated
                 */
                $controller = new $controller_name();
                /**
                 * if 2 or more string phrases available in the url,
                 * pass 2nd and later strings as parameters to the action
                 */
                if(isset($url[2])){
                    $action = $url[1];
                    /**
                     * removing 0th and 1st elements from $url array
                     */
                    array_shift($url);
                    array_shift($url);
                    $data = $url;

                    /**
                     * check whether action function exists
                     */

                    if(method_exists($controller, $action)){
                        $controller->{$action}($data);
                    } else {
                        $controller = new Error();
                    }
                } else {
                    if(isset($url[1])){

                        /**
                         * check whether the action function exists
                         */
                        if(method_exists($controller, $url[1])){
                            /**
                             * calling the action with no parameters
                             */
                            $controller->{$url[1]}();
                        } else {
                            $controller = new Error();
                        }
                    } else {
                        /**
                         * calling to home page, if there is no action specified
                         */
                        $controller = new Error();
                    }
                }
            } else {
                /**
                 * If controller file is not found, the error/404 page is loading
                 */
                require_once (ABSPATH."Controller/error.php");
                $controller = new Error();
                return false;
            }
        } else {
            /** if url/controller is not set, load home page */
            require_once(ABSPATH.'Controller/index.php');
            $controller = new Index();
        }
    }
}

How to show posts from a category?

Have you ever wanted to show wordpress posts from a category? Well, a customer had a such requirement recently and I’m going to share my code with some comments here. I know there are number of plugins to do the same, but we have more control when we write our own code in our theme.

In the first step lets write our code snippet in the functions.php file of our theme as a shortcode and use it in theme files. In the next step we will integrate it to a plugin.

Ok, its time to exercise. Open functions.php file of your active theme and copy and past following code in it.

<?php
function unc_show_posts_by_category($attr){
    /** wp query to get posts from specific category */
    $cat_name = $attr['category_name'];
    $num_posts = $attr['num_posts'];
    $unc_query = new WP_Query( array('category_name' => $cat_name, 'posts_per_page' => $num_posts));

    $results = '';
    /** starting the loop */
    if($unc_query->have_posts()):
        $results .= '<ul class="muaw-posts-by-category">';
        while($unc_query->have_posts()){
            $unc_query->the_post();
            $results .= '<li>';
            if(has_post_thumbnail()) {
                $results .= '<a href="' . get_the_permalink() . '" rel="bookmark">' . get_the_post_thumbnail(get_the_ID(), array(50, 50)) . get_the_title() . '</a>';
            } else {
                $results .= '<a href="' . get_the_permalink() . '" rel="bookmark">' .get_the_title() . '</a>';
            }
            $results .= '</li>';
        }
        $results .= '</ul>';
    endif;

    return $results;

    /* Re-set original Post Data */
    wp_reset_postdata();
}

// Add a shortcode
add_shortcode('muaw_category_posts', 'unc_show_posts_by_category');
?>

Now your theme is ready to use shortcode. This function queries to get specific number of posts from a certain category. If featured image is set, this code snippet will display the post thumbnail too. And at the end we defined a shortcode ‘muaw_category_posts’ to simplify it’s usage.

There are 3 different ways to display posts in a certain category using above code.

First method is to call to the function directly in a preferred place inside your theme. To do that simply past the following code in a preferred theme file ( such as page.php, sidebar.php etc… )

<?php
$attr['category_name'] = "uncategorized";
$attr['num_posts'] = 5;
echo unc_show_posts_by_category($attr);
?>

Make sure to change ‘uncategorized’ to a desired category slug and 5 to the number of posts you need to display.

And second method is to call the shortcode inside a theme file. Same as above, past the following code in a desired place of a desired theme file to show posts from a certain category.

<?php echo do_shortcode( '[muaw_category_posts category_name="uncategorized" num_posts="5"]' ); ?>

Here also you will have to change the parameters to fit your needs.

The last method of applying this code to your theme is pretty easy. In the post/page editor, you can past the bellow code and that’s it.

[muaw_category_posts category_name="uncategorized" num_posts="5"]

In order to show the list of posts, you may do some css coding in your theme’s stylesheet. Happy coding!