Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTrent Burkenpas
22,388 PointsLinks are not connecting to single-page.php
So I created the the_permalink() function just like the video. But when i click on the link it sends me to a page with a error message .
"This webpage has a redirect loop"
though it says in the address bar that i'm in the right page. (I clicked on the Dr. Wattz link)
"http://localhost/allisongrayce.com/work/dr-wattz/"
Here is my code:
<?php
/*
Template Name: Work Page
*/
get_header(); ?>
<p>This is the Work.php file</p>
<?php
$args = array(
'post_type' => 'work'
);
$the_query = new WP_Query( $args );
?>
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h3><a href="<?php the_permalink() ;?>"><?php the_title(); ?></a></h3>
<?php the_field( 'description' ); ?>
<hr>
<?php endwhile; else: ?>
<p>There are no post or pages here</p>
<?php endif; ?>
<?php get_footer(); ?>
This is the work.php page
Any advice would be great thanks!
18 Answers
Sean T. Unwin
28,690 PointsIn your terminal: cd
to your WordPress root directory.
-- cd ../
to go up one directory and type ls -l
(that is a lower-case "L")
-- wp root dir should be - rwx-r-x-r-x
-- this is equal to chmod 755
(if there is a "d" at the start it means directory, if there is a "-" or "f" it means it's a file)
-- FYI: All WordPress files should be set this by default (chmod -R 755 "%WP-ROOT-DIR%"
-- -R
means recursively, in other words, all files/folders inside) with the exception of .htaccess
and wp-admin/index.php
(these are set to chmod 644
)
-- go back inside wp root dir and type cd ls -al
(-a
is for all files including .htaccess
, and again that is a lower-case "L")
-- .htaccess
shoud be - rw-r--r--
-- this is equal to chmod 644
-- cd wp-admin
-- ls -l
-- index.php
should be rw-r--r--
(chmod 644
)
- If you need help with using
ls
type:ls --help
orman ls
. - If you need help with
chmod
type:chmod --help
orman chmod
. -
Search for tutorials online
References:
http://codex.wordpress.org/Hardening_WordPress#File_Permissions
Sean T. Unwin
28,690 PointsIt might be a quick fix to flush your permalink settings.
Go to Settings -> Permalinks : Common Settings - select a different option briefly then change it back to what you had it and save.
If this doesn't work then perhaps there is a permission issue either with your directories or .htaccess.
Trent Burkenpas
22,388 PointsHmm well the flush didn't work. You think it has to do with my MAMP?
Zac Gordon
Treehouse Guest TeacherHmm, are you getting the error message on the main work page or the single work page? This looks like the code for the main work page, but URL you mention would seem to be run by the single-work.php or single-portfolio.php, whichever you named it. What does that file look like?
Trent Burkenpas
22,388 Pointsoh its on the single-work.php file.
Heres the code for that file :
<?php get_header(); ?>
<p>This is the single-work.php</p>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_feild( 'description' ); ?>
<hr>
<?php endwhile; else: ?>
<p>There are no post or pages here</p>
<?php endif; ?>
<?php get_footer(); ?>
Thanks!
Zac Gordon
Treehouse Guest TeacherIs this the page that is throwing the error or the main work page? What happens when you remove the Loop code for the single-work.php page. Does the error still appear?
Trent Burkenpas
22,388 PointsNo its on the single work page. And yeah the error is still appearing after i got rid of the loop.
Zac Gordon
Treehouse Guest TeacherHmmm, interesting. Keep removing code and see what might be causing the issue. Is your custom post type slug named "work"?
Trent Burkenpas
22,388 Pointsyeah the custom post slug is work, I heard it might be a permissions issue? is there any truth to that?
Trent Burkenpas
22,388 PointsLike in the config file for MAMP, I need to turn off a setting...idk. I see a lot of other people have this issue and I have seen 100 different solutions.
Trent Burkenpas
22,388 PointsOk so when I cd to the folder that is holding all the WP files. I assume thats the root dir. So for this project is is called "allisongrayce.com" that is the folder that is in my htdocs, holding all the WP Files. Is that the root dir.? and when I ls -l the file I see all the files in the folder. It looks like this
-rw-r--r--@ 1 burkenpastrent staff 418 Sep 25 2013 index.php
-rw-r--r--@ 1 burkenpastrent staff 19930 Apr 9 23:50 license.txt
-rw-r--r--@ 1 burkenpastrent staff 7192 Mar 3 01:34 readme.html
-rw-r--r--@ 1 burkenpastrent staff 4896 Dec 24 17:57 wp-activate.php
drwxr-xr-x@ 89 burkenpastrent staff 3026 May 4 15:37 wp-admin
-rw-r--r--@ 1 burkenpastrent staff 271 Jan 8 2012 wp-blog-header.php
-rw-r--r--@ 1 burkenpastrent staff 4818 Feb 18 20:45 wp-comments-post.php
-rw-r--r--@ 1 burkenpastrent staff 3087 Oct 24 2013 wp-config-sample.php
-rw-rw-rw- 1 burkenpastrent admin 3375 Apr 30 13:24 wp-config.php
drwxr-xr-x@ 8 burkenpastrent staff 272 May 4 15:38 wp-content
-rw-r--r--@ 1 burkenpastrent staff 2932 Sep 25 2013 wp-cron.php
drwxr-xr-x@ 124 burkenpastrent staff 4216 May 4 15:38 wp-includes
-rw-r--r--@ 1 burkenpastrent staff 2380 Oct 24 2013 wp-links-opml.php
-rw-r--r--@ 1 burkenpastrent staff 2359 Oct 24 2013 wp-load.php
-rw-r--r--@ 1 burkenpastrent staff 32671 Apr 13 16:06 wp-login.php
-rw-r--r--@ 1 burkenpastrent staff 8235 Nov 13 10:58 wp-mail.php
-rw-r--r--@ 1 burkenpastrent staff 11070 Apr 7 20:15 wp-settings.php
-rw-r--r--@ 1 burkenpastrent staff 25665 Nov 13 02:23 wp-signup.php
-rw-r--r--@ 1 burkenpastrent staff 4026 Oct 24 2013 wp-trackback.php
-rw-r--r--@ 1 burkenpastrent staff 3032 Feb 9 19:39 xmlrpc.php
now am i headed in the right direction?
This is what the allisongrayce.com folder looks like
drwxr-xr-x 24 burkenpastrent admin 816 May 4 15:37 allisongrayce.com
Trent Burkenpas
22,388 PointsOk so after looking at all the files index.php, and .htaccess are chmod 644. And my Root Dir is equal to chmod 755.
Sean T. Unwin
28,690 PointsAnd you're still getting the redirect loop error?
Trent Burkenpas
22,388 Pointsyes. it looks like its not a permissions issue. This is very frustrating. Then I read that if you delete your cookies on chrome it will sometimes work, But i'm working locally i cant imagine that working :(
Sean T. Unwin
28,690 PointsTry another browser? Sometime you'd be surprised what ends up getting things to work. :p
Trent Burkenpas
22,388 PointsWell I tried fireFox and this is what I got.
"Firefox has detected that the server is redirecting the request for this address in a way that will never complete."
So pretty much the same thing. I guess it something with my code. Idk I just mess around with it. Thanks for the help
Trent Burkenpas
22,388 PointsSo after messing with files and stuff. I broke my WordPress.. lol, and I decided to start from scratch. I restarted the project and i'm still stuck on the same issue. What could it be :(
Trent Burkenpas
22,388 PointsZac Gordon, Hey I have found that when I deactivate the CTP UI plugin the redirect loop goes away. IDK if that has anything to do with it. But I don't understand why i have this error. I have read everything on redirect loops and I even spoke to one of the developers of the CTP UI plugin. Im not having any luck :(. I just can not find any clues on what could be going on.
Just a recap:
Im developing locally with MAMP And the redirect loop happens when I click on a link in the work page.
Zac Gordon
Treehouse Guest TeacherHi Trent,
I'm not sure what the problem is here then offhand, sorry :-/
Trent Burkenpas
22,388 Pointsno worries
Clayton Knight
5,280 PointsSean T. Unwin I flushed my permalinks and it worked like a charm. Thanks!
Kevin Murphy
24,380 PointsKevin Murphy
24,380 PointsSean T. Unwin - I'm in the process of clarifying my understanding of .htaccess, its permissions, and practical WP usage. Your explanation on permissions is definitive in my search. Thank you for the detailed response.