Grow your CSS skills. Land your dream job.

page loop issue

  • # October 30, 2012 at 7:57 pm

    < ?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

    < ?php the_title(); ?>

    < ?php the_content(); ?>
    < ?php endwhile; ?>

    That is the current loop in my index php file that gets all of my pages made. The site is one long website and I used custom links in the menu section to link to an anchor inside the page content.

    Few issues I need help with would be – 1. The pages, while ordered, seemingly don’t care. They are in the exact opposite of what I want the order to be and can’t seem to find how to change that. 2 – I’d like each page to have its own wrap so I can put margin on each to divide the sections.

    If anyone can give me some insight, would be very helpful. Thanks.

    # October 30, 2012 at 8:01 pm

    @Jeager I’m sort of confused still. You want each page to have a different wrap? Surely there could be a better way than to do that.

    What do you mean you ordered the pages and they are listing in the opposite way? Are you talking about the main nav? If so, the loop above has no involvement with that. You can set how you want the pages to appear by going to ‘Pages’, select a page and then edit the ‘Page Attribute’ order: http://cloud.chrisburton.me/KYCq

    # October 30, 2012 at 8:11 pm

    No, I am currently using my nav bar to link to anchors inside the content of each page. I had to create each anchor inside the page content and a custom nav link inside the menu option to link to said anchor.

    That said, the loop I posted above populates the main page with each page I have created. However when the pages are listed, they do not have their own unique or global class/ID, rather they are all under the div.content rather then all under div.content with a class of .page or .(whatever)

    I need each page posted to have a class of .whatever so I can style it. Then I need some way of ordering the pages that are shown.
    http://www.jtpenezich.com/abc/

    That is an older version, as I am currently working locally, but it should give the idea of how the pages are being listed verse what the navigation shows.

    # October 30, 2012 at 8:22 pm

    Trying to make this easier to understand, as I know I am probably not perfectly describing it.

    In the link it has the first 3 posts displayed through a custom query followed by the twitter, and then starts to display the pages (which I made through the dashboard – pages). I can find/work with normal post loops easier then the page loop, hence where the trouble is kicking in.

    After twitter, the pages are displayed but without a wrapper around each individual page. I would like to add that, similiar to my post loop.

    < ?php $custom_query = new WP_Query('posts_per_page=3');
    while($custom_query->have_posts()) : $custom_query->the_post(); ?>

    id=”post-< ?php the_ID(); ?>“>

    “>< ?php the_title(); ?>

    < ?php the_content('Continue Reading..'); ?>

    < ?php endwhile; ?>
    < ?php wp_reset_postdata(); // reset the query ?>

    Mainly so I can create a division in between each of the pages without adding the margin to the headings.

    The other issue is that they are displaying in the incorrect order. If there is some way to display them ASC or DESC (forget what is default) then it would display in the correct order.

    Hope that clears things up a tad more.

    Edit: Changed the page loop to display headings as h3′s and adding a margin to that. It creates the division I want to do, but would rather each page have a wrap instead if possible.

    # October 30, 2012 at 8:31 pm

    @Jeager Hmm. The only thing I can suggest is using the following:

    `

    >`

    This will spit out the normal classes but also attach the class ‘whatever’ to it.

    Edit: You can set the page order by using the following:

    `’order’ => ‘ASC’`

    or

    `’order’ = ‘DESC’;`

    # October 30, 2012 at 8:36 pm

    Hmm… It still gives the entire listing of pages the same class. Do I have to reset the page loop somehow?

    # October 30, 2012 at 8:39 pm

    @Jeager Please post the output of the classes/ID’s (including the div).

    # October 30, 2012 at 8:40 pm

    How would one do that? When I click code, nothing shows up, so i tried

    # October 30, 2012 at 8:42 pm

    @Jeager No, no. Just give me what this outputs:

    >
    # October 30, 2012 at 8:45 pm

    Edit: Did something wrong. Fixed to:

    However it still displays the entire section of pages under the class. Whatever is now .page-content

    # October 30, 2012 at 9:00 pm

    Don’t use `body_class` for this, just get the post’s slug:

    http://www.joshstauffer.com/get-post-slug-in-wordpress/

    As for the ordering, you should be able to fiddle with `query_posts` to your liking.

    # October 30, 2012 at 9:02 pm

    Would that be done in a custom query post? Because I need it to get the slug of the page, not the post, and havnt found a way to display the page information through a query.

    # October 30, 2012 at 9:03 pm

    @Jeager You paste your code, highlight it and then click the code button.

    This is still quite confusing so I’m going to ask one last question. Is this a one page site?

    # October 30, 2012 at 9:05 pm

    Yes. One page site. I mentioned it in the first post but should of made it more clear, sorry. That is why I’d like each page to be similar to the post loop and able to give each its own container. Also why I need to be able to sort them like how I want.

    # October 30, 2012 at 9:05 pm

    Are you querying posts or pages?

Viewing 15 posts - 1 through 15 (of 31 total)

You must be logged in to reply to this topic.

Projects

*May or may not contain any actual "CSS" or "Tricks".