Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

侧边栏最新文章显示与置顶文章冲突 #671

Open
666ghj opened this issue Feb 25, 2024 · 14 comments
Open

侧边栏最新文章显示与置顶文章冲突 #671

666ghj opened this issue Feb 25, 2024 · 14 comments
Labels
bug Something isn't working

Comments

@666ghj
Copy link

666ghj commented Feb 25, 2024

是什么版本出现了此问题?

hao版本:1.4.8
halo版本:2.12.4

在线站点地址

http://lovexl.top

发生了什么?

如在线站点地址中展示的,给部分文章添加置顶显示后,侧边栏的最新文章也会被置顶文章占用,从而导致无法显示真正的最新发布的文章

相关日志输出

No response

附加信息

No response

@666ghj 666ghj added the bug Something isn't working label Feb 25, 2024
@carolcoral
Copy link
Collaborator

侧边栏中“最新文章”使用的是获取文章列表第一页的方式进行展示的,目前无法有效的获取到“最新文章”,需要官方提供相应Finder才行。建议找halo官方提issues。
image

@666ghj
Copy link
Author

666ghj commented Apr 4, 2024

有啦,halo的14版本提供了该类api了终于😍

@carolcoral
Copy link
Collaborator

有啦,halo的14版本提供了该类api了终于😍

回头看看,上次2.14版本会议说的是2.15才出

@carolcoral
Copy link
Collaborator

@666ghj 看过了,2.14的文档里面没有相关api,你发来看看:https://docs.halo.run/developer-guide/theme/finder-apis/post

Copy link

github-actions bot commented May 7, 2024

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label May 7, 2024
@666ghj 666ghj closed this as completed May 7, 2024
@666ghj 666ghj reopened this May 7, 2024
@carolcoral
Copy link
Collaborator

本来说2.15有api的,结果还是没有

@666ghj
Copy link
Author

666ghj commented May 7, 2024

本来说2.15有api的,结果还是没有

🥹

@github-actions github-actions bot removed the stale label May 8, 2024
@alwayszhangyu
Copy link

alwayszhangyu commented May 19, 2024

我看了halo官方的api,我认为可以使用archives(page,size)或archives(page,size,year)来代替现在主题使用的list(page,size)。

list(page,size)的描述是:根据分页参数获取文章列表。

list,这里我理解为首页的文章列表,这里面的排列方式虽然也按时间顺序进行排列,但添加了一个优先级更高的条件,置顶。

archives(page,size)的描述是:根据分页参数获取文章归档列表。

archives(page,size,year)的描述是:根据年份和分页参数获取文章归档列表。

archives,这里我理解为归档的文章列表,这里面的排列方式只按时间进行排序,是不管是否置顶的。

使最新发布列表与归档列表(/archives)相同就行了,如下图所示。

image-20240519143342257

思路仅供参考

@carolcoral
Copy link
Collaborator

如果置顶文章和最新文章在相同年份呢,这样还是没法获取实际想要的最新文章列表的

@alwayszhangyu
Copy link

alwayszhangyu commented May 19, 2024

场景:有9篇文章,其中测试6{置顶}与置顶是已置顶的文章,其余的是正常文章,如下:

image-20240519230236501

下面是完全复制**archives(page,size)**官方示例进行的修改

<div class="card-widget card-recent-post" th:with='posts = ${postFinder.archives(1,theme.config.sidebar.recentPost)},
    postRandomImg=${#strings.contains(theme.config.layout.postRandomImg,"?") ? theme.config.layout.postRandomImg+"&" : theme.config.layout.postRandomImg+"?"}'>
    <div class="item-headline"><i class="haofont hao-icon-eicon_map-2-line1"></i><span>最近发布</span></div>
    <div class="aside-list">
         <!-- 修改处分界线 -->
        <th:block th:with="archives = ${postFinder.archives(1,10)}">
            <th:block th:each="archive : ${archives.items}">
                <h1 th:text="${archive.year}"></h1>
                <ul>
                    <th:block th:each="month : ${archive.months}">
                        <li th:each="post : ${month.posts}">
                            <a th:href="@{${post.status.permalink}}" th:text="${post.spec.title}">
                            </a>
                        </li>
                    </th:block>
                </ul>
            </th:block>
        </th:block>
		<!-- 修改处分界线 -->
    </div>
</div>

image-20240519225106774

结果:

测试6{置顶}与置顶在文章列表是正常排列的,在最近发布是按时间由近及远排序的,不受测试6{置顶}与置顶的置顶效果影响。(不会写样式,将就着哈!)

image-20240519225434374

image-20240519232543298

下面是未使用archives(page,size)的最近文章:可以看到置顶的优先级最高

image-20240519231222391

@carolcoral
Copy link
Collaborator

@chengzhongxue 鱼,来活啦

@chengzhongxue
Copy link
Owner

这里是要改成最热门文章,而不是最新文章这样

@carolcoral
Copy link
Collaborator

这里是要改成最热门文章,而不是最新文章这样

侧边栏的“最新文章”

@chengzhongxue
Copy link
Owner

下个版本更新

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants