Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other How to display pages (not posts) in wordpress?

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #191292
    raj080288
    Participant

    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(); ?&gt;
            &lt;article&gt;
                &lt;h1&gt;&lt;?php the_title(); ?&gt;&lt;/h1&gt;
                &lt;?php the_content(''); ?&gt;
            &lt;/article&gt;
    
    &lt;?php endwhile; wp_reset_query(); ?&gt;
    
    #191324
    Senff
    Participant

    It’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-us

    So 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?

    #191326
    raj080288
    Participant

    Hi, 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

    #191330
    Alen
    Participant

    If 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,
    -Alen

    #191331
    Senff
    Participant

    If 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.

    #191368
    raj080288
    Participant

    @Senff, thanks I have gone with the post as it is easier to do. Thanks

    Also thanks Alen, I will deffo keep you solution in mind.

    Thanks,

    Raj

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Other’ is closed to new topics and replies.