Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Blog Module /

Discuss the Blog Module.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Looping over Blog Posts of a Certain Category giving duplicated results.


Go to End


1223 Views

Avatar
bcapel

Community Member, 3 Posts

11 October 2016 at 4:36pm

Hi,
so I am trying to show two blog posts of a certain category on one of my page templates. I have managed to write a function that pulls in all blog posts and makes them accessible via the page and then I have the below code on the template to render out just 2 posts with the correct category of "Business-Featured". which works, however, it seems to be running the loop twice as it is bringing in both posts twice. can anyone see where I have gone wrong?

		<% if $RecentNews %>
			<% loop $RecentNews %>
				<% loop $Categories %>
					<% if $Title ="Business-Featured" %>		
						<% loop blogPosts.Limit(2) %>
							<div class="col-md-6">
								$FeaturedImage.CroppedImage(555, 144)
								<div class="post-preview">
									<h3><a href="$Link">$Title</a></h3>
									<p>$Summary <a href="$Link" style="display: inline;">Read More...</a></p>
								</div>
							</div>
						<% end_loop %>
					<% end_if %>
				<% end_loop %>
			<% end_loop %>
		<% end_if %>