# 在搜索显示中添加点赞和浏览量

**URL:** <https://meta.discourse.org/t/add-likes-and-views-to-search-display/63368>\
**Category:** Support\
**Created:** [2017年五月25日 15:24 UTC](https://meta.discourse.org/t/add-likes-and-views-to-search-display/63368 "2017-05-25T15:24:43Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2017年五月25日 15:24 UTC](https://meta.discourse.org/t/add-likes-and-views-to-search-display/63368/1 "2017-05-25T15:24:43Z")

</div>

I’d like to add to the search page the number of likes and views a topic has received.

The json in `https://site.com/search.json?q=whatever` has the number of likes in the posts and for topics includes likes and views. I think it should be “easy” to pull that data out of the json payload and display it, but it’s still not easy for me.

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2017年五月25日 21:57 UTC](https://meta.discourse.org/t/add-likes-and-views-to-search-display/63368/2 "2017-05-25T21:57:57Z")

</div>

Can you please mock up what this would look like?

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2017年五月25日 22:03 UTC](https://meta.discourse.org/t/add-likes-and-views-to-search-display/63368/3 "2017-05-25T22:03:24Z")

</div>

No. I’m really bad at that. Here is instead some hand waving.

The the right of the title (“Discourse backup vs DO backup”, below) there would also be the number of likes and/or views the topic has gotten.

 ![](https://global.discourse-cdn.com/meta/original/3X/4/9/49f78eebe9171eafbb40840a6837eebc51e265f4.png)

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2017年五月25日 22:07 UTC](https://meta.discourse.org/t/add-likes-and-views-to-search-display/63368/4 "2017-05-25T22:07:31Z")

</div>

The hand waving is the easy part unfortunately.

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2017年五月26日 17:32 UTC](https://meta.discourse.org/t/add-likes-and-views-to-search-display/63368/5 "2017-05-26T17:32:03Z")

</div>

What I was asking for more generally, is how to pull a field out of the json load and display it. Do I need javascript to access the number of likes that’s in the json load for the page?

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [2017年五月26日 17:49 UTC](https://meta.discourse.org/t/add-likes-and-views-to-search-display/63368/6 "2017-05-26T17:49:06Z")

</div>

I believe the data is inside the posts model and there is a outlet for each result, so maybe you can get around it using this:

> [@Using Plugin Outlet Connectors from a Theme or Plugin](https://meta.discourse.org/t/adding-plugin-outlets-using-a-theme/32727):
>
> Discourse includes hundreds of Plugin Outlets which can be used to inject new content or replace existing contend in the Discourse UI. ‘Outlet arguments’ are made available so that content can be customized based on the context. Choosing an outlet To find the name of a plugin outlet, search Discourse core for “\<PluginOutlet”, or use the [plugin outlet locations](https://meta.discourse.org/t/plugin-outlet-locations-theme-component/100673) theme component. (e.g. topic-above-posts). Wrapper outlets Some outlets in core look like \<PluginOutlet @name="foo" /\>. These allow you…

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [2017年五月26日 17:50 UTC](https://meta.discourse.org/t/add-likes-and-views-to-search-display/63368/7 "2017-05-26T17:50:55Z")

</div>

By the way, the likes are displayed when you order by likes.

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2017年五月30日 18:20 UTC](https://meta.discourse.org/t/add-likes-and-views-to-search-display/63368/8 "2017-05-30T18:20:26Z")

</div>

Aha! That’s helpful, though for some reason the likes are not showing on that site when I sort by likes. They do here, though. I don’t see any CSS changes there.

> [@codinghorror](#):
>
> Can you please mock up what this would look like?

It’d look like this:

 ![](https://global.discourse-cdn.com/meta/original/3X/a/2/a267c0637fdb95f90287d759648cd6af34304eb7.png)

And the number of views might be to the right of the ❤ like `views: 123`.

Edit: but you’d not have to sort by likes to make it show up.

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2017年五月31日 17:13 UTC](https://meta.discourse.org/t/add-likes-and-views-to-search-display/63368/9 "2017-05-31T17:13:32Z")

</div>

Thanks, @falco. That’s what I was looking for. I’ll leave it to my client to implement it if he wants. 🙂

---

<div class="post-metadata">

**Author:** ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)\
**Post date:** [2024年六月8日 12:44 UTC](https://meta.discourse.org/t/add-likes-and-views-to-search-display/63368/10 "2024-06-08T12:44:39Z")

</div>

此主题已在 2570 天后自动关闭。不再允许回复。
