如何在WordPress中为主页创建提要部分 [英] How to create Feed section in wordpress for homepage

查看:23
本文介绍了如何在WordPress中为主页创建提要部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做的是,当用户从他的帐户发布一些东西时,它将直接需要显示在WordPress网站的主页上。这将适用于所有用户角色。 在这里,我想构建一个类似LinkedIn的提要页面。 提前谢谢。

推荐答案

我假设您对. 您只需添加一个限制为特定作者的循环即可。或用户通过抓取用户ID。您可以这样做:

<!-- Start page loop here -->
<?php
// 'post_type' => 'any' ... to display all post and custom post type related to the author or user
// You should restrict the number of post, you don't want your site crashing by loading all posts available
// I'm letting your imagination take over
$authID = get_the_author_meta( 'ID' );
$query = new wp_query( array( 'author' => $authID,'post_type' => 'any', 'post_status' => 'publish', 'posts_per_page' => '3' ) );  if ( $query->have_posts() ): ?>
<h4>Discover your feed 🥳</h4>
<?php while ( $query->have_posts() ): $query->the_post(); ?>
<!-- Start page template here -->
<div><a aria-label="<?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
<!-- End page template here -->
<?php endwhile; else: ?>
<h4>Your feed is empty 😥</h4>
<?php endif; ?>
<!-- End page loop here -->

应该可以工作,只是测试了一下。

问候您。StackOverflow,万维网支持x)

这篇关于如何在WordPress中为主页创建提要部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆