- This topic has 5 replies, 3 voices, and was last updated 1 year ago by
Tom.
-
AuthorPosts
-
December 26, 2019 at 12:01 pm #1114682
Neil
I’ve created this hook in the elements section after_main_content with priority 22.
The aim is to use a page as a hub and display only posts from a specific category.
Not sure what is wrong here but none of my posts a specific category are displaying.
Below is the code I put in the element hook.
<div class="generate-columns-container"> <?php $args = array( 'post_type' => 'post', 'cat'=>39, 'posts_per_page' => -1, 'post_status' => 'publish', 'order' => 'ASC' ); $query = new WP_Query( $args ); if($query->have_posts()) : while($query->have_posts()) : $query->the_post(); if (has_post_thumbnail()) { ?> <article <?php $postid = get_the_ID(); ?> class="hub-grid tablet-grid-50 mobile-grid-100 grid-parent grid-33 no-featured-image-padding" itemtype="https://schema.org/CreativeWork" itemscope=""> <div class="inside-article design-article"> <header class="entry-header"> <a href="<?php get_permalink( $postid ); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a> </header> <div class="entry-summary" itemprop="text"> <h2 class="entry-title" itemprop="headline"><a href="<?php the_permalink($postid); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> <?php the_excerpt(); ?> <div> </div> </article> <?php } endwhile;endif;?> </div>
December 26, 2019 at 4:24 pm #1114782Leo
StaffCustomer SupportHi there,
Not sure if I understand.
Is this for the posts page or a static page?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/December 27, 2019 at 3:42 am #1115011Neil
This is a static page that is being used to loop all posts from a specific category.
I’ve added the above hook to do this but it returns nothing.
December 27, 2019 at 9:17 am #1115383Tom
Lead DeveloperLead DeveloperCan you try adding quotations around the category ID?:
'39'
Just to confirm, does this category have published posts?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentDecember 27, 2019 at 1:05 pm #1115529Neil
I did that and I’ve also tried
category_name
. None of them work.The category does have published posts.
Thanks
December 27, 2019 at 5:03 pm #1115613Tom
Lead DeveloperLead DeveloperDo those posts have a featured image? Your code is saying to only output the posts if a featured image exists.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.