Querying for blog posts via tag.

35 views
Skip to first unread message

con...@hivemindcomedy.com

unread,
Apr 13, 2015, 6:05:30 PM4/13/15
to apostr...@googlegroups.com
How can I go about returning only posts of a certain tag?

I've tried:

{{ renderBlogListings(pieces, {tags: 'data'}) }}

In index.html of the blog module, but to no avail.

Tom Boutell

unread,
Apr 13, 2015, 6:11:28 PM4/13/15
to apostr...@googlegroups.com
templates are synchronous, and fetching things is asynchronous. So you need to get all your data-fetching needs out of the way before you come to nunjucks.

Are you using apostrophe-blog, or apostrophe-blog-2?


--
You received this message because you are subscribed to the Google Groups "apostrophenow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apostropheno...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--


THOMAS BOUTELL, DEV & OPS
P'UNK AVENUE | (215) 755-1330  |  punkave.com

con...@hivemindcomedy.com

unread,
Apr 13, 2015, 6:14:36 PM4/13/15
to apostr...@googlegroups.com
Apostrophe blog 2

Tom Boutell

unread,
Apr 13, 2015, 7:36:47 PM4/13/15
to apostr...@googlegroups.com
Normally index.html's job is to list all blog posts, unless someone has intentionally filtered them, for instance by adding:

?tag=whatever

To the URL.

Perhaps that's all you're really looking to do, in which case my job is done here (:

The default index.html template doesn't include filtering by tag, but you can easily implement it because the backend already supports it, and an array of all of the distinct tags is already available as piecesTags when coding index.html.

con...@hivemindcomedy.com

unread,
Apr 13, 2015, 9:27:59 PM4/13/15
to apostr...@googlegroups.com
How would I go about querying for it not in the url?

Tom Boutell

unread,
Apr 13, 2015, 11:00:18 PM4/13/15
to apostr...@googlegroups.com
How will you know which tag to search for, if not via the URL?

If you only want posts with a certain tag to appear at all, with that tag being determined in advance, you can lock the page down (via page settings) to display content from particular blogs that has particular tags, in addition to anything posted directly to that particular blog.

con...@hivemindcomedy.com

unread,
Apr 13, 2015, 11:51:55 PM4/13/15
to apostr...@googlegroups.com
If you only want posts with a certain tag to appear at all, with that tag being determined in advance, you can lock the page down (via page settings) to display content from particular blogs that has particular tags, in addition to anything posted directly to that particular blog.

 
Any chance I can get an example config of this?

Tom Boutell

unread,
Apr 14, 2015, 9:16:01 AM4/14/15
to apostr...@googlegroups.com
1. Go to your blog
2. Click "blog settings"


3. Scroll down and set up "And from these blogs"


Basically the idea is to set up more than one blog on the site, but also use "and from these blogs" to pull content to a "main" blog page if you want to, filtering each individual blog you're pulling in by tag if you want to.

Maybe this meets your needs and maybe it doesn't - if not, please describe what you are really trying to accomplish. I suggest telling a "user story" - what the user is supposed to experience.

con...@hivemindcomedy.com

unread,
Apr 14, 2015, 4:27:19 PM4/14/15
to apostr...@googlegroups.com
Here is my user story.

User visits blog of website. Blog has a list of featured posts tagged with "featured". Underneath the featured listing is another listing of all blog posts sorted chronologically.

If the user can log in, they should be able to create a post and tag it with "featured" to get it to show in the featured posts listing.

con...@hivemindcomedy.com

unread,
Apr 14, 2015, 5:13:36 PM4/14/15
to apostr...@googlegroups.com
So basically I'd like to have a section of the template only include a query or what have you for posts that have the "featured" tag.

Tom Boutell

unread,
Apr 14, 2015, 5:25:56 PM4/14/15
to apostr...@googlegroups.com
Oh good, that's an easy one (:

In lib/modules/apostrophe-blog-2/views/index.html:

aposSingleton(page, 'featured', 'blog')

This will add a "blog widget" to the page. The site administrator can log in, click "edit" and configure it to show posts from a particular blog with a particular tag.


--
You received this message because you are subscribed to the Google Groups "apostrophenow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apostropheno...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

con...@hivemindcomedy.com

unread,
Apr 14, 2015, 6:13:50 PM4/14/15
to apostr...@googlegroups.com
Much thanks!
Reply all
Reply to author
Forward
0 new messages