nopCom v2.5 Customize default meta description tag content for ProductsByTag.cshtml

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 yıl önce
Google Webmaster tools complains of dozens of web pages which have duplicate meta descriptions.

Currently the following pages output the default meta description set in admin: Configuration > Settings > General And Miscellaneous Settings > SEO Settings

~\Presentation\Nop.Web\Views\Catalog\ProductsByTag.cshtml
~\Presentation\Nop.Web\Views\Catalog\RecentlyViewedProducts.cshtml
~\Presentation\Nop.Web\Views\Catalog\RecentlyAddedProducts.cshtml
~\Presentation\Nop.Web\Views\Catalog\CompareProducts.cshtml
~\Presentation\Nop.Web\Views\Customer\Login.cshtml

I can see the <meta name="description" content="@(Html.NopMetaDescription())" /> in ~\Presentation\Nop.Web\Views\Shared\_Root.cshtml\_Root.cshtml

Ideally I would like to overload this in the relevant .cshtml files as above and leave the rest of the .cshtml files alone.

Does anyone know how I should go about controlling the meta descriptions tag output on these pages?
11 yıl önce
1. Open an appropriate cshtml file
2. Use "AddTitleParts", "AddMetaDescriptionParts", and "AddMetaKeywordParts" extensions method.
P.S. Have a look at \Views\Catalog\CategoryTemplate.ProductsInGridOrLines.cshtml file to get an idea
11 yıl önce
Thanks a.m. - works perfectly!

Below is a fix that I think should be included in the next release. Simple SEO URL Encode that fixes spaces, ampersands, forward slashes etc. in product tags.

CREATE New Class file

~\Presentation\Nop.Web\Extensions\SeoUrlEncodeExtension.cs

START New Class


using System;
using System.Text;
using System.Web.Mvc;
using Nop.Core;
using Nop.Core.Infrastructure;

namespace Nop.Web.Extensions
{
    //LFW 15-06-2012 SEO URL Product Tags
    //SOURCE: http://www.dominicpettifer.co.uk/Blog/34/asp-net-mvc-and-clean-seo-friendly-urls
    public static class SeoUrlEncodeExtension
    {
        public static string ToSeoUrl(string stringToEncode)
        {
            stringToEncode = (stringToEncode ?? "").Trim().ToLower();

            StringBuilder url = new StringBuilder();

            foreach (char ch in stringToEncode)
            {
                switch (ch)
                {
                    case ' ':
                        url.Append('-');
                        break;
                    case '&':
                        url.Append("and");
                        break;
                    case '\'':
                        break;
                    default:
                        if ((ch >= '0' && ch <= '9') ||
                            (ch >= 'a' && ch <= 'z'))
                        {
                            url.Append(ch);
                        }
                        else
                        {
                            url.Append('-');
                        }
                        break;
                }
            }

            return url.ToString();
        }

    }
}


END New Class


MODEL

ADD  SeoUrlName property to ProductTagModel class

//LFW 15-06-2012 SEO URL Product Tags
public string SeoUrlName { get; set; }

~\Presentation\Nop.Web\Models\Catalog\ProductTagModel.cs


CONTROLLER

ADD line below 'Name = x.Name,' to ProductTagModel loop within public ActionResult ProductTags(int productId) within CatalogController class

SeoUrlName = SeoUrlEncodeExtension.ToSeoUrl(x.Name), //LFW 15-06-2012 SEO URL Product Tags

~\Presentation\Nop.Web\Controllers\CatalogController.cs


ADD line below 'Name = tag.Name,' to ProductTagModel loop within public ActionResult PopularProductTags() within CatalogController class

SeoUrlName = SeoUrlEncodeExtension.ToSeoUrl(tag.Name), //LFW 15-06-2012 SEO URL Product Tags

~\Presentation\Nop.Web\Controllers\CatalogController.cs


VIEWS

CHANGE Name to SeoUrlName in ProductTags view

                    <a href="@Url.RouteUrl("ProductsByTag", new { productTagId = Model[i].Id, SeName = Model[i].SeoUrlName })" class="producttag">

~\Presentation\Nop.Web\Views\Catalog\ProductTags.cshtml


CHANGE Name to SeoUrlName in PopularProductTags view

                            <li><a href="@Url.RouteUrl("ProductsByTag", new { productTagId = item.Id, SeName = item.SeoUrlName })" style="font-size:@(Model.GetFontSize(item))%;">@item.Name</a>&nbsp;&nbsp;

~\Presentation\Nop.Web\Views\Catalog\PopularProductTags.cshtml
11 yıl önce
Thanks!
11 yıl önce
Done. But a bit another way. See changeset 571cd2be1c68
11 yıl önce
a.m. wrote:
Done. But a bit another way. See changeset 571cd2be1c68


Yeah, That's a more elegant multi-lingual solution.

How are the & and / symbols treated? Are they replaced with a code or stripped or replaced with a hyphen or 'and' like mine?
11 yıl önce
They're removed. Have a look at \Libraries\Nop.Services\Seo\SeoExtensions.cs file, GetSeName(string name, bool convertNonWesternChars, bool allowUnicodeCharsInUrls, bool urlEncode = false) method for more info
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.