Get all Creator Names but list them only once Razor
I am trying to make my own blog. I don't want to use uBlogsy or Blog4Umbraco. I know how to get all the CreatorNames of a specific Nodes, I just need to know how to list them only once vs listing them all for all items. The code below is currently what I am using but I need to know how to list each Creator Name only once. Thanks
I have it started by
<ul> @foreach(var item in @Model.NodeById(1089).Descendants("ScienceResearchUpdatesPost").OrderBy("CreatorName")){ <li>@item.CreatorName</li> } </ul>
And took it apart. This is what I did using a part of their example. I think I was missing a step somewhere. Thanks for getting back to me. If you have a simpler way or if you see antying that is not necessary in the code, please let me know.
string creatorList = "";
<ul> @foreach(dynamic node in @Model.NodeById(1089).Descendants("ScienceResearchUpdatesPost").OrderBy("CreatorName")) { if (creatorList != node.CreatorName) { <li>@node.CreatorName</li> } creatorList = node.CreatorName; } </ul>
One more question. Now that I have the CreatorName list. I was wondering how I would build a Querystring to show the nodes only shown by a selected name.
I am using the base pagination Macro and currently have all items of the certain NodeTypeAlias listing. I now have all of the CreatorNames
How would I filter these once a name is selected?
I tried to make a simple query string but I don't know what to do with it after I have made it. Any help is appreciated.
This is my build query string
var baseNode = @Model.AncestorOrSelf("DWTBlogLanding"); <h3>@Dictionary.DWTAuthors</h3> string creatorList = ""; <ul> @foreach(dynamic node in @Model.NodeById(1089).Descendants("ScienceResearchUpdatesPost").OrderBy("CreatorName")) { if (creatorList != node.CreatorName) { <li><a href="@[email protected]">@node.CreatorName</a></li> } creatorList = node.CreatorName; }
</ul>
Here is my base page that lists the posts of that NodeTypeAlias.
var pagesToList = @Model.NodeById(1089).Descendants("ScienceResearchUpdatesPost").OrderBy("CreateDate desc");
// configuration var itemsPerPage = String.IsNullOrEmpty(Parameter.ItemsPerPage) ? 3 : int.Parse(Parameter.ItemsPerPage); var previousLabel = String.IsNullOrEmpty(Parameter.PreviousLabel) ? "Previous" : Parameter.PreviousLabel; var nextLabel = String.IsNullOrEmpty(Parameter.NextLabel) ? "Next" : Parameter.NextLabel;
// paging calculations var numberOfItems = pagesToList.Count(); int currentPage = 1; if (!int.TryParse(HttpContext.Current.Request.QueryString["Page"], out currentPage)) { currentPage = 1; } currentPage--; var numberOfPages = numberOfItems % itemsPerPage == 0 ? Math.Ceiling((decimal)(numberOfItems / itemsPerPage)) : Math.Ceiling((decimal)(numberOfItems / itemsPerPage))+1;
<p> Total Items: @numberOfItems <br /> Items per Page: @itemsPerPage<br /> Pages: @numberOfPages;<br /> Current Page: @(currentPage) </p>
var baseNode = @Model.AncestorOrSelf("DWTBlogLanding"); <ul class="dwtPostList"> @foreach(var item in pagesToList.Skip(currentPage*itemsPerPage).Take(itemsPerPage)) {
<li> <h3> <a href="http://umbcarlos.dmns.org/@(baseNode.Url)Post/?nid=@(item.Id)&cid=1">@item.Name</a> @*<a href="@item.Url"> @item.Name </a>*@ </h3> @*TODO - Add link to creator name for query string URLing*@ <div class="dwtPosted">Posted @item.CreateDate by @item.CreatorName</div> @*Cant get bodyText to show on paging*@
Get all Creator Names but list them only once Razor
I am trying to make my own blog. I don't want to use uBlogsy or Blog4Umbraco. I know how to get all the CreatorNames of a specific Nodes, I just need to know how to list them only once vs listing them all for all items. The code below is currently what I am using but I need to know how to list each Creator Name only once. Thanks
I have it started by
Hi Carlos
If I understand your question correctly you should be able to use Distinct like Tom does in this post perhaps? http://our.umbraco.org/forum/developers/razor/27295-Find-and-count-unique-values-in-a-dynamicNodeList-
/Jan
Jan, I actually found what I was looking for. I found another post
http://our.umbraco.org/forum/developers/razor/19020-Is-there-something-like-'GroupBy'?p=0#comment120345
And took it apart. This is what I did using a part of their example. I think I was missing a step somewhere. Thanks for getting back to me. If you have a simpler way or if you see antying that is not necessary in the code, please let me know.
string creatorList = "";
<ul>
@foreach(dynamic node in @Model.NodeById(1089).Descendants("ScienceResearchUpdatesPost").OrderBy("CreatorName"))
{
if (creatorList != node.CreatorName)
{
<li>@node.CreatorName</li>
}
creatorList = node.CreatorName;
}
</ul>
Jan,
One more question. Now that I have the CreatorName list. I was wondering how I would build a Querystring to show the nodes only shown by a selected name.
I am using the base pagination Macro and currently have all items of the certain NodeTypeAlias listing. I now have all of the CreatorNames
How would I filter these once a name is selected?
I tried to make a simple query string but I don't know what to do with it after I have made it. Any help is appreciated.
This is my build query string
var baseNode = @Model.AncestorOrSelf("DWTBlogLanding");
<h3>@Dictionary.DWTAuthors</h3>
string creatorList = "";
<ul>
@foreach(dynamic node in @Model.NodeById(1089).Descendants("ScienceResearchUpdatesPost").OrderBy("CreatorName"))
{
if (creatorList != node.CreatorName)
{
<li><a href="@[email protected]">@node.CreatorName</a></li>
}
creatorList = node.CreatorName;
}
</ul>
Here is my base page that lists the posts of that NodeTypeAlias.
var pagesToList = @Model.NodeById(1089).Descendants("ScienceResearchUpdatesPost").OrderBy("CreateDate desc");
// configuration
var itemsPerPage = String.IsNullOrEmpty(Parameter.ItemsPerPage) ? 3 : int.Parse(Parameter.ItemsPerPage);
var previousLabel = String.IsNullOrEmpty(Parameter.PreviousLabel) ? "Previous" : Parameter.PreviousLabel;
var nextLabel = String.IsNullOrEmpty(Parameter.NextLabel) ? "Next" : Parameter.NextLabel;
// paging calculations
var numberOfItems = pagesToList.Count();
int currentPage = 1;
if (!int.TryParse(HttpContext.Current.Request.QueryString["Page"], out currentPage)) {
currentPage = 1;
}
currentPage--;
var numberOfPages = numberOfItems % itemsPerPage == 0 ? Math.Ceiling((decimal)(numberOfItems / itemsPerPage)) : Math.Ceiling((decimal)(numberOfItems / itemsPerPage))+1;
<p>
Total Items: @numberOfItems <br />
Items per Page: @itemsPerPage<br />
Pages: @numberOfPages;<br />
Current Page: @(currentPage)
</p>
var baseNode = @Model.AncestorOrSelf("DWTBlogLanding");
<ul class="dwtPostList">
@foreach(var item in pagesToList.Skip(currentPage*itemsPerPage).Take(itemsPerPage))
{
<li>
<h3>
<a href="http://umbcarlos.dmns.org/@(baseNode.Url)Post/?nid=@(item.Id)&cid=1">@item.Name</a>
@*<a href="@item.Url">
@item.Name
</a>*@
</h3>
@*TODO - Add link to creator name for query string URLing*@
<div class="dwtPosted">Posted @item.CreateDate by @item.CreatorName</div>
@*Cant get bodyText to show on paging*@
@*
@item.bodyText
*@
<div class="dwtBtnHolder">
<a href="@item.Url" class="buyNowBtn">Read More</a>
</div>
</li>
}
</ul>
<div class="pagingPages">
@{
// Google style paging links
if (currentPage > 0) {
<a href="?page=@(currentPage)">« @previousLabel</a>
} else {
<span class="pagingDisabled">« @previousLabel</span>
}
var Pages = Enumerable.Range(1, (int)numberOfPages);
foreach(var number in Pages) {
if (number-1 != currentPage) {
<a href="?page=@number">@number</a>
} else {
<span class="dwtPagingCurrent">@number</span>
}
}
if (currentPage < Pages.Count()-1) {
<a href="?page=@(currentPage+2)">@nextLabel »</a>
} else {
<span class="pagingDisabled">@nextLabel »</span>
}
}
</div>
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.