How do I edit the default Ghost routes.yaml file to create a static subpage for each author?
For example, site.com/author/{slug}/static-page. I need to be able to access the specific author's information on the static page, so I am hoping the url points to a custom template such as author-static-page.hbs where I can load the {{#author}} information.
This is the default:
collections:
/:
permalink: /{slug}/
template: index
taxonomies:
tag: /tag/{slug}/
author: /author/{slug}/
Related
Using the Ghost blog routes.yaml file it is possible to use the collections block to create a custom collection made from some tag(s) and / or other data. You can also tell this collection to use a custom theme template see:
https://docs.ghost.org/tutorials/creating-content-collections/
https://docs.ghost.org/concepts/routing/#content-structure
For instance:
collections:
/example/:
permalink: /example/{slug}/
controller: channel
filter: tag:example-tag
template:
- example
All of the above works and my collection properly uses my new example theme file.
The issue is that unlike the tag page (for example-tag) my new custom collection does not have a readily documented way to work with the title etc.
It does not pull the title / meta description from the tag used to build the collection (which would be great for collections built from single tags). In an attempt to work around that I tried some {{#has}} statements but I can't figure out what context the custom route would fit into.
With the above example routes.yaml the title for the custom collection ends up as 'My Site Name (Page 1)' — and there is no Meta Description.
This issue also extends into the Open Graph data which lists an identical title as well as no description for the custom collection.
My guess is that it may be possible to use a data property attached to the routes.yaml file to achieve this (see: https://docs.ghost.org/concepts/routing/#data) but I haven't found a solution as of now.
While my initial attempts at googling for a solution came up empty, this is the best reference I have seen to the issue:
https://forum.ghost.org/t/dynamic-routing-page-post-data-context-in-default-hbs-nested-navigation-on-custom-collections/4204
https://github.com/TryGhost/Ghost/issues/10082
I found a way to work around.
You create a page called example in the Ghost Admin tool.
Customize routes (instead of collections) in the routes.yaml as following:
routes:
/example/:
controller: channel
filter: tag:example-tag
template: example
data: page.example
The page.example will use the metadata of this page in the Ghost.
This is possible only with workaround described in issue: https://github.com/TryGhost/Ghost/issues/10082
Generally do following:
create page Example (with slug example) and fill metadata title & description you want
in routes.yaml alter your collection definition /example/ add following:data: page.example to link your collection root with specified page
now in your template definition example.hbs you could use e.g. {{#page}} {{content}} {{/page}} tag to insert content from your page. You can do it also in default.hbs template which is included from your example.hbs. So replace: <title>{{meta_title}}</title> in default.hbs with following:
{{#unless page}}
<title>{{meta_title}}</title>
{{else}}
{{#page}}
<title>{{meta_title}}</title>
<meta name="description" content="{{meta_description}}"/>
{{/page}}
{{/unless}}
This will set specific title/description for your collection root pages in general way. It is possible to generate schema.org metadata in the similar way. Unfortunately Facebook and Twitter metadata is not so simple to do because, {{ghost_head}} tag in default.hbs already inserts site metadata to this page. Last note: besides {{meta_title}} and {{meta_description}} I suppose you could use all metadata fields defined here.
In default.hbs I added the following block:
{{{ block "metaTitle"}}}
and eg. in post.hbs I filled that block as follows:
{{!< default}}
<div class="content-area">
<main class="site-main">
{{#post}}
{{#contentFor "metaTitle"}}
<title>{{title}}</title>
{{/contentFor}}
...
For other pages like page.hbs, blog.hbs, author.hbs I did the same. I think that solution is more flexible because we have more control over title value.
So I created a custom Location post type and a custom Location Page Template but I am not able to assign the Location Page Template to the Location posts.
The top of my Location Page Template looks like this:
/*
Template Name: Location
Template Post Type: Location
*
*/
I required the template in my functions.php file like this:
require get_stylesheet_directory() . '/inc/locations.php';
Does anyone have any experience with this?
Instead of using the Location Page Template I referred to the WordPress template hierarchy and used the single-[posttype].php so in my case single-locations.php. The diagram linked below was a helpful reference. http://codex.wordpress.org/images/1/18/Template_Hierarchy.png
I have just set up a Ghost Blog. This is a clean install on a VPS, and it is up and running correctly.
By default, Ghost shows a list of posts when opened in the browser. I would like to have a home page at the / location, and have my posts available at /blog. From what I can tell, this can be achieved by using Dynamic Routing.
To simplify this, I thought I would be able to page (Ghost has the concept of pages and posts) as the home page. I could then render this page using the already existing page.hbs template.
Here is my routes.yaml file:
routes:
/:
data: page.home
template:
- page
collections:
/blog/:
permalink: /blog/{slug}/
template:
- index
taxonomies:
tag: /blog/tag/{slug}/
author: /blog/author/{slug}/
I have a page called home, but when I load the home page, I get an empty-ish page: just the footer displays.
There are no hints in the log that tells me what could be happening. Am I understanding routes.yaml correct? Is page.home not how to pass data to a page?
I asked this question on forum.ghost.org and got the answer I was looking for.
The solution is to use the long-form data notation as below. My routes.yaml file now looks like:
routes:
/:
data:
post: page.home
template: page
collections:
/blog/:
permalink: /blog/{slug}/
template:
- index
taxonomies:
tag: /blog/tag/{slug}/
author: /blog/author/{slug}/
Now, when I load example.com the page home is loaded, and when I navigate to example.com/blog the blog is loaded
I'm facing a very common problem with Wordpress, I don't see the list of my templates in the post edit page. There are tons of posts about this here but I haven't found the solution to my problem in any of them.
I basically have this in my theme directory: index.php, page.php, header.php, functions.php, sidebar.php, style.css
in page.php and index.php, I have:
/*
Template Name: HOME
*/
and
/*
Template Name: PAGE
*/
What I've already tried:
- switched back to the original Wordpress theme and back to mine
- made sure permission 755 was attributed to folder
- copied a working file from another theme and inserted my code into it
- completely logged out and came back
but nothing worked, I still don't see the list of templates for my theme while for official themes, I do see the list of page templates.
Any suggestions?
Thanks
Laurent
You cannot use index.php or page.php as a Page Template, because those files are reserved for other templates of a theme.
As the Page Template reference states:
Name your template file so you can easily identify its Template Name, e.g., filename my-custom-page.php for template name "My Custom Page". Some coders group their templates with a filename prefix, such as page_my-custom-page.php (Don't use page- prefix as WordPress will interpret the file as a specialized page template.)
For information on Theme file-naming conventions and filenames you cannot use, see reserved Theme filenames.
How do I include a php page in a wordpress post?
I know how to include in pages, using /* Template Name: templatename */ and select a value from dropdown attributes. I don't know how to achieve this in a post, can you help?
i have file ex.php and i want to display the contents of the file in post article.
The template file for single posts is single.php
Depending on your theme you might have to create it
(for example copy index.php and name it accordingly)
see http://codex.wordpress.org/Theme_Development#Single_Post_.28single.php.29