WordPress.org

Ready to get started?Download WordPress

Forums

Using PHP files with wordpress (11 posts)

  1. orgzchaos
    Member
    Posted 2 years ago #

    I was looking through the documentation and seems like what I was trying is valid thou it is not working for me.

    I have created a PHP file example.php and put it in the template's root directory. Now when I am trying to open http://myblog.com/example it simply throws me to the 404 page and not example.php. I checked and double checked in the documentation and it should be working fine like this. What am I doing wrong here?

  2. Pioneer Valley Web Design
    Member
    Posted 2 years ago #

    I was looking through the documentation and seems like what I was trying is valid thou it is not working for me

    Please review this again, but first to access your site again, remove that file using an FTP tool or your host provided file manager.

  3. fonglh
    Member
    Posted 2 years ago #

  4. Pioneer Valley Web Design
    Member
    Posted 2 years ago #

    Or set as default page (with proper coding).

  5. michael.mariart
    Member
    Posted 2 years ago #

    I have created a PHP file example.php and put it in the template's root directory. Now when I am trying to open http://myblog.com/example it simply throws me to the 404 page and not example.php. I checked and double checked in the documentation and it should be working fine like this. What am I doing wrong here?

    Simple. The URL of the file example.com is http://www.yoursite.com/example.php and not http://www.yoursite.com/example

    If you use the full file name, that page will show up as you expect. Becuase you are not using the full file name, the server doesn't find that file, so it throws the requst back to the default catch-all that's in place for WordPress, which gives you the WordPress 404 error.

  6. haxxxton
    Member
    Posted 2 years ago #

    if it was in the site's root directory the above should work :)

    except if it is in the

    template's root directory
    you will probably need to link to it using the WHOLE url like:

    http://www.yoursite.com/wp-content/themes/your-theme/example.php

  7. orgzchaos
    Member
    Posted 2 years ago #

    Agree to the post above, I tried it earlier and it was working that way but still couldn't get it to work as http://mysite.com/myphppage

    I saw the docs again and it was pointing towards modifying the page.php file besides doing what I did before but I still can't put in the pieces for the whole scenario because I was in kind of a rush to get it done.

    For example, I have a file myphppage.php which uses the get_template_part('loop','myphppagecontent') to fetch the rest. What exactly do I need to modify in page.php because that seemed to be pretty generic to me and nothing about assigning certain permalinks to certain files. Or some other way to get this done?

  8. fonglh
    Member
    Posted 2 years ago #

    What are you actually trying to do? Access an arbitrary PHP file which just happens to be placed together with the WordPress files? Or are you trying to write a page template?

  9. orgzchaos
    Member
    Posted 2 years ago #

    What I am trying to do is make alternate versions for the main index.php file, ones that display posts based on certain custom field so the alternate php file will stay as a page template just like the main file.

  10. fonglh
    Member
    Posted 2 years ago #

    See http://codex.wordpress.org/Template_Hierarchy to check which file gets called first. It may not be index.php, but that depends on whether your theme has other templates which might be used first.

    You'll need to add the conditionals for your custom field into page.php, and use get_template_part() to get the custom template you want to use.

    You don't access the page template directly. You access the permalink of the page and WordPress if you've coded your conditionals correctly, WordPress will fetch the relevant template file.

  11. orgzchaos
    Member
    Posted 2 years ago #

    I was going through how to put in conditions in the current page.php file without having to create a new template file but got lost a little bit.

    Following is my page.php file:

    <?php get_header(); ?>
    
    		<div id="container">
    			<div id="content" role="main">
    
    			<?php get_template_part( 'loop', 'page' ); ?>
    
    			</div><!-- #content -->
    		</div><!-- #container -->
    
    <?php get_footer(); ?>

    Following is my loop-page.php file:

    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    
    				<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    					<?php if ( is_front_page() ) { ?>
    						<x2 class="entry-title"><?php the_title(); ?></x2>
    					<?php } else { ?>
    						<x1 class="entry-title"><?php the_title(); ?></x1>
    					<?php } ?>
    
    					<div class="entry-content">
    						<?php the_content(); ?>
    
    						<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'imbalance2' ), 'after' => '</div>' ) ); ?>
    						<?php edit_post_link( __( 'Edit', 'imbalance2' ), '<span class="edit-link">', '</span>' ); ?>
    
    						<div class="clear"></div>
    
    					</div><!-- .entry-content -->
    				</div>
    <!-- #post-## -->
    <?php endwhile; // end of the loop. ?>

    Now I have the loop-index.php ( and index.php ) which sort contents based on their posting date. I can manipulate those and create four new files i.e. loop-lowest.php ( and lowest.php ) and also loop-highest.php ( and highest.php ) to get the job done as required, what exactly do I need to edit in the two page files shown above to get the two manipulated files to show up at http://myblog.com/lowest and http://myblog.com/highest?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.