Kyle_Risi
(Kyle Risi)
2019 年 1 月 4 日午前 9:26
1
Hi Guys,
Our HR team have decided to go with category boxes instead of a category list as below.
However, they also would like the latest topics to appear at the bottom of the categories as seen in revoluts community page
I am struggling to work out how this can be done, either as an existing setting or with CSS,
any ideas?
「いいね!」 2
Stranik
(Evgeny)
2019 年 1 月 4 日午前 11:49
2
Try to work with components
You can use: categories-and-latest-topics
In this mode, there is a connection and categories and recent topics.
<script type='text/x-handlebars' data-template-name='components/categories-and-latest-topics'>
<div class='column categories'>
{{categories-only categories=categories}}
</div>
<div class='column'>
{{categories-topic-list topics=topics filter="latest" class="latest-topic-list"}}
</div>
</script>
Next, you override: categories-only
<script type='text/x-handlebars' data-template-name='components/categories-only'>
The contents of the file...
</script>
Perhaps from this file it is necessary to move the box with the categories, or to do simply to change the css.
Options think very many.
https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/templates/components/categories-boxes.hbs
Useful material
「いいね!」 1
Another option is to simply structure your category directly
https://meta.discourse.org/c/howto
「いいね!」 4
Stranik
(Evgeny)
2019 年 1 月 4 日午後 12:10
4
Then just change the css, which is even easier. )
「いいね!」 2
Kyle_Risi
(Kyle Risi)
2019 年 1 月 4 日午後 12:17
5
Ideally I would prefer to do it like you have suggested, however, there isnt a way to display categories in a grid layout and have the latest topics below.
「いいね!」 2
I suggest building a static header customization if your categories do not change much. Then you could have whatever layout you like above the topic list.
「いいね!」 2
I’ve built this or something similar for a few sites at this point. If you put this in the </head> section of your theme it will put all the categories on top of your home page (and /latest assuming that it’s the same as your homepage)
Then all you’ll need is add the CSS to structure this layout however you want. This is a good introduction to using the API and Handlebars templates in general.
<script type="text/discourse-plugin" version="0.8">
const ajax = require('discourse/lib/ajax').ajax;
api.registerConnectorClass('below-site-header', 'custom-homepage', {
setupComponent(args, component) {
component.set('hostname', window.location.hostname);
api.onPageChange((url, title) => {
if (url == "/" || url == "/latest"){
$('html').addClass('show-custom-homepage'); // Show homepage
component.set('displayCustomHomepage', true);
ajax("/site.json").then (function(result){ // Get list of categories
let categoryName = [];
result.categories.forEach(function(categories){
categoryName.push(categories);
});
component.set('categoryName', categoryName);
});
}
else { // Hide homepage
$('html').removeClass('show-custom-homepage');
component.set('displayCustomHomepage', false);
}
});
}
});
</script>
<script type='text/x-handlebars' data-template-name='/connectors/below-site-header/custom-homepage'>
{{#if displayCustomHomepage}}
<div class="custom-homepage-wrapper">
<div class="wrap wrap-category-boxes">
<div class="homepage-category-boxes">
{{#each categoryName as |c|}}
<a href="/c/{{c.slug}}" class="box">
<div class="homepage-category-box">
{{#if c.uploaded_logo}}
<div class="category-image-wrapper">
<img class="homepage-category-image" src="{{c.uploaded_logo.url}}" />
</div>
{{/if}}
<h2>{{#if c.read_restricted}}<i class="fa fa-lock"> </i>{{/if}}{{c.name}}</h2>
<p>{{c.description}}</p>
</div>
</a>
{{/each}}
</div>
</div>
</div>
{{/if}}
</script>
「いいね!」 10
It looks very nice. How I can to add Font Awesome 5 instead of images? Many thanks!
「いいね!」 1
thymotep
(Thymotep)
2019 年 7 月 2 日午前 9:56
10
Hello,
Thank you for this code snippet! I am working on a project where I need to do some things on this principle (not necessarily categories) and I would like to put this directly in the plugin that I develop.
I know where to put the template handlebars, but I can not find the folder / file where to put the javascript. Could you tell me how to proceed?
Thank you,
Thymotep
「いいね!」 1
jrgong
(jrgong)
2019 年 7 月 6 日午後 3:49
11
I love this idea! Looking forward to test such a theme component or plugin
「いいね!」 1
Is there an update to this? I’m getting an error from the script not being able to get the category names. Nothing is changing on the page.
Yes, there was an error! Thanks for reporting it. I’ve fixed the code in the post above.
We turned strict mode on for our JavaScript, which means categoryName = []; needs to be declared, changing that line to let categoryName = []; was the fix.
「いいね!」 4
bksubhuti
(Bhante Bhikkhu Subhuti)
2022 年 4 月 4 日午後 12:15
15
このトリックを行うコンポーネントへのGitHubリンクは404です。
「いいね!」 1
simonk
(Simon King)
2022 年 4 月 4 日午後 3:31
16
「いいね!」 2
bksubhuti
(Bhante Bhikkhu Subhuti)
2022 年 4 月 5 日午前 12:32
17
わかりました。hbsをDiscourseに追加できるものとして機能させる方法を見つける必要があります。コンポーネントのファイルとしてこれを使用する必要があると思いますが、それに関するチュートリアルを作成する必要がありますか?
簡単なテーマのチュートリアルを見ましたが、それが正しい方向でしょうか?
「いいね!」 1
simonk
(Simon King)
2022 年 4 月 5 日午前 8:27
18
以前やったことがないので、答えがわかりません。テーマ開発者のチュートリアルは、確かに良い出発点になるでしょう。
Discourse Themes and Theme Components can be used to customize the look, feel and functionality of Discourse’s frontend. This section of the developer guides aims to provide all the reference materials you need to develop simple themes for a single site, right up to complex open-source theme components.
This introduction aims to provide a map of all the tools and APIs for theme development. If you prefer a step-by-step tutorial for theme development, jump straight to:
Themes vs. Theme Compon…
そのページで**「Mounting widgets」**を検索すると、ページの別の場所にウィジェットを表示する例が見つかるはずです。
この howto トピックも例として役立つかもしれません。
https://meta.discourse.org/t/how-to-add-a-featured-topic-list-to-your-discourse-homepage/132949
「いいね!」 3
bksubhuti
(Bhante Bhikkhu Subhuti)
2022 年 4 月 6 日午前 6:00
19
成功したらお知らせします。それまでの間、Airテーマを適用しましたが、かなり満足しています。それでも、カテゴリトピックの下に最新の投稿を表示したいと思っています。
かつて25年前にmsvc++プログラマーでしたが、PlayストアでリリースされたFlutterアプリを構築することに成功しました。しかし、オープンソースAPIは私にとって簡単ではありません。どうなるか見てみましょう。可能な時にアップデートを投稿します。
「いいね!」 2
Bhante Bhikkhu Subhuti:
成功したらお知らせします。
成功しましたか?同じことをしたいのですが、簡単な方法があるのか、それともテーマを掘り下げて時間を費やす必要があるのか疑問に思っています。
「いいね!」 1
デスクトップのカテゴリページスタイル「ボックスとサブカテゴリ」設定を使用してテーマコンポーネントを作成し、ボックスの下にコードを追加しました。現在、サイト全体の最新トピックを一覧表示する方法を調べています。
<script type="text/x-handlebars" data-template-name="/connectors/category-boxes-after-boxes/mwp">
<div class='column'>
{{categories-topic-list topics=topics filter="latest" class="latest-topic-list"}}
</div>
</script>
問題は、これが単純に「すべて既読です」と表示されることです。
「いいね!」 1
bksubhuti
(Bhante Bhikkhu Subhuti)
2023 年 12 月 2 日午前 3:44
22
諦めました。今はほとんど標準的なものを使っています。
「いいね!」 1