How to display all images from a blog article - shopware

I am trying to display all the images from a blog article in the blog listing page.
Currently it only displays the image marked as preview in the shopware backend > blog article configuration > Image configuration. But I also need to display the others if you select more than one.
I have been trying to modify the box.tpl file from the blog folder, the detail.tpl, and even the Blog.php file under Shopware > Controllers > Frontend but didn't have luck.
In the Blog.php file under the index method I saw this piece of code but not sure if this one does the trick
//adding thumbnails to the blog article
if (empty($blogArticle['media'][0]['mediaId'])) {
continue;
}
$mediaId = $blogArticle['media'][0]['mediaId'];
if (!isset($medias[$mediaId])) {
continue;
}
I am not a shopware expert so any tip would be appreciated.
Thanks.

You would need to write your own plugin and override the index method of the Blog Controller.
You can take a look at the Blog Controller's detailAction how to get all media images.
In your above example you're just getting the first image with [0], but you would need to loop trough all images like in the detailAction.
You may also have a look at the Shopware developer video trainings on Udemy and the Shopware developer documentation.

Related

Pagination in Big Commerce - Not Pre-Fixing correctly

I'm using a stencil theme in Big Commerce and am having an issue with the pagination buttons. When I click on the page number or next button, the site prefix is not adding an additional / to the end of the url.
The url should read as follows:
https://example.com/learn-more/?page=2
but clicking the buttons only links back to the main blog page:
https://example.com/learn-more/
I went through the "Store Front > Blog > {...} (settings) > About This Blog" and made sure the blog url was set to the correct format ( i.e.- /blog/ }, but that is not having the correct effect.
I'm gettting familiar with the stencil themes, but I'm lost on how to correct urls in this format, as the normal react fixes are not there...
Please Help
Yeah, same issue here. After playing with the blog settings like you did, I ended up applying a workaround by correcting the URLs via script just to fix it quickly.
const isBlogPostsPage = $('.blogPosts').length > 0;
if (isBlogPostsPage) {
$('.pagination-link').each(function() {
let link = $(this).attr('href');
link = link.replace('/articles?', '/articles/?');
$(this).attr('href', link);
});
}

Kentico 9 blog main page, archive page, and tag page

I'm new to Kentico, and have spent hours trying to make the blog work but haven't had any luck. Hope someone could help. I created a new blog by [a] using Pages > New Page > Blog; [b] then applying the Blog page template to it; [c] after that I created 2 sample blog posts. The only thing that works is the individual blog post. Other things don't work:
1- the blog main page --> empty
2- the blog archive page (for July) --> empty
3- tag link --> error message "Page /Blogs/My-blog-1.aspx was not found." Although I know I can change the tag link url, not sure what should be in there.
4 - making "Blog" appears on my nav (that I used CSS List menu web part). For this one, as a workaround, I was thinking about adding a blank "Blog" page and had it redirected to the blog url.
I've read the documentation related to Blog, but couldn't make it to work. Thanks for help!
Some of the out of the box templates are setup in such a way to only work on some of the example site templates which is why you're getting these results.
In the rptAllPosts repeater, set the Path property to ./%, ensure the Page types property is set to cms.blogpost, make sure you have a value in the Transformation property as well.
Should be resolved when you finish #1
You will have to modify the Selected Transformation. If you're using the default transformation, about line 9, way at the end you will need to modify the last parameter from ~/Blogs/my-blog-1.aspx to ~/Blog. This should fix the blog tag link.
Your work-around is very common and I'd stick with it for now.

How to change orchard blog home page list view/summary view

I have Orchard 1.7 setup with blog recipe.
The home screen display a list of blog posts.
I want to override the way the content is displayed in summary view. I could do this for each parts. But my styling is such that I need to wrap title, body, and meta tags with a special div when ever the display type is summary.
The problem is:
After shape tracing I understood that the template used in the home page (summary) is same as the detailed one.
Content.cshtml
For detail view I want to use the default core-> Views/Content.cshtml but for summary I need to supply my own. How can I do this?
OR
How to write a driver/widget to the home page. I know how I can do this for parts/fields/modules but I don't have an idea on how to create a driver for Blog home page.
Whenever I add a widget to the homepage the default blog post list still get displayed.
Just create a file called Content.Summary.cshtml in your theme. This will target all summary views, so if you have more than just blog posts on your site you will probably want to have Content-BlogPost.Summary.cshtml.
I wrote a small blog post on Item templates in Orchard if you are interested... http://arkleseizure.net/what-the-hell-is-an-item-template

Orchard query content items in my custom controller

The title pretty much sums it up. I created my own module in Orchard. I can access its actions via http requests like an ordinary controller in any MVC application.
I generated the controller using the command line interface and it came with IOrchardServices property that is populated in the constructor.
On my Orchard site I have a blog which I filled up with about 40 blog posts.
How can I query these blog posts from within my controller?
First I would like to start by saying: "read the source luke". You may find Orchard lacking in documentation and examples, but because it is open source, pretty much everything you want to know can be found there.
You should use the BlogPostService, inject that into your controller to get the blog posts you want.
https://orchard.codeplex.com/SourceControl/latest#src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogPostService.cs
You can see it being used in several controllers within Orchard.Blogs:
https://orchard.codeplex.com/SourceControl/latest#src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostController.cs
https://orchard.codeplex.com/SourceControl/latest#src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogAdminController.cs
Check out the code in the BlogPostService to see how it works, it is a little confusing because blogs are content items with blog posts underneath them. If you want to learn about simpler querying of content items I would check out how the BlogService works, it is a little easier to get to grips with:
https://orchard.codeplex.com/SourceControl/latest#src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogService.cs
Here is an example of what I was looking for:
var query = Services.ContentManager.Query();
var list = query.ForType(new []{"BlogPost"}).List();
var result = new List<dynamic>();
foreach (var contentItem in list) {
result.Add(new
{
title = contentItem.As<TitlePart>().Title, // dynamically typed: ((dynamic)contentItem).TitlePart.Title
text = contentItem.As<BodyPart>().Text
});
}

Liferay: How to fetch the first 3 items from an asset publisher?

In Liferay I have used the asset publisher to publish news on my news page. I want to fetch the 3 top news from the page and embed it into another page. How can I do this? The page URL containing the news links looks like the following:
Liferay.Widget({ url: 'http://test.com/testnews/101_INSTANCE_f22'});
Liferay itself has a property where one can share an asset publsiher instance any where else on a site, but that is not exactly what I want. So any help or guidance is appreciated. Thanks.
If you want only links then you can set display style 'title-list' (this will take you to the article on the main news page).
if you want to open the link in another page, change asset link behavior to 'View in a specific portlet'.
You can change the look of asset publisher to whatever design you want. follow the path look & feel --> advanced styling --> Copy the portlet id. Now by using mozilla firefox pick the class,tags,etc. and write your css code. This will override the basic design. E.g.
#p_p_id_101_INSTANCE_8f5JPIxv8ml0_ .asset-abstract {
width: 25%;
float: left;
}
Is there a particular reason why you don't want to configure another AssetPublisher on the second page? You can just use the identical configuration, but limit the number of results shown to 3 - done.
Problem solved. Here is the solution with jQuery:
$.get('http://test.com/news/', function(data) {
var top3links = $(data).find('a:lt(3)');
$('#top3').html(top3links); // });

Resources