Forums

Index changer Twenty Ten child theme (6 posts)

  1. zeaks
    Member
    Posted 2 years ago #

    I'm creating a twenty ten child theme, I have 2 layouts for the front page. A post grid style layout, and a regular twenty ten style. I want to have an option to switch between the two in the admin section.

    Is this possible? I've read alot of tutorials on how to change the stylesheet and add basic options, but haven't found one that would let me change which index file to use.

    At the moment it's using loop-index.php

  2. govpatel
    Member
    Posted 2 years ago #

    Yes it is possible you will install this plugin that will give a choice same way you have for pages.
    Custom Post Template

    I have article on my website how to do it along with video

  3. Digital Raindrops
    Member
    Posted 2 years ago #

    You can add a template page as Govpatel says to your theme, and instruct the user how to change this in the general Settings > Reading.

    However if you want to dynamically change the posts from a list to a grid from say Appearance > Theme Options?

    You will need to add to your child theme a theme options page, then add a new option, lets call it a checkbox loop_grid.

    create two files loop parts in your child theme, loop-index.php and loop-grid.php

    then copy index.php to the child theme and in index.php, something like:

    <?php
    /* Switch the loop to output the posts in list or grid. */
    if ( get_option('loop_grid') && get_option('loop_grid') == true ) :
    	get_template_part( 'loop', 'grid' );
    else :
             get_template_part( 'loop', 'index' );
    endif;
    ?>

    HTH

    David

  4. zeaks
    Member
    Posted 2 years ago #

    @adeptris after reading what you said I understand how it would work, I just don't know how to add it to the admin. I've used Arron Jorbins thirty ten tutorial to add the admin which I used to change the stylesheets.

    I've tried to modify the code to add a section to switch .php files and using the code you supplied, but never got it to work.

    http://wordpress.pastebin.com/M4psnQRm is my options file.

    I added and changed it to this.

    function simpleten_add_layout_php(){
    	$option = get_option('simpleten');
    	if (strlen($option) <= 1 )
    		$option = 'green';
    	$src =  get_stylesheet_directory_uri() . "/$option.php";
    	if (! is_admin() )
    		wp_enqueue_style( 'simpleten_layout', $src );
    }

    and added the option to switch to it, but it didn't work.I'm still very new with php so that's probably not even close to what I need to do.

  5. Digital Raindrops
    Member
    Posted 2 years ago #

    The code wp_enqueue_style is looking to load a stylesheet (.css), what is in green.php?

    This code might be useful to others!

    WARNING THIS IS UN-TESTED CODE
    I have changed Arron's code to give four post list output types, index (default), grid, excerpt, and postimage
    http://wordpress.pastebin.com/Hacni4WQ

    @Zeak: can you add a link to the options tutorial you used please?

    you would need to copy loop.php from the parent to create and add three / four files to your child-theme, loop-index.php, loop-grid.php, loop-excerpt.php and loop-postimage.php

    Move the index.php file to the child theme and this php code would call the loop, and would replace the standard code:

    get_template_part( 'loop', 'index' )

    With this code which gets the option and outputs one of the loop files.

    $liststyle = get_option('zeakloop');
    if (strlen($liststyle) <= 1 ) $liststyle = 'index';
    Get_template_part( 'loop' , $liststyle );

    NOTE:
    The code in the pastebin has this code but the '' are missing in get_ template_part around the loop should be 'loop'

    Anyone using the code and creating the loop parts please post them to WordPress pastebin for others to use and add them to this topic.

    HTH

    David

  6. zeaks
    Member
    Posted 2 years ago #

    Thanks Adeptris, the "green.php" was a mistake, it should of had the grid.php in there I think, either way, it wouldn't of worked. Here is the tutorial I referred to
    http://aaron.jorb.in/blog/2010/04/introducing-thirty-ten/

    Here is a grid style page layout I am using if anyone wants to use it. http://wordpress.pastebin.com/SvyVd28X I have it active on this site http://test.zeaks.org/

    I referred to two sites when creating it, yours http://digitalraindrops.net/2010/09/two-post-columns/
    and this one http://www.transformationpowertools.com/wordpress/playing-with-columns-stacking-posts-grid-style

    Here is my entire options page which works great now. The style and layout are in separate links but they are working fine.

    http://wordpress.pastebin.com/yJmctXYz

    Thanks for the help

Topic Closed

This topic has been closed to new replies.

About this Topic