如何为 BlogEngine.net 创建一个扩展来访问帖子是否属于某个类别?
我正在使用 blogengine.net。 如果特定帖子属于特定类别,我想在 H1 中显示默认图像。 例如,如果帖子属于播客类别,我想显示一张图像,如果帖子属于博客类别,我想显示另一张图像。
我已经掌握了CSS,我想做的就是更改类,即: 基于类别,但为了这样做我需要知道帖子是否属于某个类别。
我开始为 POST_SERVING 事件构建扩展,但没有 Post.IsInCategory 方法。 除非在源代码中创建我自己的方法,有人可以建议更好的方法吗?
I'm using blogengine.net. I would like to show a default image in the H1 if a particular post is in a particular category. For instance if a post is in the Podcasts category I'd like to display one image and if a post is in the Blog category I'd like to display another.
I have the CSS figured all, all I want to do is change the class, ie: <h1 class="CHANGE"></h1>
based on the category, but in order to do so I need to know whether a post is in a category or not.
I started building an extension for the POST_SERVING event, but there is no Post.IsInCategory method. Barring creating my own method in the Source, can someone suggest a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的扩展连接到 Post_Serving 事件,则传递给 EventHandler(发送者)的第一个参数是 Post 对象。 如果将其转换为帖子,则可以访问当前帖子的类别属性。
If your extension is wired to the Post_Serving event, then the first argument that gets passed to your EventHandler (sender) is a Post object. If you cast it as Post, then you can access the Categories property of the current post.