Understanding how do pageofposts custom fields work
-
I am trying to implement this example in a page
store-page.php
which has posts.- Inside the loop, I am just calling
<?php get_template_part( 'content', 'store-product' ); ?>
and nothing else. - Then I am assigning the page as a template to all the categories I want to turn into a store.
- Each post is placed in a specific category that matches the name of one page (because e.g. I want to display posts from “Courses” category in “Courses” page).
Though, WP, instead of showing up articles, it shows the message as if no articles were there at all.
Is there anything I forgot to do? How do you get the current category in a loop on a page?
This is my code inside the
store-page.php
:<?php /** * Template Name: Store Page * The template for displaying the store page. * * This is the template that displays all pages by default. * Please note that this is the WordPress construct of pages * and that other 'pages' on your WordPress site will use a * different template. * * @package govpress */ get_header(); ?> <div id="primary" class="content-area"> <div id="main" class="site-main" role="main"> <?php /* The loop: the_post retrieves the content * of the new Page you created to list the posts, * e.g., an intro describing the posts shown listed on this Page.. */ if ( have_posts() ) : while ( have_posts() ) : the_post(); // Display content of page get_template_part( 'content', get_post_format() ); wp_reset_postdata(); endwhile; endif; ?> <?php if ( is_page() ) { $category = get_post_meta( $posts[0]->ID, 'category', true ); $cat = get_cat_ID( $category ); } if ( $cat ) : $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $post_per_page = 4; // -1 shows all posts $do_not_show_stickies = 1; // 0 to show stickies $args=array ( 'category__in' => array($cat) ); $temp = $wp_query; // assign original query to temp variable for later use global $wp_query; $wp_query = null; $wp_query = new WP_Query( $args ); if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?> <?php get_template_part( 'content', 'store-product' ); ?> <?php endwhile; ?> <?php endif; // if ( $wp_query->have_posts() ) ?> <?php $wp_query = $temp; //reset back to original query ?> <?php else : ?> <?php get_template_part( 'content', 'none' ); ?> <?php endif; // if ( $cat ) ?> </div><!-- #main --> </div><!-- #primary --> <?php get_footer(); ?>
- Inside the loop, I am just calling
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Understanding how do pageofposts custom fields work’ is closed to new replies.