Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialjoeboo2529
9,805 PointsCan's get page to display on a single page.
I've been trying to get pull all the pages to display on a single page, e.g front-page.php.
<?php
query_posts('post_type=page&order=ASC');
// OR
$args = array(
'post_type' =>'page',
'order' => 'ASC'
);
$the_query = new WP_Query( $args );
?>
13 Answers
Roberto Alicata
Courses Plus Student 39,959 PointsLook at this topic id it can help you. It seems you need to loop on $the_query.
Stephen O'Connor
22,291 PointsWhat template are you using for your pages? A standard WordPress loop should bring in page content if you are using page.php.
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!-- Gets the title and content -->
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; else: ?>
<!-- Displayed if no posts or pages are available -->
<p>There are no posts or pages here!</p>
<?php endif; ?>
joeboo2529
9,805 Pointshere is my codes:
$args = array(
// 'year' => $year,
// 'w' => $week
'post_type' => 'project'
);
$the_query = new WP_Query( $args );
?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php endwhile; // end of the loop. ?>
Stephen O'Connor
22,291 PointsWhat's in content-page.php?
joeboo2529
9,805 Points<?php /**
- Template Name: Menu */ ?>
<?php
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
$args = array(
'post_type' => 'menu'
);
?>
<?php the_field('menu_descriptions'); ?>
</article>
Stephen O'Connor
22,291 PointsWhat are you trying to display on the page, just the content/title from each page or something else?
joeboo2529
9,805 PointsI'm trying to display 'custom fields' from the custom post.
Stephen O'Connor
22,291 PointsAre you using WordPress custom fields or a plugin like Advanced Custom Fields?
joeboo2529
9,805 PointsYes I am.
Stephen O'Connor
22,291 PointsWhich one? WordPress' own custom fields or the ACF plugin?
joeboo2529
9,805 Pointssorry, it's ACF plugin that I'm using.
Stephen O'Connor
22,291 PointsOK. So you can just use the following to display the custom field(s) in whichever order you like within the standard WordPress loop - if your custom fields are assigned to the page:
<?php the_field('your_custom_field_name'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!-- Custom field -->
<?php the_field( 'your_custom_field_name' ); ?>
<?php endwhile; else: ?>
<!-- Displayed if no posts or pages are available -->
<p>There are no posts or pages here!</p>
<?php endif; ?>
Or you can use WP_Query if you are using a custom post type as well as custom fields:
<?php
$args = array(
'post_type' => 'your_custom_post_type'
);
$the_query = new WP_Query( $args );
?>
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<!-- Custom field -->
<?php the_field( 'your_custom_field_name' ); ?>
<?php endwhile; else: ?>
<!-- Displayed if no posts or pages are available -->
<p>There are no posts or pages here!</p>
<?php endif; ?>
Also check out the ACF Documentation for more info.
joeboo2529
9,805 PointsHi guys apologize for late reply.
I've managed to get all other pages to display on one page but, when I tried to have a custom page e.g " page-about.php " - nothing is showing on up that page? Obviously when displaying" page-about.php " on it own, everything displaying correctly on the page. I've been scratching my head for days now and trying to figure this out.
anyone could help?
joeboo2529
9,805 Pointsjoeboo2529
9,805 Pointsall pages seem to be displaying onto the page ok, but when creating a template for a certain page nothing is showing up.