Need Some Help Modifying Wordpress Theme

Discussion in 'Web Design' started by Bekbek, Apr 30, 2013.

  1. Bekbek

    Bekbek Junior Member

    Joined:
    Apr 10, 2010
    Messages:
    190
    Likes Received:
    35
    homepage.jpg

    I want to add an additional block above for a new category and I want to have an option like I can choose what it looks like. With 1 big thumb and 3 small ones or with 6 small ones. I already knew how to add them manually, what I want is I can choose between them on the options page on my wp admin shown below

    options.png

    The original theme have only 4 blocks and 4 options I just added additional two blocks and option by copying the last part of the code. And it was successful, I just want to have an option like If I want the block with big thumbs or the small ones, Or I want to disabled a block in the future without having to edit the code again. I really hope you can help me as I don't have much knowledge on this kind of stuff.

    Here's the code for the homepage

    Code:
    <?php
    /**
     * Template Name: Home
     * Description: Custom Home Page Template.
     *
     * @package WordPress
     * @subpackage mafiablog
     */
    
    get_header(); ?>
    
            <div id="primary" class="wrap_8">
                <div id="latest" class="grid_4">
                <h3 class="widget-title"><span>Latest</span></h3>
                
                <?php $wp_query = new WP_Query(array('ignore_sticky_posts' => 1, 'posts_per_page'=> 1)); ?>
                <?php if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post(); ?>
                
                    <div class="homecontent">
                            <a class="thumbnail" href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail( 'home-thumbnail' ); ?></a>
                        <div class="homeinfo">
                            <h4><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h4>
                            <div class="postdate"><?php _e("Posted on", 'mafiablog'); ?> <?php the_time(__("F j, Y", 'mafiablog')); ?></div>
                            <div class="excerpt"><?php the_excerpt(); ?></div>
                        </div>
                    </div>
                    
                <?php endwhile; ?>
                <?php else : // do not delete ?>
                <?php endif; // do not delete ?>
    
                </div><!-- #latest -->
                <div id="feature" class="grid_4">
                <h3 class="widget-title"><span>Featured</span></h3>
                <?php $feat_cat = of_get_option('feat_cat', 'no entry' ); ?>
                <?php $wp_query = new WP_Query(array('cat'=>$feat_cat, 'showposts'=>1)); ?>
                <?php if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post(); ?>
                
                    <div class="homecontent">
                            <a class="thumbnail" href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail( 'home-thumbnail' ); ?></a>
                        <div class="homeinfo">
                            <h4><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h4>
                            <div class="postdate"><?php _e("Posted on", 'mafiablog'); ?> <?php the_time(__("F j, Y", 'mafiablog')); ?></div>
                            <div class="excerpt"><?php the_excerpt(); ?></div>
                        </div>
                    </div>
                    
                <?php endwhile; ?>
                <?php else : // do not delete ?>
                <?php endif; // do not delete ?>
    
                </div><!-- #featured -->
                <div id="movies" class="cat-content grid_8">
                <?php $movie_title = of_get_option('movie_title', 'Movies' ); ?>
                <h3 class="widget-title"><span><?php echo $movie_title; ?></span></h3>
                <?php $movie_cat = of_get_option('movie_cat', 'no entry' ); ?>
                <?php $c = 0; ?>
                <?php $wp_query = new WP_Query(array('cat'=>$movie_cat, 'showposts'=>4)); ?>
                <?php if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post(); ?>
                <?php $class = ''; $c++; if ( $c == 1 ) $class .= ' first'; ?>
                <?php global $post; $video = get_post_meta($post->ID, 'video_code', true); ?>
                    <div class="cat thumbnail grid_4<?php echo $class; ?>">
                        <?php if ($video) {
                            echo html_entity_decode($video);
                        }
                        else {
                            echo '<a href="'; the_permalink(); echo '" rel="bookmark">';
                                the_post_thumbnail( 'category-thumbnail' );
                            echo '</a>';
                        } ?>
                        <div class="cat-info">
                        <h4 class="cat-title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h4>
                        <div class="postdate"><?php _e("Posted on", 'mafiablog'); ?> <?php the_time(__("F j, Y", 'mafiablog')); ?></div>
                        </div>
                    </div>
                    
                <?php endwhile; ?>
                <?php else : // do not delete ?>
                <?php endif; // do not delete ?>
                <div class="clear"></div>
                </div><!-- #movies -->
                <div id="sports" class="cat-content grid_8">
                <?php $sports_title = of_get_option('sports_title', 'Mafia Sports' ); ?>
                <h3 class="widget-title"><span><?php echo $sports_title; ?></span></h3>
                <?php $sports_cat = of_get_option('sports_cat', 'no entry' ); ?>
                <?php $c = 0; ?>
                <?php $wp_query = new WP_Query(array('cat'=>$sports_cat, 'showposts'=>4)); ?>
                <?php if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post(); ?>
                <?php $class = ''; $c++; if ( $c == 1 ) $class .= ' first'; ?>
                
                    <div class="cat thumbnail grid_4<?php echo $class; ?>">
                        <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail( 'category-thumbnail' ); ?></a>
                        <div class="cat-info">
                        <h4 class="cat-title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h4>
                        <div class="postdate"><?php _e("Posted on", 'mafiablog'); ?> <?php the_time(__("F j, Y", 'mafiablog')); ?></div>
                        </div>
                    </div>
                    
                <?php endwhile; ?>
                <?php else : // do not delete ?>
                <?php endif; // do not delete ?>
    
                </div><!-- #sports -->
                <div id="other" class="cat-content grid_8">
                <?php $other_title = of_get_option('other_title', 'In Other News' ); ?>
                <h3 class="widget-title"><span><?php echo $other_title; ?></span></h3>
                <?php $other_cat = of_get_option('other_cat', 'no entry' ); ?>
                <?php $wp_query = new WP_Query(array('cat'=>$other_cat, 'showposts'=>6)); ?>
                <?php if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post(); ?>
                
                    <div class="cat thumbnail grid_4<?php echo $class; ?>">
                        <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail( 'category-thumbnail' ); ?></a>
                        <div class="cat-info">
                        <h4 class="cat-title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h4>
                        <div class="postdate"><?php _e("Posted on", 'mafiablog'); ?> <?php the_time(__("F j, Y", 'mafiablog')); ?></div>
                        </div>
                    </div>
                    
                <?php endwhile; ?>
                <?php else : // do not delete ?>
                <?php endif; // do not delete ?>
                
                </div><!-- #fifth -->
                <div id="fifth" class="cat-content grid_8">
                <?php $fifth_title = of_get_option('fifth_title', '5th Block' ); ?>
                <h3 class="widget-title"><span><?php echo $fifth_title; ?></span></h3>
                <?php $fifth_cat = of_get_option('fifth_cat', 'no entry' ); ?>
                <?php $wp_query = new WP_Query(array('cat'=>$fifth_cat, 'showposts'=>6)); ?>
                <?php if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post(); ?>
                
                    <div class="cat thumbnail grid_4<?php echo $class; ?>">
                        <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail( 'category-thumbnail' ); ?></a>
                        <div class="cat-info">
                        <h4 class="cat-title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h4>
                        <div class="postdate"><?php _e("Posted on", 'mafiablog'); ?> <?php the_time(__("F j, Y", 'mafiablog')); ?></div>
                        </div>
                    </div>
                    
                <?php endwhile; ?>
                <?php else : // do not delete ?>
                <?php endif; // do not delete ?>
                
                </div><!-- #sixth -->
                <div id="sixth" class="cat-content grid_8">
                <?php $sixth_title = of_get_option('sixth_title', '6th Block' ); ?>
                <h3 class="widget-title"><span><?php echo $sixth_title; ?></span></h3>
                <?php $sixth_cat = of_get_option('sixth_cat', 'no entry' ); ?>
                <?php $wp_query = new WP_Query(array('cat'=>$sixth_cat, 'showposts'=>6)); ?>
                <?php if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post(); ?>
                
                    <div class="cat thumbnail grid_4<?php echo $class; ?>">
                        <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail( 'category-thumbnail' ); ?></a>
                        <div class="cat-info">
                        <h4 class="cat-title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h4>
                        <div class="postdate"><?php _e("Posted on", 'mafiablog'); ?> <?php the_time(__("F j, Y", 'mafiablog')); ?></div>
                        </div>
                    </div>
                    
                <?php endwhile; ?>
                <?php else : // do not delete ?>
                <?php endif; // do not delete ?>
    
                </div><!-- #other -->
                <div class="clear"></div>
            </div><!-- #primary -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
    
    The fifth and six block / code was just copied by me from the sports block / code above

    and here's the code for the option

    Code:
    <?php
    /**
     * A unique identifier is defined to store the options in the database and reference them from the theme.
     * By default it uses the theme name, in lowercase and without spaces, but this can be changed if needed.
     * If the identifier changes, it'll appear as if the options have been reset.
     * 
     */
    
    function optionsframework_option_name() {
    
        // This gets the theme name from the stylesheet (lowercase and without spaces)
        $themename = get_theme_data(STYLESHEETPATH . '/style.css');
        $themename = $themename['Name'];
        $themename = preg_replace("/\W/", "", strtolower($themename) );
        
        $optionsframework_settings = get_option('optionsframework');
        $optionsframework_settings['id'] = $themename;
        update_option('optionsframework', $optionsframework_settings);
        
        // echo $themename;
    }
    
    /**
     * Defines an array of options that will be used to generate the settings page and be saved in the database.
     * When creating the "id" fields, make sure to use all lowercase and no spaces.
     *  
     */
    
    function optionsframework_options() {
        
        // Test data
        $test_array = array("one" => "One","two" => "Two","three" => "Three","four" => "Four","five" => "Five");
        
        // Multicheck Array
        $multicheck_array = array("one" => "French Toast", "two" => "Pancake", "three" => "Omelette", "four" => "Crepe", "five" => "Waffle");
        
        // Multicheck Defaults
        $multicheck_defaults = array("one" => "1","five" => "1");
        
        // Background Defaults
        
        $background_defaults = array('color' => '', 'image' => '', 'repeat' => 'repeat','position' => 'top center','attachment'=>'scroll');
        
        
        // Pull all the categories into an array
        $options_categories = array();  
        $options_categories_obj = get_categories();
        foreach ($options_categories_obj as $category) {
            $options_categories[$category->cat_ID] = $category->cat_name;
        }
        
        // Pull all the pages into an array
        $options_pages = array();  
        $options_pages_obj = get_pages('sort_column=post_parent,menu_order');
        $options_pages[''] = 'Select a page:';
        foreach ($options_pages_obj as $page) {
            $options_pages[$page->ID] = $page->post_title;
        }
            
        // If using image radio buttons, define a directory path
        $imagepath =  get_bloginfo('stylesheet_directory') . '/images/';
            
        $options = array();
        
        $options[] = array( "name" => "Basic Settings",
                            "type" => "heading");
                            
        $options[] = array( "name" => "Category For Featured block",
                            "desc" => "Choose among the categories.",
                            "id" => "feat_cat",
                            "type" => "select",
                            "options" => $options_categories);
                            
        $options[] = array( "name" => "Title for 2nd Block (Movies)",
                            "desc" => "Please input plain text, no html markup.",
                            "id" => "movie_title",
                            "type" => "text",);
                            
        $options[] = array( "name" => "Category For 2nd block (Movies)",
                            "desc" => "Choose among the categories.",
                            "id" => "movie_cat",
                            "type" => "select",
                            "options" => $options_categories);
        
        $options[] = array( "name" => "Title for 3rd Block (Mafia Sports)",
                            "desc" => "Please input plain text, no html markup.",
                            "id" => "sports_title",
                            "type" => "text",);
                            
        $options[] = array( "name" => "Category For 3rd block (Mafia Sports)",
                            "desc" => "Choose among the categories.",
                            "id" => "sports_cat",
                            "type" => "select",
                            "options" => $options_categories);
        
        $options[] = array( "name" => "Title for 4th Block (In Other News)",
                            "desc" => "Please input plain text, no html markup.",
                            "id" => "other_title",
                            "type" => "text",);
                            
        $options[] = array( "name" => "Category for 4th Block (In Other News)",
                            "desc" => "Choose among the categories.",
                            "id" => "other_cat",
                            "type" => "select",
                            "options" => $options_categories);
                            
        $options[] = array( "name" => "Title for 5th Block (5th Block)",
                            "desc" => "Please input plain text, no html markup.",
                            "id" => "fifth_title",
                            "type" => "text",);
                            
        $options[] = array( "name" => "Category for 5th Block (5th Block)",
                            "desc" => "Choose among the categories.",
                            "id" => "fifth_cat",
                            "type" => "select",
                            "options" => $options_categories);    
                            
        $options[] = array( "name" => "Title for 6th Block (6th Block)",
                            "desc" => "Please input plain text, no html markup.",
                            "id" => "sixth_title",
                            "type" => "text",);
                            
        $options[] = array( "name" => "Category for 6th Block (6th Block)",
                            "desc" => "Choose among the categories.",
                            "id" => "sixth_cat",
                            "type" => "select",
                            "options" => $options_categories);                            
                                        
        return $options;
    }
    
    I also just added the code for Category for 5th and 6th Block by copying the code from "Category for 4th Block (In Other News)"

    Please I really need your help. Thank you so much