I am working on a WordPress website it has some code in header.php which I want to display only on the home page:
<header id="header">
<!-- few lines of code displaying Images and some text -->
</header>`
I tried to put this line but it is showing some error
<?php if(is_front_page())
This code worked for me
<?php if (is_home()): ?>
<!-- ... -->
<?php endif; ?>
Related
UPDATE: I have just figured it out! I used a full URL (http://localhost/practice/wp-content/themes/cpmock/assets/images/cplogo.png) as the img src and now it works on all pages.
I hope someone can help.
I am creating a wordpress site/theme, from scratch, for the first time.
I have created a header.php file which contains a logo, some nav links and a search bar.
I have created several files/pages, such as; index.php, front-page.php, page-about.php and single.php for example.
Each file/page calls the header.php and displays it. However, only the front-page.php file shows the image.
All files/pages are in the root folder. The image src is the full file path. I don't understand why the image only works in the front-page.php and not the others.
I hope someone can advise why this is. I have included code from header.php, front-page.php and page-about.php.
header.php:
<!DOCTYPE html>
<html <?php language_attributes() ?>>
<head>
<meta charset="<?php bloginfo('charset')?>">
<meta name="description" content="<?php bloginfo('description')?>">
<title><?php bloginfo('name')?></title>
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<div class="container">
<header class="header">
<a href="http://localhost/practice/"><img src="wp-
content/themes/cpmock/assets/images/cplogo.png" alt="CP Logo"></a>
<div class="search-header">
<?php get_search_form(); ?>
</div>
<?php wp_nav_menu( array(
'theme_location' => 'primary'
) ); ?>
</header>
front-page.php:
<?php get_header(); ?>
<section class="front-page">
<h1>front-page.php</h1>
<p>This is a mock website.</p>
</section>
<?php get_footer(); ?>
page-about.php:
<?php get_header(); ?>
<section class="page-about">
<h1>page-about.php</h1>
<h4>This is my custom about page.</h4>
</section>
<?php get_footer(); ?>
Here are a couple of screenshots. One showing the front-page.php which displays the image. The other of the page-about.php which doesn't show the image.
front-page.php image visible
page-about.php image not visible
You should not type static image URLs like that:
"http://localhost/practice/wp-content/themes/cpmock/assets/images/cplogo.png"
The reason you don't type them like that is that you will have to retype them when you connect to the website to a domain. A better solution would be...
<?php
$imageUrl = get_site_url()."/folder/folder/image.png";
?>
<img src="<?php echo $imageUrl ; ?>" alt="CP Logo">
I using gravity forms plugin and I want to add a form in my blog page(posts page) but on the page editor, I can't add gravity form in the content.
Or I need to show the form where I need it, not in the content of the post or page
my problems are:
I can't(don't know how to) show the form where I want
I can't show my form inside blog page(posts page)
my index.php and single.php files code:
<?php
get_header();
if(have_posts()):
while(have_posts()): the_post(); ?>
<article class="post page">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</article>
<?php endwhile;
else:
echo '<p>No Content Found!</p>';
endif; ?>
<div class="gravity-form-place">
<!-- gravity form must show here -->
</div>
<?php get_footer(); ?>
how to show the forms inside <div class="gravity-form-place"> in the single.php file ?
how to show the forms inside <div class="gravity-form-place"> in the index.php file blog page(posts page)?
Have you tried to use Gravity Form shortcode? If you haven't, try it. Here's the documentation:
Creating a Form Shortcode - Gravity Form
It should be something like this:
<?php
echo do_shortcode( '[gravityform id="1"]' );
?>
Once you created your form you should be able to get a short code. Copy it and paste it in between the following
<?php echo do_shortcode('_Your_Short_Code_Goes_Here_'); ?>
The just paste that line in between your div:
<div class="gravity-form-place">
<!-- gravity form must show here -->
<?php echo do_shortcode('_Your_Short_Code_Goes_Here_'); ?>
</div>
If you're going to be outputting the form via PHP, the best way to do so is with the gravity_form() function.
gravity_form( 1, false, false, false, '', false );
Full details here: https://docs.gravityforms.com/adding-a-form-to-the-theme-file/#function-call
I'm sure this is a simple fix, but I'm not much of a programmer.
I coded a WordPress site for one of my clients 3 or 4 years back. They asked to have a blog added to their site.
There are several strange things happening that I'm not entirely sure why.
If you go to: http://firstcalliowa.com/blog/
You can see it's not displaying the post title or meta data. Just the post content.
Also, go to: http://firstcalliowa.com/author/austinhudspeth/
So, this is interesting. Here, you can see the post title and edit this link. The post title isn't linked, but that can be fixed. The interesting part is, I don't have an author file made yet. So, I'm not sure why it looks more correct here, but won't pull up the post title on the first link.
Here's my loop code:
` <div id="content">
<div id="content_container">
<!-- Start the Loop. -->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!-- Test if the current post is in category 3. -->
<!-- If it is, the div box is given the CSS class "post-cat-three". -->
<!-- Otherwise, the div box is given the CSS class "post". -->
<?php if ( in_category('3') ) { ?>
<div class="post-cat-three">
<?php } else { ?>
<div class="post">
<?php } ?>
<!-- Display the Title as a link to the Post's permalink. -->
<h2><?php the_title(); ?></h2>
<!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
<small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>
<!-- Display the Post's content in a div box. -->
<div class="entry">
<?php the_content(); ?>
</div>
<!-- Display a comma separated list of the Post's Categories. -->
<p class="postmetadata">Posted in <?php the_category(', '); ?></p>
</div> <!-- closes the first div box -->
<!-- Stop The Loop (but note the "else:" - see next line). -->
<?php endwhile; else: ?>
<!-- The very first "if" tested to see if there were any Posts to -->
<!-- display. This "else" part tells what do if there weren't any. -->
<p>Sorry, no posts matched your criteria.</p>
<!-- REALLY stop The Loop. -->
<?php endif; ?>
</div>`
On the first link you provided it doesn't look like the HTML you've provided is being used. Can you do a test edit to make sure the /blog page is actually using the loop you've created? I see an empty .post-header div being outputted but I don't see that anywhere in your loop.
I have my own theme and Buddypress installed on my Wordpress page but when I updated to the newest version (1.7.2) the titles of the BuddyPress pages display incorrectly (Profile page, Groups page, …): They show in a HTML form. On the twenty twelve theme everything looks good.
As an alternative I tried creating a new theme for BuddyPress (using the groups, members, … folders in my theme folder) but I found it too much of work to do. Isn't there a simple solution for only the title.
A screenshot of my groups title:
A screenshot how it is supposed to look:
<div id="page">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2 id="page_title"><?php the_title(); ?></h2>
<p id="author"><?php the_author(); ?></p>
<div class="content">
<?php the_content(); ?>
</div>
<?php endwhile; endif; ?>
<?php comments_template(); ?>
</div><!-- main -->
I used the "Remove private/protected from post titles" snippet from CSS Tricks in my functions.php. After I deleted it, it worked again.
I'm trying to learn how to build my own WordPress themes. I've been through a few tutorials but I've hit a snag. I can't seem to figure out what I'm doing wrong. When I have my html for my footer in the same file as my "home.php" it works fine. When I try to separate it however and place the footer html in "footer.php" and use the "get_footer();" function, the footer does not appear at all, visibly or in the code... it's not there. I am wondering if there is something else I have neglected to do to get the footer to work? If not then what could be causing the footer not to show up when I split up the code into different theme parts/files?
Here is the code for home.php:
<?php
/*
Template Name: Front Page
*/
?>
<?php get_header(); ?>
<?php get_template_part('nav'); ?>
<div id="content"><!-- Start Content -->
<?php get_sidebar('left'); ?>
<div id="middle-column" class="grid_8"><!-- Main Content Begins Here -->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?><!-- Start Loop -->
<div class="post">
<h2 id="post-<?php the_ID(); ?>"><?php the_title(); ?></h2>
<div class="entrytext">
<?php the_content('<p class="serif">Read the rest of this page »</p>'); ?>
</div>
</div>
<?php
endwhile;
else:
?>
<?php _e('This page does not appear to have been set up yet. Sorry, please try again later. Thanks!'); ?>
<?php endif; ?>
<!-- End Loop -->
</div>
<?php get_sidebar('right'); ?>
<?php get_footer(); ?>
and here is the code for footer.php:
<div style="clear:both;"></div>
<div id="push"></div>
</div><!-- End Content -->
</div><!-- End Container -->
</div><!-- End Wrapper -->
<div id="footer"><!-- Start Footer -->
<div id="footWrap"><!-- Start #footWrap -->
<p>© Brent Blackwood</p>
</div><!-- End #footWrap -->
</div><!-- End Footer -->
<div id="headerBand"></div><!-- Placed here for SEO purposes -->
<div id="navBand"></div><!-- Placed here for SEO purposes -->
</body>
</html>
I don't see anything obviously wrong.
Do you have define('WP_DEBUG',true); in your wp-config.php? If not, add that and see if there are errors that might help.
Are you sure it fails at get_footer() and not before, with get_sidebar() for example?
Are your "Front Page" template file and footer.php in the same directory?
Do you have a public URL?