Backstory: I've been dealing with this website for the past 5 months. I didn't have previous experience with Wordpress, but I had some with HTML, CSS and PHP.
I have two different ways to display posts on my custom Wordpress template.
On the "Services" page, a post is loaded onto a dynamic content div by clicking on different buttons. Each button loads a different post on the same div by calling specific post ID's:
<a
href="#contentBox1"
class="dem_buttons"
onclick="loadPage1('<?php the_permalink(361) ?>')"
target="#contentBox1">
</a>
<div class="text-center clearfix" id="contentBox1"></div>
On the "Search" page there is no dynamic content div. Each search result consists on an image, the title and the excerpt of the post. The posts are acessed by clicking on their respective titles after the search results come up.
Here's the problem: If I don't include the header and the footer on single.php, the post will be loaded without styles, navigation bar and footer after clicking the title of the search result. I need to load the header and the footer on single.php because of this search page, but this means there will be a second header and footer on the dynamic content div of the "Services" page, as well.
I've tried starting single.php with:
<?php
if ( is_page([page id]) ) { ?>
[single.php's content]
<?php
} else {
get_header(); ?>
[single.php's content]
<?php get_footer();
} ?>
to no success. I've also tried out !is_page, but no luck on that either.
Please don't recommend plugins. I really need to code everything by hand. The written reason for that would be longer than this post.
The final solution was to rearrange the parts of single.php so that it used include (or require) for showing the given post's content (named here: postcontent.php).
// Pseudo code
get_header()
// postcontent.php is the body of the post
include_once( postcontent.php )
get_footer()
This way the single.php had its header and footer, but the "Services" template could include the post's content directly:
// Pseudo code
// Template: Services
get_header()
// the content of the "Services" template
services_content()
// postcontent.php is the body of the post referenced
include_once( postcontent.php )
get_footer()
This way headers and footers are there on both pages, and there are only one header and footer on each of them.
I'm not 100% sure on the Wordpress side of all this, but could you perhaps wrap the second/first header in a div with a specific id, then give that id a style of display none? Like below:
HTML
<header class='header'> ..... </header>
<div id='hidden-header'>
<header class='header'> ..... </header>
</div>
CSS
#hidden-header {
display: none;
}
Let me know if that helps or not and maybe I can see if I can find something else.
Related
I m building a word press site with a unique theme that i created, now i got like 10 classes of different styles for the static pages in my site.
The question is, when i want to display the content of the page, with all the forms images and text, how should i do that? With the text editor where the user usually insert his content for the posts in regular wp website? Or should i insert the content images and forms hard coded in the php custom page template of those static pages?
In the text editor if i insert some html in edit as html it's becoming a mess it doesn't seems right to create sections and div where the user regularly just put his raw content, and anyway adding more content to a static page in the future will require my intervention to wrap it with css sections and div's definitions and classes...
By the other hand to write raw data with images and forms in the php custom page template doesn't seems to me the right choice... Is it normal to do so for static pages?
Thanks everyone!
Wordpress static pages, by default contains text and images that you can put into it using the Wordpress text editor. This content is known as "The Content" in WP context.
If you want to put into your static page some elements that cannot be setted by the text editor (like your own forms, per example) you'll need to create your own page template with hard-coded elements.
Example:
<?php /* Template Name: My custom page template */ ?>
<?php get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="article">
<div class="date"></div>
<!-- Your own custom content here -->
</div>
<div class="clear">
<?php if ( comments_open() ) : ?><div id="comments"><?php comments_template('', true); ?> </div>
</div><?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
<?php get_footer(); ?>
I normally will put those styles into styles.css of your theme. Even if it's images that will be standard images for the theme or shortcodes available to the user you want it to load from within the styles.css page. You don't want to do anything static like that with WordPress. Updates can mess it up as well as having issues with inline css messing up your SEO for the site.
If the user needs to do something in the editor to have an image show or something like that you can do it as a shortcode. That's normally going to be your best approach. Have you used shortcodes and loaded the images that before?
I have an HTML template which I am trying to convert into PHP for WordPress.
The homepage has been converted and is shown properly. Next, the menu in navbar is about, the page that needs to be converted in PHP.
I have just added get_header() at the top and get_footer() below. In between these two I have added the HTML content for my entire page.
Then I tried to provide the link for the menu that I created, but the content of about page is not visible.
Do I need to add any other line for that page apart from get_header and get_footer? Or is something wrong with the link?
Clearly I can't understand what your are trying to say. I think you want to create a page that will show your about menu content.
So in your theme directory create a page name page.php and use get_header(); in first and below get_footer and where you want to show page content write the_content();. like this
<?php
get_header(); ?>
<div><?php the_content(); ?></div>
<?php get_footer(); ?>
after that follow the url of # Sajid Anwar. because for dynamic data you have to create pages(home,about etc) from wordpress dashboard and in menu section add these pages as navigation menu to menu.
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 have a theme that I am developing using the _s (aka: underscores) theme.
I do not want my archives to include the sidebar.php file.
My archive.php and paged.php files do not have the sidebar.php
included.
I created a home.php file which includes the get_sidebar()
function, and edited my index.php to not include that function.
I'm still seeing my sidebar when I click "Older Posts" on my site which brings me to: MYDOMAIN/?paged=2 -- this is not what I want.
Specific archive pages (such as for months and categories) do not display the sidebar, which is what I want.
I only want the sidebar to appear on the front page of the site.
I checked the body tags on my home page and on the paged "Older Posts" archive pages to determine what template is being rendered.
Home page:
<body class="home blog">
paged "Older Posts" archive page:
<body class="home blog paged paged-2">
This leads me to believe they are both using the home.php template. How can I get those pages to use a different template?
What am I doing wrong?
A friend helped me resolve this issue and I thought I'd share our solution. In order to make sure the sidebar appeared only on the front page of the blog and not appear on the ?paged= pages, we added some conditional statements around the call to the sidebar on home.php:
<?php if ( !is_paged() ) { ?>
<?php get_sidebar(); ?>
<?php } ?>
Additionally, this code could be added to the sidebar to keep it from appearing on other pages such as category pages, single posts, etc. While this wasn't necessary since I had used specific templates for those pages that did not include the sidebar, here it is in case it's useful for others:
<?php if ( is_front_page() ) { ?>
<!-- ALL CODE FOR YOUR SIDEBAR HERE -->
<?php } ?>
I need to create a page which is an exact copy of my index.php page. I have duplicated index.php and renamed it page-newindex.php and included
/*
Template Name: homepage
*/
at the top of the page so I can select it as a template when creating a new page.
The problem occurs when the page is rendered. Becuase it is a 'page', a containing div which looks like this: <div id="page" class="hfeed"> in included which all of the other html is inserted into. This is causing major formatting problems.
How do I get rid of this containing div??
<div id="page" class="hfeed"> this is added in header.php.
If you remove it from header.php then it will affect all the pages. So create a custom header for homepage template.
Copy header.php and paste in a new php file & name it as header-home.php
In the header-home.php, remove page id and hfeed class from div. ie just keep <div>.
In homepage template, instead of get_header() call get_header('home');
With this you have a separate header from which you can remove page id from div.
Hope this helps.