I am trying to build a custom theme for my wordpress site, I am putting it together from a bootstrap theme I found. This is my first foray into developing with php, and I've just finished learning to list posts. Since I have two posts, I haven't bothered to figure out how to break the loop into multiple pages (ie. show 10 posts per page and navigation at the bottom).

What I am trying to learn is how to make the permalinks work in the theme I am building. I get that wordpress works by making queries and displaying those queries. I don't understand how to obtain arguments for the query, or if that is how I get the permalinks and pages to work.

I haven't figured out the right google search parameters to resolve my confusion. So what should I be researching, or perhaps a tutorial?

ps. sorry if I get the tags wrong, or if this isn't stackexchangey enough, I know it wouldn't be for the original.


You see I don't know how to fill in the else for my wp-content/themes/name/index.php file. This is the structure I have setup thus far.

    $last_date = '';
    if( is_home() ) :
        while( have_posts() ) :
            $the_date = the_date( 'Y', '', '', false );

            if ( false ) : //$the_date != $last_date ) :
                    <!-- Year HTML -->
            $last_date = $the_date;
                    <!-- Blog Entries (titles, author, tags, date, excerpt -->
    else :
<!-- No Frigging Clue! -->
<?php endif; ?>
  • If you're talking about "pretty links" WordPress will handle most of that for you in Settings->Premalinks. Google "tutsplus wordpress permalinks" for several guides from basic usage to the using the WP Rewrites API.
    – BillK
    Commented Feb 16, 2016 at 2:16
  • @BillK I am afraid I may have been unclear. I am not trying to rewrite the URLs. I am happy with the functionality WP has provided there. I can't load permalinks in my theme, due to the if ( is_home() ) on my index.php in my theme.. nothing loads. I don't know what to put in the else. I will edit the question to add this stuff.
    – Josh C
    Commented Feb 16, 2016 at 2:25

2 Answers 2


The Action Reference may give you some insight into what's going on when you visit a front-end page in WordPress and help you to understand things a bit better.

Actions are events that occur in the process of loading a page, they let you "hook" into the process to run your own code at specific times. The section Actions Run During a Typical Request shows these events roughly in the order they happen, so we can follow along and figure out what's going on. Most of the action names are pretty self-explanatory, we'll skip ahead through the list to the wp_loaded action.

Up to this point we've loaded some things and established the initial state, after this is where the query action happens- "The Automagic". The requested URL is parsed to determine what has been requested, and is converted to query variables for the "Main Query", which runs between the posts_selection and wp actions. This is where the data is loaded that "The Loop" will ultimately operate on, and the results of this query determine how all the is_ Conditional Tags are set up, and what template file gets loaded according to the Template Hierarchy.

After the query runs, we see template_redirect, which is the last action before your template is loaded.

  • Very informative, thank you. I'd upvote if I had 15 rep.
    – Josh C
    Commented Feb 16, 2016 at 14:59

Well that is more clear. You can place whatever you want in there, like a message saying "No Posts Found" for example. Rather than using is_home() the code you have could be a template for displaying archive pages; be it posts, categories, etc. You would use different templates for single posts and pages.

Code for determining what template should be loaded can be in your theme, WP has some defaults that it looks for like page.php. You will want to read the Page Templates guide in the developer's Theme Handbook.

The Page Templates guide states that WordPress will use "index.php — If no specific page templates are assigned or found, WordPress defaults back to using the theme’s index file to render pages"

Update: I'm sorry, I should have also referred to Post Template Files

  • So each "template" page will automagically~ deal with the wp_query arguments for me? I can just make a standard loop? I imagine I'll find out once I start reading the page, but figure I might ask for some clarification just in case.
    – Josh C
    Commented Feb 16, 2016 at 2:56
  • No, the results of wp_query will determine what template should be used. In most cases WP will handle the query for you when you click a link to a page or post. The post-type is returned in the query object.
    – BillK
    Commented Feb 16, 2016 at 3:09
  • @JoshC You should probably be reading about The Loop in the Codex. Your theme will interact with the WP loop. You don't necessarily have to write any queries unless you need something custom. Even then, you can use the pre_get_posts filter to modify the default query.
    – BillK
    Commented Feb 16, 2016 at 3:15
  • Alright, I am still fuzzy on the details of how the working php script(ie. template) gets the correct data, but I'll just research those three pages more and hope it comes together. I'll start in the morning though. So much information on each page to sort through. By the way, thanks for the help. I was worried my first post here would be like my first post on stackoverflow.com
    – Josh C
    Commented Feb 16, 2016 at 3:18
  • Getting the whole query/template/loop concept is most of the WP learning curve. After that it gets easier.
    – BillK
    Commented Feb 16, 2016 at 3:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.