- This topic is empty.
-
AuthorPosts
-
December 19, 2014 at 7:13 pm #191292raj080288Participant
I want to know how I can display a page created in wordpress on the front end. I don’t want to display the ‘post’, I want to display the ‘page’ e.g ‘about us’ page.
<?php
query_posts('posts_per_page'); while(have_posts()) : the_post(); ?> <article> <h1><?php the_title(); ?></h1> <?php the_content(''); ?> </article> <?php endwhile; wp_reset_query(); ?>
December 20, 2014 at 9:29 am #191324SenffParticipantIt’s not clear what you want exactly.
A Post can be shown as an individual, or you can show a number of posts on one page.
A Page can only be shown individually (e.g. http://yoursite.com/about-usSo what are you trying to do exactly? You want to show the contents of a Page on a page where there’s normally a Post?
December 20, 2014 at 10:07 am #191326raj080288ParticipantHi, yes you’re right, I want to show contents of a page on a page where there is nornally a list of posts. In the same way I wish to loop through all of my pages and display every single page on that main front page.
I hope that makes sense?
Thanks,
Raj
December 20, 2014 at 11:35 am #191330AlenParticipantIf you need to pull page content you need to use WP_Query and ask for that specific data. To go with @Senff example above, if you had a page with a slug of
about-us
your code would look like this:// You can also use page ID as 'page_id' => '11' // instead of 'pagename' => 'about-us', 11 would be the unique page ID. $query_arguments = array('pagename' => 'about-us',); $special_query = new WP_Query( $query_arguments ); // The Loop if ( $special_query->have_posts() ) { while ( $special_query->have_posts() ) { $special_query->the_post(); // do something with the data // the_title(); // the_content(); } } else { // no posts found } // Restore original Post Data wp_reset_postdata();
In the same way I wish to loop through all of my pages and display every single page on that main front page.
I would use a menu here instead of making a questom query. It gives you the ability to change the menu in the future without having to go to the template page and change code. Your template code would be something like:
// register menu location in your functions file // register_nav_menu('custom', __( 'Custom')); wp_nav_menu(array('theme_location' => 'custom'));
Hope that helps,
-AlenDecember 20, 2014 at 11:40 am #191331SenffParticipantIf you want to loop through Pages and display the contents of them on one page, why not….use Posts?
I’m not trying to tell you that what you want to do is wrong, but with the way WordPress is set up, I would just say that the contents you’re trying to show should be placed in Posts.
A Page is just one page. Nothing more, nothing less.
A Post is meant to be shown “dynamically” — either single, or grouped, or part of it, sorted, etc.
The Loop can be used to go through Posts, but not through Pages (at least not without some custom coding).Just wondering if it would just make more sense to put that content in Posts, instead of Pages. Basically — if you want to show contents of various items on the main page, then just put it in Posts (and not in Pages). That’s what they’re for, after all.
December 21, 2014 at 6:27 am #191368 -
AuthorPosts
- The forum ‘Other’ is closed to new topics and replies.