I have created html pages and trying to convert into wordpress theme,how to link html one page to other page in wordpress menu bar
sample code :
Features
this code is not working,it 's showing page not found.how to make this link in wordpress using php code.
Firstly Create Page "Features" from wp-admin.
Create template for this page.
http://codex.wordpress.org/Stepping_into_Templates
To set this page in menu Go in "Menu" section in WordPress.
http://codex.wordpress.org/Appearance_Menus_Screen
To view this menu in fronted use wp_nav_menu()
Take example template from your theme.
This is file in theme ending with -page.
Change template name in head of a file.
Then remember about the_loop all should be inside a loop to work correctly with many pages.
Put html there, also in header.php attach css to this html.
Page structure is like, header in the up, then page and then footer.
Remember to preserve good html structure - divs beginning and ending.
Then you create a page with content ( which is presented in the_loop ) , which has its own url address.
You can set url naming of pages in settings -> permalinks, you may need to write to .htaccess file.
Then you have direct url to page. You can use it in code like this:
echo bloginfo('url'). 'nameofpage';
All to do is create a template and assign it to page ( on page edit page template option ).
You can use pages or posts for this, i prefer pages.
Create new pages or posts and get their ID.
For linking its:
Get link with this:
get_permalink( $yourPostOrPageID ); // only get; not echo
Otherwise
Wordpress homepage link:
get_bloginfo('home');
Category or custom taxonomy term link:
get_term_link( $term, $taxonomy );
Related
I need to add a header Access-Control-Allow-Origin: * into one of my template files. How would I do this I would like it to be for just this specific template so that its not site wide,
I think you're looking for is_page_template();
<?php
if(is_page_template('your-page-template.php')) { //Change this to the path to your wordpress template
//Add your code here...
} ?>
you can create a custom template page and call the custom Header on this template.
To create a page and apply a page template
use this code to create page template
First you need to have a single page. There are several ways to do it, one is to create a page in wordpress, then use the ID and create a file page-ID.php in the theme folder. Other way is to create a template file which you can select from the side menu in the wordpress editor.
In that page, you can add the php header and the code you want to show.
I have a .php file which uses some WP functions e.g. get_stylesheet_directory_uri(), query_posts, etc... and $wpdb of course.
File it self return JSON data so it is not intended for viewing on its own.
I'm not looking for template, or clicking around in WP dashboard, I just want to know where is the good place in WP file structure to put the .php file and expect WP functions and object to be available.
And also what do I need to include at the top?
You can create custom template in theme root directory or in child theme (child theme is important when you are creating custom template).
template should contain template name, header and footer function.
eg. custom-tpl.php
<?php
Template Name: My Custom Temlate
get_header();
//your other functions and content goes here
get_footer();
after creating template it will appear in your edit page template section under drop down. select custom template for your page and view page you will get your output
You can create a custom page template.
Inside the page template:
<?php
global $wpdb;
[here you will write your code]
?>
On the front pages where you want the json output, use this url
http://domainname.com/wp-content/themes/themename/custompagetemplatename.php
Use your domain name (domainname), theme name (themename) and theme template file name (custompagetemplatename) in place of example names in the url. This url will return you the output for your code.
About this comment in your template:
<?php
/* Template Name: Full Width Page */
?>
You do not need a template name in the header of your file unless you want to use this as a template for pages in wordpress.
I am relatively unfamiliar with Wordpress and I am creating a custom theme for a client. I would like to either display or remove the main menu depending on the page type. I have researched several options like removing the navigation from header.php and referencing it separately and also making the menu conditional which is preferable.
I have a custom page type in my theme called 'landing page' on which I would like the menu to be never be displayed, though it will be on every other page. Ultimately there will be a lot of these and I would rather I didn't have to intervene.
I would rather not duplicate my header.php file but I can only find reference to displaying the menu conditionally like below by page name or ID which seems ridiculous.
<?php
if (is_page('contact')){
<?php include(TEMPLATEPATH.'/headerA.php'); ?>
}
elseif (is_page('gallery')){
<?php include(TEMPLATEPATH.'/headerB.php'); ?>
}
else {
<?php include(TEMPLATEPATH.'/headerA.php'); ?>
}
?>
Rather than including files as above, I will put the whole thing into my header and just make the navigation conditional. Does anyone know how I should approach this using my custom page type landing page rather than by page name so every page created with that type will never have a menu?
Thanks
Are you talking about a Custom Post Type (CPT) or a page called landing-page?
They are completely different. See http://codex.wordpress.org/Post_Types
In any event, this will work for a custom post type or a page:
if ( !is_singular( 'custom-post-type-name-or-page-slug-here' ) ) {
get_template_part('menu');
}
It says: "If this page is not a single page or a CPT, load the file menu.php from the theme folder."
See also http://codex.wordpress.org/Include_Tags:
The get_template_part() tag includes the file {slug}.php or
{slug}-{name}.php from your current theme's directory, a custom
Include Tags other than header, sidebar, footer.
I want to change the meta description on my Wordpress website for a certain page that queries all the posts containing a certain tag.
The page I am talking about looks like this:
mainwebsite.com/tag/tag-name
So I want to add in the header.php file a conditional where I can change the meta description only on that page. I tried the following:
<?php if(has_tag('this-is-the-tag-name')){
echo 'test';
}
?>
And this puts "test" on every single tag page. I want the change to apply only on the tag page "this-is-the-tag-name."
Say your tag name is "slug". Look at the template hierarchy for tags. Wordpress will start from the top, and work its way down until it finds an available template to display the tag
tag-slug.php > tag-id.php > tag.php > archive.php > index.php
With that said, if you create a template called tag-slug.php, you can simply add a if( is_page_template( 'tag-slug.php' )) statement to your header or functions.php, and your conditions will only display on that specific page.
I have a php site template and i want to create hyperlinks to the homepage on the internal pages. I tried this code which works in wordpress but doesn't work on my template: anchor text
What alternative code i can use to replace <?php echo home_url(); ?>, so it will work on my php template?
edit:
This worked Homepage! but i have another problem. In my php template the most recent pages are displayed on the homepage in a same way as a wordpress site. For the inner pages I am using this code page title to create hyperlinks for the page title similiar to the blog posts in wordpress. The problem is that the pages on the homepage are linking to the homepage not to the page url. For exmple, page with title Blue Widget has this page url domain.com/blue-widget, but when the page is displayed on the home page the page title is linking to domain.com.
How can i make the page title that are displayed on the homepage to link to they corresponding page url and not to the homepage. The same way blog posts that are dispalayed on the homepage of wordpress site are linking to they blog post pages.
Homepage link is just (when you have one domain):
Homepage!
Create a constant, somewhere in a central place like a config file. Then use it throughout the script.
define ('SITELINK', 'http://www.stackoverflow.com');
And in your template:
Go to home!
Or you can wrap it into a function:
<?php
function home_url(){
return SITELINK;
}
?>
Go to home!
Go to about page!
For referring only homepage:
In php
echo 'anchor text';
In Html
anchor text
Use "/" to redirect to home page from any other page.
The problem with $_SERVER['SERVER_NAME']; is it can be unreliable on some instances such as subdomains, etc...
Here is WordPress' Reference Manual: http://codex.wordpress.org/Function_Reference/network_home_url
In WordPress you can use:
$url = network_home_url();
echo $url;
So for you example it would be:
anchor text
Hope that helped.
<?php
function home_url(){
?>Go Home<?php
}
home_url();
try to use $_SERVER['SERVER_NAME']; to get the home URL
Home