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">
Related
Two questions together
How to make a page without header and footer in WordPress and
Load The Event Calendar plugin's single event post as a popup on that page
TheEventCalendar Link - https://wordpress.org/plugins/the-events-calendar/
<?php
/**
* Template Name: Calender Page
* If it is saprate page then you can define template name and use it with page OR if it is post single page then save as single-your-post-slug.php
*/
?>
<html <?php language_attributes(); ?> class="no-js">
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php wp_head(); ?>
</head>
<body>
<?php
while ( have_posts() ) : the_post();
the_content();
endwhile;
?>
<?php wp_footer(); ?>
</body>
</html>
You can create a page template that displays only the content of your page without header and footer.
Ex :
<?php /* Template Name: Event calendar popup */
while ( have_posts() ) : the_post();
the_content();
endwhile;
?>
Put this file in your theme folder.
Then create a page and give it this template. Add the shortcode in the editor.
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.
So I cant find and info about this, but I want to hook the default 404 page to a page thru a custom page template so that I can manage the content on the 404 page. Is this possible ?
To do this, simply create a page named 404.php in your theme.
Take a look at the simple structure of the 404.php file that is shipped with Twenty Thirteen. It basically features tags that display the header, sidebar, and footer, and also an area for your message:
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<header class="page-header">
<h1 class="page-title"><?php _e( 'Not Found', 'twentythirteen' ); ?></h1>
</header>
<div class="page-wrapper">
<div class="page-content">
<h2><?php _e( 'This is somewhat embarrassing, isn’t it?', 'twentythirteen' ); ?></h2>
<p><?php _e( 'It looks like nothing was found at this location. Maybe try a search?', 'twentythirteen' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .page-content -->
</div><!-- .page-wrapper -->
</div><!-- #content -->
</div><!-- #primary -->
So, to change the error message your visitor sees, revise the text within the h1 heading and within the page-content class; if necessary, add more paragraphs below that.
You can see more about this in the WordPress Codex.
Now to add content to this page you'll need to first create a new page in WP and tell it to use your 404 template. Once we've added page content we just need to add some code to the template php file. The following assumes that our new page has an ID of '12'.
<?php
// would get post 12's entire content after which you
// can manipulate it with your own trimming preferences
$post_12 = get_post(12);
$content = $post_12->post_content; //would echo post 12's content
//$excerpt = $post_12->post_excerpt; // would echo post 12's content up until the <!--more--> tag
?>
Now add this code into your template like so:
<?php
/**
* The template for displaying 404 pages (Not Found)
*
* #package WordPress
* #subpackage Twenty_Thirteen
* #since Twenty Thirteen 1.0
*/
get_header(); ?>
$post_12 = get_post(12);
$content = $post_12->post_content; //would echo post 12's content
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<header class="page-header">
<h1 class="page-title"><?php _e( 'Not Found', 'twentythirteen' ); ?></h1>
</header>
<div class="page-wrapper">
<div class="page-content">
<h2><?php $content ?></h2>
<p><?php _e( 'It looks like nothing was found at this location. Maybe try a search?', 'twentythirteen' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .page-content -->
</div><!-- .page-wrapper -->
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>
However, assuming that you want to install this on a system where you don't know the page ID you could always create a page via your theme or plugin that uses a fixed name/title, eg: "custom-404".
Then you can change your template's code to call that post by name/title, since we always know what this is called.
$page = get_page_by_title( 'custom-404' );
//$post_12 = get_post(12);
$content = $page->post_content; //would echo post custom-404's content
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; ?>
I'm just starting to play around with SimplePie, and have created a basic test page that will display the results of an RSS feed on a webpage. This works well when testing a handful of pages, but fails silently when trying to view an Apple Forum feed.
https://discussions.apple.com//community/feeds/search?q=mathtype&peopleEnabled=true&dateRange=all&rankBy=date
Any suggestions on how to troubleshoot this issue?
<?php
require_once('php/autoloader.php');
$feed = new SimplePie();
$feed->set_feed_url(
'https://discussions.apple.com//community/feeds/search?q=mathtype&peopleEnabled=true&dateRange=all&rankBy=date'
);
$feed->force_feed(true);
$feed->init();
$feed->handle_content_type();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN">
<html>
<head>
<title>Sample SimplePie Page</title>
</head>
<body>
<div class="header">
<h1><?php echo $feed->get_title(); ?></h1>
<p><?php echo $feed->get_description(); ?></p>
</div>
<?php
foreach ($feed->get_items() as $item):
?>
<div class="item">
<h2><?php echo $item->get_title(); ?></h2>
<p><?php echo $item->get_description(); ?></p>
<p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
</div>
<?php endforeach; ?>
</body>
</html>
You're going to kick yourself... I checked the return value of $feed->init() and it was false, so I took out the extra / before "community" in your url and it seems to work.
https://discussions.apple.com/community/feeds/search?q=mathtype&peopleEnabled=true&dateRange=all&rankBy=date
When you use the double / in your browser, it ignores it, but SimplePie does not.