Forum Replies Created

Viewing 15 replies - 1 through 15 (of 24 total)
  • Thread Starter s-design

    (@s-design-1)

    Wow! You are quick. It works! This is awesome. THANK YOU, for everything.

    Thread Starter s-design

    (@s-design-1)

    That would be really cool if you had time to look more into that bug, but I won’t hold my breath. So, no worries if you don’t have time.

    Encouragement goes a long ways to helping me and I’m sure many others work through a problem. So, thank you for that.

    Thread Starter s-design

    (@s-design-1)

    Happy news! It’s working!

    I kept checking to see if it was working by going into my list of pages in my admin, clicking on “Quick Edit” options and looking for the new page templates in the “Template” drop-down. It is not showing my newly added templates, it only shows my default template. This caused me to think it wasn’t working at all.

    But, then I went into a page editor and checked under “Page Attributes” in the “Template” drop-down. The new templates are there. I can select them and they work just I would expect. I should have checked this sooner, but I didn’t. So, It is working with the class PageTemplater code above without changing it at all.

    It often seems like the dumbest little thing I don’t check is often the answer to an issue I run into. I am so happy when I am able to get something working. Thanks for all your help with this.

    You are right about the benefits and power of using a plugin to add a feature like this. Now I can easily keep my core features only in my child theme and now a feature that I may want to use on other sites I can keep in a plugin. It is just as easy to set up a plugin as it is to create a child theme. I will recommend using this method for adding specific features to anyone.

    The templates still don’t show up in the template drop-down menu in the “Quick Edit” options. Any idea how to get them to show up there too? It is not essential to figure this part out, it would just be convenient if they showed up there too.

    Thread Starter s-design

    (@s-design-1)

    Well, I guess it is good to know that it is working on your site.

    I should give a shout-out to the ones who came up with this code that I found and I’m trying. Tom McFarlin put together this code here on github. Harri Bell-Thomas put together this tutorial here on WPExplorer.com with a github download here.

    I was aware that I could change: . 'templates/' . to something else if I wished.
    I also knew that I could change out these array items:

    $this->templates = array(
    			'template-example.php'     => 'Example Page Template',
    			'template-example-two.php' => 'Example Page Template II',
    			'About-Pages.php' => 'About SubMenu'
            );

    I knew this thanks to Harri Bell-Thomas’s tutorial.

    So, I have tried what you said. I have deactivated all my other plugins. The templates are still a no show :/

    I have tried searching these filter names in my theme files that I got from the code:
    page_attributes_dropdown_pages_args
    wp_insert_post_data
    template_include
    As far as I can tell none of them are showing in my theme files. I do see these names showing up in core WordPress files.

    I tried searching these names that I got from the action that is in the last line of code. I looked for them in my theme files:
    plugins_loaded
    PageTemplater
    get_instance
    Again, as far as I can tell none of them show up in my theme files. I do see a couple of them showing up in the core WordPress files.

    Not sure what to do next. I guess for now, I will keep searching more carefully for a conflict in my theme files. Do you have any more ideas? You are very kind to take the time to help me out.

    Thread Starter s-design

    (@s-design-1)

    Thanks for you response bcworkz. I don’t even know what you mean when you say “simple matter of setting it in post meta.” I don’t know how to ” worth debugging the offered script to determine why it does not work.” I don’t know jQuery and very little php. I mostly just copy and paste code and try and try and try different things.

    Here is the code below that I have been trying but can’t get the page templates to show up in the Page editor > Page Attributes > Drop-down. Is there something I’m doing wrong? Thank you for any help.

    class PageTemplater {
    
    		/**
             * A Unique Identifier
             */
    		 protected $plugin_slug;
    
            /**
             * A reference to an instance of this class.
             */
            private static $instance;
    
            /**
             * The array of templates that this plugin tracks.
             */
            protected $templates;
    
            /**
             * Returns an instance of this class.
             */
            public static function get_instance() {
    
                    if( null == self::$instance ) {
                            self::$instance = new PageTemplater();
                    } 
    
                    return self::$instance;
    
            } 
    
            /**
             * Initializes the plugin by setting filters and administration functions.
             */
            private function __construct() {
    
                    $this->templates = array();
    
                    // Add a filter to the attributes metabox to inject template into the cache.
                    add_filter(
    					'page_attributes_dropdown_pages_args',
    					 array( $this, 'register_project_templates' )
    				);
    
                    // Add a filter to the save post to inject out template into the page cache
                    add_filter(
    					'wp_insert_post_data',
    					array( $this, 'register_project_templates' )
    				);
    
                    // Add a filter to the template include to determine if the page has our
    				// template assigned and return it's path
                    add_filter(
    					'template_include',
    					array( $this, 'view_project_template')
    				);
    
                    // Add your templates to this array.
                    $this->templates = array(
    			'template-example.php'     => 'Example Page Template',
    			'template-example-two.php' => 'Example Page Template II',
    			'About-Pages.php' => 'About SubMenu'
            );
    } 
    
            /**
             * Adds our template to the pages cache in order to trick WordPress
             * into thinking the template file exists where it doens't really exist.
             *
             */
    
            public function register_project_templates( $atts ) {
    
                    // Create the key used for the themes cache
                    $cache_key = 'page_templates-' . md5( get_theme_root() . '/' . get_stylesheet() );
    
                    // Retrieve the cache list.
    				// If it doesn't exist, or it's empty prepare an array
                    $templates = wp_get_theme()->get_page_templates();
                    if ( empty( $templates ) ) {
                            $templates = array();
                    } 
    
                    // New cache, therefore remove the old one
                    wp_cache_delete( $cache_key , 'themes');
    
                    // Now add our template to the list of templates by merging our templates
                    // with the existing templates array from the cache.
                    $templates = array_merge( $templates, $this->templates );
    
                    // Add the modified cache to allow WordPress to pick it up for listing
                    // available templates
                    wp_cache_add( $cache_key, $templates, 'themes', 1800 );
    
                    return $atts;
    
            } 
    
            /**
             * Checks if the template is assigned to the page
             */
            public function view_project_template( $template ) {
    
                    global $post;
    
                    if (!isset($this->templates[get_post_meta(
    					$post->ID, '_wp_page_template', true
    				)] ) ) {
    
                            return $template;
    
                    } 
    
                    $file = plugin_dir_path(__FILE__). 'templates/' .get_post_meta(
    					$post->ID, '_wp_page_template', true
    				);
    
                    // Just to be safe, we check if the file exist first
                    if( file_exists( $file ) ) {
                            return $file;
                    }
    				else { echo $file; }
    
                    return $template;
    
            } 
    
    } 
    
    add_action( 'plugins_loaded', array( 'PageTemplater', 'get_instance' ) );
    Thread Starter s-design

    (@s-design-1)

    bcworkz, I have searched and searched for how to create a plugin. I have created a plugin that I am able to activate. It recognizes css and I have registered menus. I can’t figure out how to make my plugin recognize page templates.

    I have tried several different coding methods that I have found on google and none of them seems to do the trick. This method seems the most promising but, it still doesn’t show the page templates in the page editor under the page template drop-down.

    Any ideas of how to make this work?

    Thread Starter s-design

    (@s-design-1)

    I do like the power of the child theme. I will look more into creating a plugin.

    Thanks bcworkz.

    Thread Starter s-design

    (@s-design-1)

    The update fixed it.

    You are so quick and helpful.

    Thank you.

    Thread Starter s-design

    (@s-design-1)

    Hi Rob, It worked beautifully! Thank you so much. That was so nice of you to go out of your way to figure this out for me. Thanks again! You can call this thread resolved.

    Thread Starter s-design

    (@s-design-1)

    Thanks for your response.

    I tried adding to the body { position:static !important; }
    I also tried removing it.

    I tried adding to the body { position: relative; }
    I also tried removing it.

    The .site style adds margin to the bottom margin I have tried adding & removing
    { position:static !important; }
    { position: relative; }
    to this style

    None of this changed the bottom margin. Any other ideas?

    Thread Starter s-design

    (@s-design-1)

    Installed the version 0.73 update and the insert related links on pages works awesome!
    I found no problems.

    Thank you, Thank you, Thank you!

    Thread Starter s-design

    (@s-design-1)

    Glad you like these ideas.

    Sweet! I look forward to the pages option, Thanks.

    I’m glad you like how I styled them.

    You are welcome to use the screen shot. For now no credit necessary. Maybe when the site I’m working on goes public, I might ask you to post an attribution link.

    Thanks!

    I feel really dumb… You totally nailed it. I did not have “Add links to Posts” checked. You can called this thread resolved, WAHOO!

    You can see how the related links are looking after I styled them, on my testing site. They look really great and work nicely with my responsive theme.

    I will head over right now and give you a nice review and five stars on this plugin.

    I have some ideas for a couple features but I will save them for another thread.

    Thanks again, you are awesome!

    I have not given up, I really appreciate all your effort and hard work. You are providing great support.

    This is the latest things I have tried.

    On my local test site:
    – I installed v0.71
    – All my related links are working, I can edit them and update, with no problems. They work so beautifully, YES!

    On my live test site:
    – I updated to v0.71
    – I tried the same thing on my live site, I made a few changes to the related links, then navigated away without hitting update.
    – Still no related links show up. ??
    – I tried it by editing the related links in different ways and updating the the post.
    – Still no related links show up. ??
    – I cleared my browser cache and cookies, and updated the post.
    – Still no related links show up. ??

    I am happy to keep trying different things. If you have some ideas of things I can try, I’d be happy to test them out. We will get this figured out, I just know it. Thanks for your dedication.

Viewing 15 replies - 1 through 15 (of 24 total)