Very Confused About Displaying Posts on Homepage - Please Help
Hi All,
First, off, I've just got uBlogsy 2.1.1.0 running and customized to the site and I'm rather happy considering I'm new to Umbraco and I'm not a coder. I love uBlogsy so far. I've installed the blog as a child of the homepage (see http://www.mccanninvestigations.com/blog.aspx) and it is running fine.
Now I want to feature the first few posts on the site homepage and I've inserted the macro in the Home template but just get 'Latest Posts' and that's it. Reading the forums I understand that I need to specify the ID of the homepage in the uBlogsyListPosts.cshtml file but I'm just getting lost in all the different codes.
On top of this the site owner would like to display posts from specific categories on some other pages as well but I'm even more lost there.
Can someone tell me what I need to edit in the following code which is the original code for uBlogsyListPosts.cshtml:
@using System.Linq
@using System.Xml.Linq
@using umbraco.MacroEngines
@using uBlogsy.Common.Extensions
@using uBlogsy.Common.Helpers
@using uBlogsy.BusinessLogic
@{
const int ITEMS_PER_PAGE = 20; // for testing
// get item count
int count = int.Parse(@Parameter.ItemCount);
IEnumerable<DynamicNode> nodes;
if (@Parameter.Small == "1")
{
var posts = PostService.Instance.GetPosts(Model.Id);
nodes = ((IEnumerable<DynamicNode>)posts).Take(count);
<div class="uBlogsy_posts_container uBlogsy_bottom_border">
<h2>@Dictionary["uBlogsyDicPostsLatest"]</h2>
<ul>
@foreach (DynamicNode n in nodes)
{
<li>
<a href="@n.Url" title="@n.GetProperty("uBlogsyContentTitle").Value">
<span>@n.GetProperty("uBlogsyContentTitle").Value</span>
</a>
@* - <span>@n.GetProperty("uBlogsyPostDate").Value.FormatDateTimeOrdinal("d MMMM yyyy")</span>*@
</li>
}
</ul>
</div>
}
else
{
// get tag, category, or author from query string
var tag = Request.QueryString["tag"];
var category = Request.QueryString["category"];
var author = Request.QueryString["author"];
var searchTerm = Request.QueryString["search"];
var commenter = Request.QueryString["commenter"];
int page = int.TryParse(Request.QueryString["page"], out page) ? page : 1;
IEnumerable<DynamicNode> posts = PostService.Instance.GetPosts(Model.Id, tag, category, author, searchTerm, commenter, page - 1, count);
// get landing node
var landing = DataService.Instance.GetLanding(Model.Id);
// only get posts where the path has the landing node's id.
posts = posts.Where(x => x.Path.Contains(landing.Id + ","));
nodes = posts.Take(count).ToList();
int postCount = PostService.Instance.GetPosts(Model.Id, tag, category, author, searchTerm, commenter, 0, int.MaxValue).Count;
// pagination
@RenderPagination(page, postCount, count)
// render search result count when this script is displaying search results
if (!string.IsNullOrEmpty(searchTerm))
{
<script type="text/javascript">
$(document).ready(function () {
$('.uBlogsy_content_body').hide();
});
</script>
<h3>@nodes.Count() Results: </h3>
}
// show each post
foreach (DynamicNode n in nodes)
{
@RenderPage("/macroScripts/uBlogsy/uBlogsyShowPost.cshtml", n.Id)
}
}
}
@helper RenderPagination(int page, int postCount, int itemsPerPage)
{
int pages = (int)Math.Ceiling((double)postCount / (double)itemsPerPage);
string url = Request.Url.ToString();
string querystring = Request.Url.Query;
<ul id="uBlogsy_pagination">
@* render prev link *@
<li class="uBlogsy_page_prev">
@if (page > 1)
{
url = url.ReplaceQueryStringItem("page", (page - 1).ToString());
<a href="@url" >Prev</a>
}else{
<span>Prev</span>
}
</li>
@* render page links *@
@for (int i = 1; i < pages+1; i++)
{
url = url.ReplaceQueryStringItem("page", i.ToString());
string liClass = i == page ? "uBlogsy_current" : string.Empty;
<li class="uBlogsy_page_item @liClass">
@if(page == i){
<span>@i</span>
}else{
<a href="@url">@i</a>
}
</li>
}
@* render next link *@
<li class="uBlogsy_page_next">
@if (page < Math.Ceiling((double)postCount/itemsPerPage))
{
url = url.ReplaceQueryStringItem("page", (page + 1).ToString());
<a href="@url" >Next</a>
}
else
{
<span>Next</span>
}
</li>
</ul>
}
Hi, back with a quick update. I managed to get posts on the first page but I'm not seeing the post summaries - there is just a bullet list of post titles. Any ideas?
Now I would like to have posts appear in the same way on other pages but restrict them by a category name so that the user can state which latest 3 posts from their chosen category name will display on their chosen internal page. How would I do this?
Okay, I've hit a brick wall. When I try adding the macro in the template I get an error on the live page. I've even copied the following code I used on the homepage of the site (which displays fine on the homepage):
The error I get displayed on the live page is 'Error loading MacroEngine script (file: /uBlogsy/uBlogsyListPosts.cshtml)' and I have no idea why. Becasue of this i can't check if what I'm trying to do using your code Heather is working.
In your web.config set umbracoDebugMode to true. Then back on your web site, put a ?umbDebugShowTrace=true at the end of the url. This should show the error at the bottom of the page
Wow, fastest reply ever...thanks! I wondered why I couldn't get the debugging to work, now that is fixed.
Okay so the errors shown ar as follows:
umbracoMacro
Error Loading Razor Script (file: uBlogsy - List Posts) Sequence contains no elements at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source) at ASP._Page_macroScripts_uBlogsy_uBlogsyListPosts_cshtml.Execute() in e:\HostingSpaces\dweiss\mccanninvestigations.com\wwwroot\macroScripts\uBlogsy\uBlogsyListPosts.cshtml:line 19 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) at System.Web.WebPages.WebPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage) at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
0.016061
0.001029
umbracoMacro
Loading IMacroEngine script [done]
0.016121
0.000059
umbracoMacro
Error loading MacroEngine script (file: /uBlogsy/uBlogsyListPosts.cshtml, Type: '' Sequence contains no elements at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
I modified that line according to recommendations here to tell the script the ID of the blog page to act as a reference point when displaying on the homepage. The modified version is a couple of line underneath...
Hi Heather (or anyone else), can I pay you to help me get this working? I've tried and failed and I just don't have the time to research further. I think it should be a very quick and easy job for you so please let me know along with your fee. You can email adam[at]atoznetventures.com if you are interested.
This is what I'm aiming for...
Add image functionality to blog so author can upload an image that appears in the post and also next to it on summary pages (like blog main page and category pages).
4 blog posts with summaries and images should be displayed on all other pages (except blog pages of course). The client should be able to choose which blog categories these posts are taken from and should display the latest first. You would also need to make sure that there are no posts displayed more than once. The client should also have the option to turn off the blog posts on a particular page so they are not displayed.
Very Confused About Displaying Posts on Homepage - Please Help
Hi All,
First, off, I've just got uBlogsy 2.1.1.0 running and customized to the site and I'm rather happy considering I'm new to Umbraco and I'm not a coder. I love uBlogsy so far. I've installed the blog as a child of the homepage (see http://www.mccanninvestigations.com/blog.aspx) and it is running fine.
Now I want to feature the first few posts on the site homepage and I've inserted the macro in the Home template but just get 'Latest Posts' and that's it. Reading the forums I understand that I need to specify the ID of the homepage in the uBlogsyListPosts.cshtml file but I'm just getting lost in all the different codes.
On top of this the site owner would like to display posts from specific categories on some other pages as well but I'm even more lost there.
Can someone tell me what I need to edit in the following code which is the original code for uBlogsyListPosts.cshtml:
I'd really appreciate all help.
Thanks!
Hi, back with a quick update. I managed to get posts on the first page but I'm not seeing the post summaries - there is just a bullet list of post titles. Any ideas?
Just add
To the part of @Parameter.Small = 1
This is the part that is rendered on the home page
Thanks Heather! That did it.
Now I would like to have posts appear in the same way on other pages but restrict them by a category name so that the user can state which latest 3 posts from their chosen category name will display on their chosen internal page. How would I do this?
No problem.
For pulling posts in via a category, you may have to duplicate the uBlogsyListPosts.cshtml
The way i have done it in the past, I have edited this line of code
So instead of category, i replaced it with the name of the category like below
You could create a new macro for each category you need. That;s the only way i'd know of doing it if thats any help to you.
Okay, I've hit a brick wall. When I try adding the macro in the template I get an error on the live page. I've even copied the following code I used on the homepage of the site (which displays fine on the homepage):
The error I get displayed on the live page is 'Error loading MacroEngine script (file: /uBlogsy/uBlogsyListPosts.cshtml)' and I have no idea why. Becasue of this i can't check if what I'm trying to do using your code Heather is working.
Any ideas?
Thanks.
Hi Adam,
In your web.config set umbracoDebugMode to true. Then back on your web site, put a ?umbDebugShowTrace=true at the end of the url. This should show the error at the bottom of the page
Wow, fastest reply ever...thanks! I wondered why I couldn't get the debugging to work, now that is fixed.
Okay so the errors shown ar as follows:
at ASP._Page_macroScripts_uBlogsy_uBlogsyListPosts_cshtml.Execute() in e:\HostingSpaces\dweiss\mccanninvestigations.com\wwwroot\macroScripts\uBlogsy\uBlogsyListPosts.cshtml:line 19
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors)
at System.Web.WebPages.WebPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)
at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
Sequence contains no elements
at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
could you post your code here too? Looks like there's an error in it so no items are pulling through
Here it is...
How come
Is commented out?
I modified that line according to recommendations here to tell the script the ID of the blog page to act as a reference point when displaying on the homepage. The modified version is a couple of line underneath...
Should I remove that commented line alltogether?
Hi Heather (or anyone else), can I pay you to help me get this working? I've tried and failed and I just don't have the time to research further. I think it should be a very quick and easy job for you so please let me know along with your fee. You can email adam[at]atoznetventures.com if you are interested.
This is what I'm aiming for...
I'll also put this in the 'Jobs' forum.
Thanks
is working on a reply...