Forums

How to use template for parent page in subpages? (8 posts)

  1. Vivienne
    Member
    Posted 1 year ago #

    Hi all,

    I'm using the following structure:
    - Showcase
    --- Website
    --- Print
    --- Animation

    I've created a template to be used for the parent page (showcase). In the Admin interface I've set the template for the Showcase page to my custom template, which works. The subpages still use the default template though. Is it possible to let the subpages (i.e. website, print, animation) use the template assigned to the parent page without having to assign the template to each individual child page?
    TIA,

    Vivienne

  2. haxxxton
    Member
    Posted 1 year ago #

    not without dynamically changing the query_posts/WP_query section of your showcase file.. which wont be easy...

    i wish there was an easier way to say to change the page template for a number of posts.. but without a lengthy SQL query there really isnt..

  3. Vivienne
    Member
    Posted 1 year ago #

    Thanks for the quick reply. I'm now using the code below in my functions.php file:

    function my_redirect_template()
    {
    	global $wp_query;
    	$thePostID = $wp_query->post->ID;
    	if ( $thePostID ) {
    		$ar_ancestors = get_post_ancestors( $thePostID );
    		if ( in_array( 11, $ar_ancestors ) ) {
    			// use Showcase template
    			include(STYLESHEETPATH . '/showcase.php');
    			exit;
    		}
    	}
    }
    add_action('template_redirect','my_redirect_template');

    Which does what I want. The only problem I then ran into was that the specific sidebar-showcase.php file was not loaded for those pages (the default sidebar was shown, as apparently is_page_template('showcase.php') returns false if you get there via redirect), so I hardcoded this sidebar into the showcase.php template.

    If anyone has another solution (especially for the sidebar issue), please let me know.

  4. haxxxton
    Member
    Posted 1 year ago #

    in your showcase.php can you not include the sidebar manually like you have done in your redirect but in the section of your showcase.php that you want your sidebar to appear..

    or even call the specific sidebar using get_sidebar('showcase');

  5. Vivienne
    Member
    Posted 1 year ago #

    Thanks, I'm now using get_sidebar('showcase') in my showcase.php template. Just to keep things orderly :-)

    I don't completely understand why after the template-redirect the code below (in functions.php) falls through to get_sidebar() in stead of get_sidebar('showcase'):

    function my_get_sidebar() {
    	if ( is_page_template( 'showcase.php' ) ) {
    		get_sidebar( 'showcase' );
    	} else {
    		get_sidebar();
    	}
    }
    remove_action('genesis_after_content', 'genesis_get_sidebar');
    add_action('genesis_after_content', 'my_get_sidebar');

    Does the method is_page_template() only look at the original template? If anyone could explain that to me, I'd appreciate it.

  6. amjewel
    Member
    Posted 1 year ago #

    i always get a message on my page
    Index of /

    * wordpress/
    can u say whats the problem ?

  7. Vivienne
    Member
    Posted 1 year ago #

    Not really the correct thread, but to answer your question: because you haven't uploaded the WordPress application to your root-folder on your server (but to the 'wordpress' folder) you have to copy the wordpress/index.php file to the root-folder and change line 17 to:
    require('./wordpress/wp-blog-header.php');

    Then, in the administration interface -> settings set the following options:
    WordPress address (URL): http://amjewel.co.cc/wordpress
    Site address (URL): http://amjewel.co.cc

    Hope this helps.

  8. amjewel
    Member
    Posted 1 year ago #

    i know its not the right place to ask but thanks a lot for your help make a try .

Topic Closed

This topic has been closed to new replies.

About this Topic