How to create Feed section in wordpress for homepage

眉间皱痕 提交于 2020-08-10 20:29:05

问题


I am trying to do is, when a user post something from his account it will directly need to show on homepage on wordpress site. This will be for all user's role. Here i want to build a feed page like LinkedIn. Thanks in advance.


回答1:


I'm assuming you have some knowledge... You could just add a loop restricted to a specific author... or user by grabbing the user ID. You could do something like this:

<!-- 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 -->

Should be working just tested it.

Regards. Stackoverflow, World Wide Web support x)



来源:https://stackoverflow.com/questions/62608577/how-to-create-feed-section-in-wordpress-for-homepage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!