Enabling permalink pages in WordPress - php

I'm using <a href="<?php the_permalink();?>" Take me to another page </a> to take the user to a permalink page.
However, when I do, it is saying No input file specified.
I have the following files in theme folder:
footer.php
functions.php
header.php
style.css
index.php
How come this is not working — am I missing another php template file?

Your template files have to be in a directory under /wp-content/thmes/your-theme/. After you inserted them into the theme dir you have to activate your theme in the wordpress administration.
You need also at least a index.php File. That's the file where you place the functions for your content. In the index.php your include the header.php and footer.php with the Wordpress functions get_header() and get_footer().
I think you should better read the Documentations:
http://codex.wordpress.org/Using_Themes
http://codex.wordpress.org/Theme_Development

Related

How do I include the blog page in a custom WordPress theme?

I am pretty new to WordPress and I am trying to make a basic custom theme from scratch. The basic navigation menu is displayed and works on all of my pages except for the default blog page (which just appears as a blank white screen when clicked on). I have my theme split up into multiple files (header, footer, page, archives, etc). I think that the page.php file is what is supposed to display the blog, but it only works on the home, about, and test pages.
page.php:
<?php get header();?>
<div>
<h1><?php the_title();?></h1>
<?php if (have_posts()) : while(have_posts()) : the_post();?>
<?php the_content();?>
<?php endwhile; endif;?>
</div>
<?php get_footer();?>
post.php is not for the post type post it is for static pages or custom post-types.
You are looking for single.php or index.php.
This template Hierarchy from the Wordpress docs will help you.
Also see: https://developer.wordpress.org/themes/basics/template-hierarchy/
Style.css
Go to the WordPress default theme folder, open the style.css file. Copy the commented code at the top and paste it to the GlossyBlue style.css file. Change the theme name and the author information as you desire.
Splitting The Files
Now you need to understand where to split the file into several files: header.php, sidebar.php, and footer.php. The image below shows a simplified version of my index file and how the markups should split.
Header.php
Open the index.html file. Cut from the top to where the ends, paste it in a new PHP file, and save the file as header.php.
Sidebar.php
Back to the index.html file, cut from where the start to the closing tag of and paste it in a new PHP file, save it as sidebar.php.
Footer.php
Back to the index.html file, cut from the tag to the end of and paste it in a new PHP file, save it as footer.php.
Index.php
Now in your index.html file, you should only have the wrap. Save the file as index.php. Insert the line:get_header, get_sidebar, and get_footer in the same order as your layout structure.
Single.php
Now, it is time to do the single.php template. If you want, you can go through the same process — cut & paste from the default theme. But, I find it easier to use the index.php that you just created and save it as single.php. Open the default theme single.php file and copy the Template Tags over. Then include the comments_template. The image below highlights what I’ve changed:
Page.php
With the single.php template you just created, save it as page.php. Remove the post date, comment form, next/previous link… and that’s it.. there goes your page.php template.
Detailed document here : http://webdesignerwall.com/tutorials/building-custom-wordpress-theme
You question answer :
Copy page.php and rename it to single.php file.

Why doesn't wordpress need to include anything before using a function

When I use get_header(); in index.php, it automatically load the header.php file and and need not to include anything in the page.
Generally index.php is the main page. everything should be include there before it was called. Am I wrong?
It seems you are checking index.php inside the theme. But that is not the entry point to the site, but the index.php file in the wordpress root. There you can see it has included some files and inside those they have included some other files. Like wise file including functions are written in the wordpress core codes. So, you don't want to worry about including files in your theme. if you call get_header() function, the function itself has coded so that the relevant file to be included. If you are going to use a separate file to code functionality other than standard wordpress theme files, you'll have to include it at the top of functions.php

How to replace instance of WordPress home_url hyperlink via functions.php

The WordPress theme I'm using applies a home_url() link to the header logo and I'd like to change it to network_home_url()... Easy enough if I am editing the theme files but I'd like to do it via the child theme functions.php file so I can keep all my tweaks separate from the main theme (it's a multisite installation).
This is what I'm working with (albeit simplified):
<div class="logo">
<a href="<?php echo home_url(); ?>">
<img src="/image.png">
</a>
</div>
I've tried the following, which worked but resulted in a site-wide change (including WP settings, etc) which in turn broke all the permalinks:
add_filter('home_url', 'change_logo_link');
function change_logo_link($output) {
return network_home_url();
}
Is there a way I can target that specific hyperlink without editing the parent theme files? I don't think the home_url function is used anywhere else in the theme so it doesn't need to be too specific, I just want to avoid affecting the WP settings.
Thanks in advance!!!
The concept of child themes is to allow customizing of almost everything without changing the parent theme. Just copy your parent theme's template file with that logo code to your child theme's folder and replace home_url() with network_home_url(). WordPress will use that modified child template instead of parent one if you activate this child theme on your network site.

get_header wordpress function invocation

The first line of index.php is get_header();
There is no include / require in my index.php. yet the wordpress site continues to render the head section of home page by referring get_header() from general-template.php
How is wordpress framework achieving this?
get_header() is a function located in wp-includes/general-template.php.
This function includes the header.php template file from your current theme's directory.
If your theme contains no header.php file then this function includes the header file located in wp-includes/theme-compat/header.php.
You can find more information about this function in codex of Wordpress.org
The index.php you're referring to is the index off your theme. Within the root folder of your WP installation also an index.php is located. This is the first one called and starts the whole 'trip'.
http://theme.fm/wp-content/uploads/2011/09/wordpress-internals-how-wordpress-boots-up-382x600.png shows an image of the complete file load-sequence.

Include wordpress theme in a custom php page

I need to include a custom PHP page in Wordpress.
So what I need to do is just to show this custom php page using the Wordpress theme installed on that Wordpress.
Does not mind which theme is up, the custom php page will have to be shown under any theme is installed in that moment.
How do I do it in Wordpress?
I am new to Wordpress development.
Thanks
Creating a custom php page that will be able to be viewed in any theme (and have the theme applied) would be considerably difficult.
Each wordpress page calls specific theme functions of that particular theme, as well as referencing files of that theme to generate header, footer, css files, javascript files, etc.. Your custom page would need to plan for all of these contingencies, for each possible theme used.
Here's a alternative solution: inject PHP code directly into a standard wordpress page via this plugin http://wordpress.org/extend/plugins/allow-php-in-posts-and-pages/
Meaning: you make a normal wordpress page, but are able to add php to it. When this page is rendered, the proper page template is used, and all the theme references are taken care of for you.
You could do this easily with a page template. WordPress allows you to create page templates which can be assigned to a page via the 'Page Attributes' panel within the page editor. These templates are php files inside your theme directory which begin with some code like (see this page in The Codex for more info):
<?php
/*
Template name: Custom PHP Page
*/
?>
<?php // begin custom PHP page ?>
Typically a template is a variation on the regular theme files (such as page.php) and would call the get_header() and get_footer() functions and have an instance of the loop. However if you simply want to use a custom PHP page, then all you need to do is create the file you want inside the current theme directory and add the above code at the very top of the file.
To output the custom PHP page on your site, you would need to add a new page via the admin area and then assign your new page template to this page.
Alternatively, if you want to include a custom PHP page inside an existing theme file, you use the code:
<?php include(TEMPLATEPATH . '/includes/file.php'); ?>
in this case your custom PHP file would be located inside a directory called 'includes' within your current theme directory.
Tim.
It's not that difficult. Here's what you need:
Once you include the main wordpress blog header, the entire armamentarium of wordpress functions is available to you, which allows you to get the active theme's directory. Once you get that, just include the header and the footer of the theme.
// If title is not displayed before loading the header, Wordpress displays "Page not found" as the title
echo "<head>
<title>Your page title</title>
</head>";
// Include the Main Wordpress blog header
include $_SERVER['DOCUMENT_ROOT']."/wp-blog-header.php";
//Now, you need to get the active theme's folder, and get a relative path to that folder
$homeurl=home_url();
$ddir= get_bloginfo( 'template_directory');
$current_theme_relative_path=substr_replace($ddir, "", 0, strlen($homeurl));
//echo "<br/>The relative path to the currently active theme is ".$current_theme_relative_path;
//Once you have the path, include the header and footer, adding your custom php code in between.
// Include the specific theme header you need
include $_SERVER['DOCUMENT_ROOT'].$current_theme_relative_path."/header.php";
// Your custom PHP code STARTS here
// Add anything you want to display to the user
echo "
<h2>
Your form has been submitted
</h2>";
// END of custom code
?>
<?php
}
// Now end with the theme's footer
include $_SERVER['DOCUMENT_ROOT'].$current_theme_relative_path."/footer.php";
?>
Was very helpfull (even if dated of 2011-13)
Also, as a thank you, i'm sharing the version i made
it's usefull if your wordpress folder is not located at ROOT
PasBin Link - wordpress custom php page
just change the value of $wplocalpath in :
// Wordpress path (if wordpress is not located at ROOT
// $wplocalpath="/Wordpress1";

Categories