WordPress.org

Ready to get started?Download WordPress

Forums

creating a page to display custom loop (7 posts)

  1. strung out
    Member
    Posted 3 years ago #

    ok, i've got as far as uploading a custom page template to my child theme.

    what i want to do is create a custom loop to go on my front page, instead of a standard loop or static front page. firstly, what code do i need to add to make my page look like a standard page on my site (with header, sidebar etc). secondly, where do i add the code for the custom loop?

    this is my test page so far, but as you can see, it's gone very wrong! http://robots-and-spaceships.com/test/

  2. @mercime
    Volunteer Moderator
    Posted 3 years ago #

    You can create a special WordPress template - home.php - and place the special loops you have in mind there and upload to server.

    Looking at your front page, the first error I see is this at the top of the page get_header(); ?>. This tells me that you forgot to add the opening <?php before that code. Code must be
    <?php get_header(); ?>
    and you'll get your styling in.

  3. strung out
    Member
    Posted 3 years ago #

    ha, well spotted. i wondered why the styles weren't working, but i haven't got an eye for these things yet. it will come with practice i'm sure! thank you.

    as i said, i am very much a beginner. i've fixed my test page now.

    if i wanted to add a loop to this page, would i just need to add some loop code into the custom page template? i'm trying to work out from the http://codex.wordpress.org/Function_Reference/query_posts page how it all works, but i don't know which templates to put the loop code into.

    i'm sure once i manage to include a loop on my test page, i can work out the rest, little by little from there. apologies for the exceptional newbieness!

  4. @mercime
    Volunteer Moderator
    Posted 3 years ago #

    No woories. You're already doing pretty well with your twentyten child theme :-)

    if i wanted to add a loop to this page, would i just need to add some loop code into the custom page template?

    Just to be clear, which page are you referring to? http://robots-and-spaceships.com/test/ ? If so, nix the home.php file because that special file is only good for the front page.

    For custom page template copy index.php from twentyten and make sure you add necessary comment at beginning of template file

    Replace lines 21-27 with custom loop.

  5. strung out
    Member
    Posted 3 years ago #

    well, i was going to test the loop code out on my test page, but yes, eventually i'm planning on having the custom loop on my front page.

    to do this, i was going to create a custom page template, add the loop code to this template, then set the this page as my static home page. am i along the right lines? am i even making sense anymore? haha :)

    this is proving to be the most difficult part of my site to get right! borders, colours etc are easy to alter with only a minimum of knowledge, but loops are really getting my brain in a twist!

    (i'd probably better mention now, i don't actually have any loop code yet, i was planning on getting a standard loop code working first, then altering it bit by bit to get it looking how i want!)

  6. @mercime
    Volunteer Moderator
    Posted 3 years ago #

    to do this, i was going to create a custom page template, add the loop code to this template, then set the this page as my static home page. am i along the right lines? am i even making sense anymore? haha :)

    I do understand where you're at. Chances are, the code you need to render the information you want on the home page can be found by searching this forums or via Google. Enjoy the journey :-)

  7. Root
    Member
    Posted 3 years ago #

    You very rarely need to query posts or the db. Certainly not for what you are doing. WP packages all http requests, queries the mysql db, and stores the output in a global variable which is of course an array. It then passes the request to the relevant theme template page using the template hierarchy. Requests to the domain are routed to home.php if it exists. The template then accesses the global and displays the data.

    SO: In home.php all you need go is access the global variable array by looping thru it which u can do one or more times. In addition there are template tags which are shortened if used inside the loop. These are used for each element in an instance in the array.

    In summary: From what u said: Running the loop is a different operation from running a db query. Its all in the Codex documentation.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.