1

I am new to WP.

I have installed WP in my local system with WAMP and trying to create my own theme.

I have created pages and trying to set my "Home" page as front page and "Blogs" page as my posts page.

But when i try to change customizing theme page is giving error like "localhost redirected you too many times."

Kindly help me with this.

Thanks in advance.

Error shone in image "localhost redirected you too many times."

Note: I have created style.css, index.php, header.php, footer.php & functions.php

footer.php

<footer>
    <p>This is my footer</p>
    <?php wp_nav_menu(array('theme_location'=>'secondary')); ?>
</footer>

<?php wp_footer(); ?>

</body>
</html>

functions.php

<?php

function first_script_enqueue() {

wp_enqueue_style('customstyle', get_template_directory_uri() . '/css/frist.css', array(), '1.0.0', 'all');
wp_enqueue_script('customjs', get_template_directory_uri() . '/js/frist.js', array(), '1.0.0', true);

}
add_action( 'wp_enqueue_scripts', 'first_script_enqueue');
function first_theme_setup() {

add_theme_support('menus');

register_nav_menu('primary', 'Primary Header Navigation');
register_nav_menu('secondary', 'Footer Navigation');

}
add_action('init', 'first_theme_setup');

header.php

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>First Theme</title>
    <?php wp_head(); ?>
</head>

<body>

    <?php wp_nav_menu(array('theme_location'=>'primary')); ?>

index.php

<?php get_header(); ?>

    <h1>This is my index</h1>

<?php get_footer(); ?>

style.php

/*
Theme Name: First Theme
Description: This is first theme.
Version: 0.1 alpha
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: black, white, responsive, one-colume, two-colume, featured-image, custom-menu, custom-header, post-formats
*/

Note: first.css & first.js are there in mentioned folder but its empty for now.

  • How does yoir index.php look like, aswell it would make sense to use front-page.php to customize the looks of your home page – funkysoul Jun 30 '18 at 21:06
  • check if any .htaccess rules exist and double-check that the table wp_options >> site_url matches. Also, use default theme to test local config. don't launch into theme-dev until WordPress is installed & confirmed. Please provide code sample for more help :) – admcfajn Jul 1 '18 at 0:49
  • I have added code of my files kindly check. – Dpen Kdcha Jul 1 '18 at 18:23
  • Yes, as admcfain mentioned, first install WP, then do your setup how you want it to be configured - check that configuration with twentyseventeen, then switch to your own theme and start building with index.php, then move on to frontpage etc. – user3135691 Jul 1 '18 at 22:35
2

A link that might help you a lot is the WordPress Template hierarchy, see: WordPress Template hierarchy.

In order to get a static front page, you should create a file called "front-page.php". WordPress will use this file to show the frontpage, in case you have set the it in the backend options. Please see the image:

Statis Frontpage

If you are writing your own WP theme it is highly recommended to you have a deep a look at the WP hierarchy as well as the WordPress Theme Developer documentation.

The principle of WordPress - following conventions and offering a wide range of "Actions, Hooks and Filter" functions - instead of writing some own solutions will appear over and over again.

Another example would be page templates where WordPress uses "page.php" by default, and - in your case propably - you can extend on this by creating "page-templatename.php".

It is also vital for the use of a (child theme), that you:

  • allow your theme to be translatable (I18N) by using .mo/.po files, translation catalogues and so on, and
  • that you make use of template functions like "get_template_part('filename');"

One last tip, which I think is import to know is that WordPress has some priority mechanisms with the template files. It all makes sense if you look at the hierarchy.

The index.php is the fallback file for everything, but with increasing files in your theme folder WordPress becomes "more hungry" to load template files, which it can find, which is "front-page.php".

So in order to feed WordPress correctly, all you need to do is to provide that file, with the correct naming for WP.

Ouhhh: and almost forgot it:

Browse the plugin directory for "What the file". Great plugin which will help you a lot by showing the current template names (index.php, home.php) in the right upper corner, when you are logged in and the plugin is activated.

What the file

I hope that helps.

  • Thanks for your reply it helps me to understand some concept but still i am facing the same issue. i have added code of my file kindly suggest me to resolve issue. – Dpen Kdcha Jul 1 '18 at 18:25
  • Well, first you are not loading CSS and JS correctly, look at this post in order to correct this: wordpress.stackexchange.com/questions/263268/… – user3135691 Jul 1 '18 at 22:39
  • Secondly, as one of the comments mentioned, you should test your configuration of your WP environment before with theme twentyseventeen. If everything is working the way you want to work, you can start building with your own theme. What exactly is not working? Your index.php as well as your front-page.php should contain correct WordPress loops. If you don't know what that is, google for "WP the loop". – user3135691 Jul 1 '18 at 22:42

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