-
Hi there!
Firstly, posts were displayed with the help of the
But there were many duplicates of posts in each row so I decided to display only unique posts in random order.
Which pulls all posts, divides them into three parts and then I send each piece to the corresponding heroX view. Each hero has the same code (I’ve removed unnecessary parts):
The problem: the new posts array doesn’t have a URL string, it’s null. The title, and images are displayed, but not not the |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 19 replies
-
In the Winter.Blog plugin, the Post model does not have a If you have a static entry path, you can use the <a href="/path/{{ post.slug }}" class="hero-link">
<h4>{{ post.title }}</h4>
</a> The Post model also has a wn-blog-plugin/models/Post.php Lines 717 to 740 in 4a14a17 You can use this data to create a URL for links in PHP code or do it like this in Twig: {% set urlParams = post.getUrlParams() %}
<a href="/{{ urlParams.category }}/{{ urlParams.slug }}" class="hero-link">
<h4>{{ post.title }}</h4>
</a> I don’t use the Winter.Blog plugin, so need to check what data the method returns and how to form a path from it. |
Beta Was this translation helpful? Give feedback.
-
Thank you!
Throws this error:
|
Beta Was this translation helpful? Give feedback.
-
The error is due to the fact that when calling the method you need to specify a parameter - the CMS page that displays the post. {% set urlParams = post.getUrlParams('here_is_the_post_cms_page') %}
<a href="/{{ urlParams.category }}/{{ urlParams.slug }}" class="hero-link">
<h4>{{ post.title }}</h4>
</a> |
Beta Was this translation helpful? Give feedback.
-
Emm, still can't make it work :) Something is wrong on my side.
|
Beta Was this translation helpful? Give feedback.
-
The Posts component sets the url property here: https://github.com/wintercms/wn-blog-plugin/blob/main/components/Posts.php#L213-L222 Refer to that for how to properly set your URLs since you're interacting with the model instances directly instead of having the component take care of that for you. |
Beta Was this translation helpful? Give feedback.
-
@LukeTowers , you suggest to modify this code with properties from here ( property ) :
and then call the |
Beta Was this translation helpful? Give feedback.
-
@LukeTowers , thank you!
But in template the |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Hi @LukeTowers , |
Beta Was this translation helpful? Give feedback.
In the Winter.Blog plugin, the Post model does not have a
url
field or property.If you have a static entry path, you can use the
slug
field:The Post model also has a
getUrlParams
method, which returns an array of parameters for forming the URLwn-blog-plugin/models/Post.php
Lines 717 to 740 in 4a14a17