This project is read-only.

Sorting Tags by Alphabeticall order before publishing on blogs

Topics: Customizing Orchard, General, Troubleshooting, Writing modules
Nov 9, 2011 at 8:04 PM

I want to sort tags(alphabeticall order)before displaying it on on all blogs
As per my understanding I have to change the driver query part in bold with below code

 public IEnumerable<IContent> GetTaggedContentItems(int tagId, int skip, int take, VersionOptions options) {
            return _orchardServices.

                .Where(tpr => tpr.Tags.Any(tr => tr.TagRecord.Id == tagId))
               .Join<CommonPartRecord>().OrderByDescending(x => x.CreatedUtc)
               .OrderBy(tpr => tpr.Tags.Get.(tr => tr.TagRecord.TagName))
                       .Slice(skip, take);
but it's giving me error can't convert string to bool.Is this correct or I am missing something.
need help with this.
Nov 9, 2011 at 9:02 PM
Edited Nov 9, 2011 at 9:07 PM

Oh, sorry, didn't see the error in there. The problem is that your Where condition is not returning a Boolean expression.

(also, please don't broadcast this under so many topics, this is not an announcement, it has nothing to do with core or installing; I'll edit your post out of those if you don't mind).

Nov 10, 2011 at 1:07 PM
Edited Nov 10, 2011 at 1:07 PM

Oh,Sorry for posting it in other topics.

Do you mean that order by is right and it should work for sorting?

Nov 10, 2011 at 8:18 PM

It *looks* ok from what I can tell, but you could make sure by looking at the stack trace or by attaching a debugger. When you ask a question of this sort it's always best to provide the full error message.

Nov 14, 2011 at 3:37 PM

This query is not working.Can you please test it and tell me what is wrong with it?

How to sort tags Alphabetically?

Nov 14, 2011 at 4:25 PM
Edited Nov 14, 2011 at 5:02 PM

This cannot be done directly at that level, but you could modify the Tags.ShowTags.cshtml like so:


@using System.Collections;
@using Orchard.Tags.Models;
    var tagsHtml = new List<IHtmlString>();
    foreach(var t in ((IEnumerable<TagRecord>)Model.Tags).OrderBy(t => t.TagName)) {
        if (tagsHtml.Any()) {
            tagsHtml.Add(new HtmlString(", "));
        tagsHtml.Add(Html.ActionLink((string)t.TagName, "Search", "Home", new { area = "Orchard.Tags", tagName = (string)t.TagName }, new { }));

@if (tagsHtml.Any()) {
    <p class="tags">
        @foreach(var htmlString in tagsHtml) { @htmlString }
Nov 14, 2011 at 4:38 PM
Edited Nov 15, 2011 at 1:42 PM

Thanks for the reply it's working,so happy