0

I'm just starting learning wordpress. I decided to go with the underscores starter theme to develop my own custom theme. And I've got some questions.

I suppose there is an answer to my question in the docs, but it seems like too much information to study at the first time. I'm just getting confused more. So I need a direct and clear answer to help me dive in the docs then with a primary understanding.

The question is:

I've installed the underscores theme on my wordpress site.

After this, I've created two pages (page1 and page2).

I've assigned page1 as my front page and page2 as my posts page then.

The index.php file contains the following code:

get_header(); ?>

<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">

    <?php
    if ( have_posts() ) :

        if ( is_home() && ! is_front_page() ) : ?>
            <header>
                <h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
            </header>

        <?php
        endif;

        /* Start the Loop */
        while ( have_posts() ) : the_post();

            /*
             * Include the Post-Format-specific template for the content.
             * If you want to override this in a child theme, then include a file
             * called content-___.php (where ___ is the Post Format name) and that will be used instead.
             */
            get_template_part( 'template-parts/content', get_post_format() );

        endwhile;

        the_posts_navigation();

    else :

        get_template_part( 'template-parts/content', 'none' );

    endif; ?>

    </main><!-- #main -->
</div><!-- #primary -->

But when I enter mysite.com/index.php, there's no posts on the page (but the code must extract them, as I understand). There is the text I've entered while creating the page only.

And the page2 (which is located at mysite.com/page2/) doesn't show the title and the posts navigation.

So I don't understand:

1) Why when I'm adressing mysite.com/index.php I see the text I've entered while creating the page, but there's no code for that in the index.php file?

2)Why the single_post_title() function doesn't return something?

3) Where's the post navigation? There's code for that in the index.php file

4) Are the posts page and the home page are the same pages?

5) How does the index.php file work? It controls the front page and the post page (and maybe some more pages) at the same time? I don't get it.

Thanks in advance!

  • 1
    All the information you need is under Theme Development section of the WordPress Codex. You can't ask somebody on this site to write a personal tutorial. – Max Yudin Mar 28 '16 at 13:45
0

1) Why when I'm adressing mysite.com/index.php I see the text I've entered while creating the page, but there's no code for that in the index.php file?

You've assigned page1 as your Front Page so this displays instead of the index.php. You will need to create a page template:

https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/

if you want to edit the code for the page. Alternatively, you can use shortcodes to add to the content part of the page.

2)Why the single_post_title() function doesn't return something?

Again, probably because you're not looking at index.php, also it's not in the loop, but I guess it probably doesn't need to be.

3) Where's the post navigation? There's code for that in the index.php file

Again this is because you're not actually seeing index.php being rendered when looking at page1.

4) Are the posts page and the home page are the same pages?

Not really, you can set your own homepage to a page and create a unique page template for it, just like you can for post pages. If you don't set a front page though, it defaults to index.php

5) How does the index.php file work? It controls the front page and the post page (and maybe some more pages) at the same time? I don't get it.

Think I've kind of answered that above!!

Basically you need to create a page template, copy and paste the contents of index.php into it, set that page template on your Page when logged into your admin area, and then any changes you make to page template will show on the home page.

In the root of your site create a folder called: page-templates

Inside this folder create a page template, for example: home-template.php

In here, at the very top put this:

<?php
/**
* Template Name: Home Template
*/
?>

After that, paste the contents of your index.php, save and upload the file etc.

Then log in, head to the edit page screen for the one you're setting as the front page, on the right hand side there should be a select box with page template options:

Set template

Publish the page, and you're done!

  • No problem, glad to help :) – Dammeul Mar 28 '16 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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