How to get all pages from Ghost blog platform, using the get helper - ghost-blog

I am trying to get all pages from ghost blog.
{{#get "posts" limit="all" filter="page:true"}}
Doesn't work.

If you are running on latest Ghost instance (or at least the version that has Content API ^2.10.0).
You can use limit=all attribute to fetch all page resouces like so:
{{#get "pages" limit="all"}}...{{/get}}
You can find more about the limit attribute in Ghost Docs for {{get}} helper and page resource here

Related

Render Divi Tags via WordPress API

I am trying to pull out a page via the WordPress API like so:
/wp-json/wp/v2/pages/MY_PAGE_ID?status=publish
However the page was built using the Divi Page Builder module and includes the various Divi tags in the content such as:
[et_pb_section fb_built=”1″ _builder_version=”4.6.0″ _module_preset=”default” module_alignment=”center” min_height=”627px” custom_padding=”||1px|||”]
I was wondering if there was a way of ensuring that the WordPress API can compile/render the full HTML generated by these tags before it's sent back via JSON to my front-end application?
Thanks very much for your time
Looks like shortcodes.
You could try to work with apply_filters()
Source: https://developer.wordpress.org/reference/hooks/rest_post_dispatch/
To filter the shortcodes to actual HTML use the do_shortcode() function.
Source: https://developer.wordpress.org/reference/functions/do_shortcode/

How do I set Ghost Blog Custom Routes.yaml Collection Title / Meta Description in my custom template?

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.

Internal Tag Parsing in Ghost

Within ghost if I use the following to display all internal tags,
{{#get "tags" limit="all"}}
{{#foreach tags visibility="internal"}}
{{name}}
{{/foreach}}
{{/get}}
How do I display a tag that has a certain string and then string off the beginning.
i.e I want to add an internal tag of:
#META:Cisco / ASA / 8.2.1
But to print Cisco / ASA / 8.2.1 only
Nice question. :)
Unfortunately, I don't think you can do this simply using the built-in features, but you
can create a custom app that registers a custom helper that can do this.
Here's how to do that:
Install the ghost-app package to your Ghost installation
Check out the docs on how to create an app.
Create the app. :)
Modify gscan to recognize your helper.
Since I found your question interesting, I implemented this app myself. You can view and download the source code from here: https://github.com/conwid/RemovesubstringApp
I also wrote a little blog post about how I created it and how you can set it up and modify gscan in detail here: https://dotnetfalcon.com/stackoverflow-adventures-creating-custom-ghost-helpers-using-apps/
With my version, you'll be able to write this in your templates:
{{#get "tags" limit="all"}}
{{#foreach tags visibility="internal"}}
{{removeSubstring name '#META:'}}
{{/foreach}}
{{/get}}
Hope this helps, if you have problems with the implementation or the setup, feel free to ask.

How do I place a configurable meme at the bottom of the index page in ghost?

I'm working on a blog for a friend of mine who wants to put a meme picture at the bottom of the index page.
So the simplest way is to edit the template and reference it from there.
The problem is, it's not user friendly to keep editing and uploading a new template.
So I had this idea that I could create a static page and place it on that page and reference it from the template. But I see that when you upload an image to ghost.io it generates a name based on the date path. That's not going to work for a fixed URL in the template.
Another option might be to use the tags. As tags allows you to put a picture and has a URL. But I tried that it also has similar problems.
How can I make this work nicely?
Don't reference image URL in your theme. Reference page slug and load its content, which would be just an image.
Example with Ghost Handlebars API:
{{!-- If a static page "meme" exists - its content will be loaded here --}}
{{#get "posts" slug="meme" }}
{{#foreach posts}}
<div>
{{content}}
</div>
{{/foreach}}
{{/get}}

How do I create and link Pages in Wordpress? (not the Pages that can be created inside the Wordpress Admin)

I would like to create a fully functional page within my WordPress application (which will have jQuery and other stuff). The problem is that when I create a file within my theme/starkers (I'm using the Starkers Theme) directory let say about.php the following links (in my index.php) don't work:
<li>About</li> <-- Fatal error: Call to undefined function get_header()
<li>About</li> <-- site not found
What's the best way of doing this becasue I think I can't add PHP and jQuery and other complex stuff inside the Pages that can be created in Wordpress Admin.
Any suggestions?
What's the best way of doing this becasue I think I can't add PHP and jQuery and other complex stuff inside the Pages that can be created in Wordpress Admin.
Why not? Just make a custom page template inside your theme, create a new page on your wp-admin, and assign that custom page template for your page. You should be able to customize that as much as you want.
Try a scan here : Wordpress Template Hierarchy : Pages
Try loading
require( '/path/to/your/wordpress/wp-load.php' );

Resources