Adding Wordpress header into a subfolder page - wordpress

Okay. I have wordpress installed on the root. I also have uploaded a subfolder within wordpress. www.mysite.com/subfolder/ I want to be able to add some php pages inside the subfolder because I need it to call some scripts. I just want to be able to add the wordpress header into it. The pages come up but when I add the wordpress header it all goes blank or just does nothing.
I have tried...
'
<?php include 'http://www.mywebsite.org/wp-blog-header.php'; ?>
<?php require('http://www.mywebsite.org/wp-blog-header.php');?>
and tried
<?php include 'http://www.mywebsite.org/wp-content/themes/MYTHEME/header.php'; ?>
<?php require('http://www.mywebsite.org/wp-content/themes/MYTHEME/header.php');?>
and
<?php include './wp-content/themes/MYTHEME/header.php'; ?>
<?php require('./wp-content/themes/MYTHEME/header.php');?>
Nothing seems to be working.
Any help would be great...Thank you.

Looks like the problem is you're including the URL to wp-blog-header.php, you should instead include the relative path, then call get_header(); as usual. So you should have something like this:
<?php
require('/the/path/to/your/wp-blog-header.php');
get_header();
?>
Check out the Integrating WordPress with Your Website Codex entry.

Related

Wordpress website with blog page structure

I've built a website (locally) that works just fine and, I've written the home page content in the Index page as I'm accustomed to and, different templates (page1.php, page2.php) for pages that required different layout for the 'About' and 'Contact' pages etc. Since deciding to add a blog though it has me stumped. I've written a blog page and it looks just fine but when I try to view a post I'm just directed back to index.php. I know it's down to the structure but it's confusing. An index page is mandatory, and you should probably have a front-page.php too. If that's the case..which one should I write my home page on? Index page doesn't show in the reading list and choosing "front page' as a static page works but still the blog links go back to index. If I was to put the content from the index page into front-page.php, what would I have in the index page?
Although the Wordpress docs are good I can't really find anything to suggest which way round all this stuff would be.
Your issue is that WordPress by default uses the index.php file for the blog archive (as well as other archives, etc.) and you need to use front-page.php for a dedicated home page with your custom content.
Read https://developer.wordpress.org/themes/basics/template-hierarchy/ on how to construct a standard WordPress theme with template files that follow a standard hierarchy.
The front-page.php template file is used to render your site’s front
page, whether the front page displays the blog posts index (mentioned
above) or a static page. The front page template takes precedence over
the blog posts index (home.php) template. If the front-page.php file
does not exist, WordPress will either use the home.php or page.php
files depending on the setup in Settings → Reading. If neither of
those files exist, it will use the index.php file.
Duplicate index.php and call it front-page.php. Edit index.php to be a basic template with a standard loop (and none of your home page content) so that it can function as a blog template that displays the_excerpt or the_content, something like this:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<?php endwhile; else: ?>
<?php _e( 'Sorry, no posts matched your criteria.', 'textdomain' ); ?>
<?php endif; ?>
See https://developer.wordpress.org/themes/basics/the-loop/

WordPress Calling Function Outside

How to get value using
<?php get_theme_mods('emailaddress') ?> in file insde theme folder?
Actually I have registered a field to set email from WordPress customize section. <?php get_theme_mods('emailaddress') ?> is working fine when I display on WordPress pages or posts but it does not work when I try to get value on formhandler.php file inside theme folder.
When form is submitted, the form calls the file formhandler.php inside theme folder. So, I want to get value using <?php get_theme_mods('emailaddress') ?> to use email sent to email.
Why is <?php get_theme_mods('emailaddress') ?> not working inside formhandler.php file? This file just process the form and sends email.
Include wp-load.php at the top of formhandler.php. You will find wp-load.php in the root. If formhandler.php is on the root of your active theme then use the following include statement.
<?php include '../../../wp-load.php'; ?>

Page layout (page.php) doesn't apply to pages

I made few pages in my admin panel. Then created page.php with this code inside
`<?php get_header(); ?>
<section>
<?php if (have_posts()): while (have_posts()): the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
</section>
<?php get_footer(); ?>`
Set one of this pages as "homepage". And when i open site it shows me header, footer... everything it should, but when i try to open any of the other pages, I get 404 page...
Help me please, where i have to search for mistakes?
Thank you
You need to define one of the following: index.php (REQUIRED), home.php, or front-page.php.
Here's the way template inheritance works for the home page:
WordPress looks for front-page.php, regardless of whether or not your site is set up to show a static front page, or your most recent posts
If front-page.php doesn't exist, WordPress looks for home.php
If no home.php is set, WordPress defaults to index.php
You can read more about template inheritance in the codex.

Wordpress: Implement basic HTML form functionality to retrieve data and visualize the results

I have experience in HMTL/PHP but I cannot understand how someone could implement this basic functionality in Wordpress. I could not find an article or web page on their website or by searching through the internet.
I want to create a basic html form, pass some data as select queries in a database and visualize back the results paginated.
In traditional PHP we are using "action" in order to send the form data through POST or GET to the action page and then with some PHP code we can fetch the data and visualize it with tables etc.
I cannot understand how to do such a thing in a wordpress page. Where the action parameter should point to? How could I implement this basic functionality in WordPress?
Please could someone help?
This is the mode to develop a separated .php file which uses your wordpress theme and can access to almost all wordpress functions:
<?php include(’wp-blog-header.php’); ?>
<?php get_header(); ?>
<!– Your code here –>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Then you can use all WordPress functions cited here: http://codex.wordpress.org/Function_Reference
You can save this file anywhere, but be sure to insert correct path to wp-blog-header and there must not be any prohibiting .htaccess
This is the way to insert php code into a wordpress post:
You have to use this plugin http://wordpress.org/plugins/allow-php-in-posts-and-pages/
Then create a post and use [php] [/php] to insert your php code and open it. Look at the address bar. This it the URL to access this post. Use it as action parameter in your form. Then control $_REQUEST[] in your php code to extract parameters received from your form.
Now you can control this post as any other normal wordpress post from the wordpress admin panel.
You need to create custom wordpress templates for pages in your theme. Here i use templates
1.form-page.php --- with template name "Form-page-template" and
2.form-page-action.php ---with template name "Form-page-action-template"
form-page.php
<?php
/*
Template Name: Form-page-template
*/
?>
<?php get_header(); ?>
<form method="post" action="http://yourdomain.com/form-page-action/" name="input-form"/>
<!-- form contents -->
</form>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
You just save this template inside your theme : location => like wp-contents/themes/your-theme/form-page.php . and this will add Form-page-template in your theme .Now create a page inside from wordpress dashboard through pages->addnew ,here i give page name "form-page" and select template for page from right pannel,here we need to select "Form-page-template" that we created early.
Now we have the page url :: http://yourdomain.com/form-page/ where we can see our form,now create form-action-page.
2.form-page-action.php
<?php
/*
Template Name: Form-page-action-template
*/
?>
<?php get_header(); ?>
<!-- Your action page contents goes here -->
<?php
//getting input etc.. you need to do
$input = $post['input'];
?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Now you need to save this template inside your theme as above, Create a new page for this template as said above here i creating a page "form-page-action" with template "Form-page-action-template" so here i get a page url for our
action page like :: http://yourdomain.com/form-page-action/ , and you need to use this url as the action url in your form page.and this way you can add your form action page inside wordpress theme.
You can edit the contents of these page inside from wordpress like=> Appreance -> Editor , select the templates to edit.

page redirection in wordpress

what I have:
a google search form (displayed on all pages)
a wordpress page to display search results
what I want to do:
when a search is performed, redirect to the page containing the search results
how do I do this?
the search results page is a wordpress-created page with a permalink domain.com/search-results
if your template files doesn't have a file called "search.php" then create one,
this is were all the results will be shown, do a standard wp loop and style it..
thats if you were using the standard wp search, in this case
apply a template tag to the top of a new php page,
<?php
/*
Template Name: Search_Results
*/
?>
<?php get_header(); ?>
or include a new one
<?php include(TEMPLATEPATH . '/header_search.php'); ?>
<!-- INCLUDE GOOGLE SCRIPT -->
<?php get_sidebar();?>
<?php get_footer();?>
this should print out your results...

Resources