WordPress.org

Ready to get started?Download WordPress

Ideas

Out-of-theme Page Templates

  1. shazdeh
    Member

    Basically, page templates that can be somewhere other than in the template root. maybe a filter for get_page_templates() function to introduce new location to search for page templates?
    Main reason for this is that sometimes you use a page template to do custom stuff, but when you change the theme, you have to make sure to copy that in the new theme to make it work. This is the same reason as why you shouldn't put site-specific codes (like custom post types) inside functions.php file.
    Also, I'm thinking plugin authors can benefit from this too, where a plugin author develops this super cool landing page template for example, or a coming soon template, and users can assign those templates to any page.

    Posted: 2 years ago #
  2. Ipstenu (Mika Epstein)
    Half-Elf Support Rogue & Mod

    You can put CPTs and all in a file in your mu-plugins folder (that's where all my CPTs live, since I agree, they suck in the theme!)

    Templates though... The reason it would suck is that your template is generally highly dependent on your theme, and if you change themes, you have to customize the template again. Now ... You COULD turn your template code into a short code, if it's just stuff included in the content of the post.

    What sort of templates are you thinking of, for an example? There may be an extant workaround :)

    Posted: 2 years ago #
  3. shazdeh
    Member

    I am developing a little utility to help with theme translations. It takes a po file from a translation-ready theme and it translates the strings which it already has in the database. The purpose of this is to cut the work of translating the same strings in different themes over and over again.

    Now, the way I implemented this is I used a page template, the reason being that a. WordPress generates a clean URL for me; b. when the page loads the WordPress is already loaded and I can access the translation API, and I can manage it within WordPress: It's not a lonely php file somewhere in the server.

    Also, imagine a developer builds this super awesome landing page plugin, the cleanest way to provide it for the user is using a page template that the user can choose which page to apply that template on.

    Also, imagine the example sections of css-tricks.com. All the example can be a child page of "Examples" parent page (and hence a clean /examples/whatever url), and each could use a page template that has just the common layout and the advertisement codes. This is not tied to the theme.

    The only workaround I could think of was using the template_redirect hook to check for the current url and spit the custom page template if it matches. Ugly.

    I also tried overriding the 'Page Attributes' meta box so it uses a customized version of get_page_templates function, which works, but the same function is used for quick edit functionality in WordPress and I couldn't figure out how to override that. An ugly solution nonetheless.

    This was one long post.

    Posted: 2 years ago #
  4. shazdeh
    Member

    I wanted to add, the dependence on themes is true for most of page templates, but even then it could use get_header and get_footer functions to pull the header and footer data from the theme. So, the design of it depends on the theme but the functionality, it doesn't necessarily.

    Posted: 2 years ago #
  5. Ipstenu (Mika Epstein)
    Half-Elf Support Rogue & Mod

    Please hit enter twice between paragraphs ;) Makes it more readable.

    Realistically, what you're doing isn't optimal only because you're putting something for use on the BACK end on the front of the site. The example you gave would be best served by making a plugin options page on the back end, maybe adding a menu under Appearance for 'Theme Translations.'

    Also, imagine the example sections of css-tricks.com. All the example can be a child page of "Examples" parent page (and hence a clean /examples/whatever url), and each could use a page template that has just the common layout and the advertisement codes. This is not tied to the theme.

    Except it IS tied to theme. The 'common layout' you speak of isn't common at all between themes and frameworks, so you'd always want to go in and twiddle. (Also I'd use CPTs instead of pages for that, but that's another story.)

    Posted: 2 years ago #
  6. shazdeh
    Member

    About that translation tool, it's on the front because i wanted other people to use this too. So no, back-end wouldn't work.

    Except it IS tied to theme. The 'common layout' you speak of isn't common at all between themes and frameworks, so you'd always want to go in and twiddle

    By common layout I meant the head tag, and the page title, the css-tricks logo, a link to the relevant article, and so on. The theme of the site is completely different. The 'example' itself (the html/css/js codes) would be the content of the page.

    Posted: 2 years ago #
  7. This is already possible with little code. Roll your own meta box in the backend and save the data as post meta. Then, filter page_template on the front end.

    Posted: 2 years ago #
  8. Larry12
    Member

    Hi Justin,
    I am using News 0.2 theme, and I like it much. Thanks for such brilliant theme.

    But I want the following to be done but I am not successful alone.

    Kindly help me getting these done.

    1. Add "Read more" link after 100 or any no. of words (configurable) in each post on home page.
    2. Change no. of posts per page
    3. Make a parent page non clickable in every menu (Primary, secondary, subsidiary)

    Many Thanks

    Posted: 2 years ago #
  9. Ipstenu (Mika Epstein)
    Half-Elf Support Rogue & Mod

    Larry, this isn't the support forum :) go ask this there, please.

    Posted: 2 years ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    1 Vote
  • Status

    This idea has been implemented