how to get all posts on post.hbs page in ghost - ghost-blog

I want all posts on post.hbs but it's not displaying any post list, I want check title with my string and display particular post on post.hbs.
Below code is not working in post.hbs
{{#foreach posts}}
<p>{{content}}</p>
{{/foreach}}`
Its not working on post.hbs page

Post.hbs is for displaying a specific post, so you are in {{post}} scope:
{{#post}}
{{/post}}
You can try something like this:
{{#get "posts" limit="all" as |allposts| }}
{{#foreach allposts}}
{{content}}
{{/foreach}}
{{/get}}

Related

Filter Ghost Homepage with specific tags

I use Ghost 3.0.2
I would like to limit first page (index.hbs) to display only posts with some tags.
I tryed without luck:
{{#foreach posts}}
{{#has tag="es"}}
{{> post}}
{{/has}}
{{/foreach}}
Current code is:
<!-- start content area -->
<div class="main-content-area">
<div class="container post-listing">
{{> loop}}
</div>
</div>

How to list pages in Ghost CMS?

I'm trying to show pages on my homepage.
In my home.hbs I have
{{!-- The tag above means: insert everything in this file
into the {body} of the default.hbs template --}}
{{#is "home"}}
{{#if #site.description}}
<header class="page-head">
<h2 class="page-head-title">{{#site.description}}</h2>
</header>
{{/if}}
{{/is}}
{{#get "posts" filter="page:true"}}
{{#foreach posts}}
{{title}}
<p>{{excerpt words="33"}}</p>
{{/foreach}}
{{/get}}
Nothing is listed on my homepage. This works for posts but not pages for some reason.
I have the article featured, and it has "Category" tag - is it possible to display these on the homepage?
You're almost there, try this:
{{#is "home"}}
{{#if #site.description}}
<header class="page-head">
<h2 class="page-head-title">{{#site.description}}</h2>
</header>
{{/if}}
{{/is}}
{{#get "pages" limit="all"}}
{{#foreach pages}}
{{title}}
<p>{{excerpt words="33"}}</p>
{{/foreach}}
{{/get}}
Hope this helps :)

have any way to change tag name dynamically in get query ?

{{#get "posts" filter="tag:news" as |news_post|}}
{{#foreach news_post}}
{{title}}
{{/foreach}}
{{/get}}
How Can I Change "news" tag dynamically ?
By your question I suggest you want to base it on some that within your .. post perhaps ? You can use it within the {{post}} by using the {{tags.[0].slug}}
{{#get "posts" filter="tag:{{tags.[0].slug}}" include="tags" as |news_post|}}
{{#foreach news_post}}
- {{title}} - {{tags.[0].slug}}<br>
{{/foreach}}
{{/get}}

Featured posts on front page

How can display featured posts at the top of the front page?
Followed by the remaining posts.
Currently they display at the top of each page of the pagination.
Here's my loop.hbs:
{{! Previous/next page links - only displayed on page 2+ }}
<div class="extra-pagination inner">
{{pagination}}
</div>
{{! This is the post loop - each post will be output using this markup }}
{{#foreach posts}}
{{#if featured}}
<article class="{{post_class}} featured">
<header class="post-header">
<h2 class="post-title">{{{title}}}</h2>
</header>
<section class="post-excerpt">
<p>{{excerpt words="26"}} <a class="read-more" href="{{url}}">»</a></p>
</section>
<footer class="post-meta">
{{#if author.image}}<img class="author-thumb" src="{{author.image}}" alt=" {{author.name}}" nopin="nopin" />{{/if}}
{{author}}
{{tags prefix="on"}}
<time class="post-date" datetime="{{date format='YYYY-MM-DD'}}">{{date format="DD MMMM YYYY"}}</time>
</footer>
</article>
{{/if}}
{{/foreach}}
{{! This is the post loop - each post will be output using this markup }}
{{#foreach posts}}
{{#unless featured}}
<article class="{{post_class}}">
<header class="post-header">
<h2 class="post-title">{{{title}}}</h2>
</header>
<section class="post-excerpt">
<p>{{excerpt words="26"}} <a class="read-more" href="{{url}}">»</a></p>
</section>
<footer class="post-meta">
{{#if author.image}}<img class="author-thumb" src="{{author.image}}" alt=" {{author.name}}" nopin="nopin" />{{/if}}
{{author}}
{{tags prefix="on"}}
<time clas s="post-date" datetime="{{date format='YYYY-MM-DD'}}">{{date format="DD MMMM YYYY"}}</time>
</footer>
</article>
{{/unless}}
{{/foreach}}
{{! Previous/next page links - displayed on every page }}
{{pagination}}
Here's my blog: http://netsca.pe/
The only featured post currently is How to Install Ghost on AWS | Amazon EC2 for free - the Complete Guide.
As you can see, it is displayed at the top of the third page of posts, as opposed to at the top of the front page.
I had a read of Stack Overflow: newest post with specific tag on the front page but still can't figure this out.
Also had a read through this: The Ghost Blogging Support Forum: Show Featured post first on index page
but still nowhere.
variations of {{get}} were not successful for me on the latest version of Ghost. What did work was:
<section id="main">
{{#foreach posts}}
{{#if featured}}
html for featured posts
{{/if}}
{{/foreach}}
<div>
{{#foreach posts}}
{{^if featured limit="2"}}
html for regular post loop
{{/if}}
{{/foreach}}
</div>
</section>
This displayed the featured posts on top while another separately styled loop of posts were displayed below.
Firstly credit to #subic from ghost.slack.com who kindly tested my theme and pointed me in the right direction.
After having a read of the lengthy discussion GitHub Ghost Issue: Query (get) helper #4439 recently closed, great news - helpers and filters are being added to Public API v1!
The {{#get}} helper #5619 has just been merged to master (still unstable), so the solution:
{{#get "posts" featured="true" as |featured|}}
{{#foreach featured}}
...
{{/foreach}}
{{/get}}

Wordpress, build a template for a post

I would like to know how can I define a post template and adding automatically the html layout when we are creating a post?
Do I have to use custom fields?
For example:
Post content:
Title
Description 1
Description 2
With links and social media
Html layout result:
<h1 class="work-title">Title</h1>
<div class="description">Description 1</div>
<div class="description">Description 2</div>
<div class="details">With links and social media</div>
</div>
Thanks
You could alter the output of the function the_content() by using (in functions.php) something like:
function alter_content($content) {
// Alter the $content variable here
return $content;
}
add_filter( 'the_content', 'alter_content', 6);
Which will alter the content before the paragraphs are added. And if you don't want paragraphs at all use:
remove_filter('the_content', 'wpautop');
Check out the codex page on apply_filters() for more info on the function.

Resources