My wordpress site was not showing blog posts content and not the single post content, so I have created a blog template and used a post grid plugin shortcode. So now the blog is showing fine, but when I click on "Read more" it directs to single post, which shows empty page, I have disabled and enabled plugins and checked my htaccess file also. Thank you.
<?php
/*
* Template Name: Blog Post
*/
?>
<?php get_header(); ?>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>
<?php wp_title('|', true, 'right'); ?>
</title>
<link href="<?php echo get_template_directory_uri(); ?>/css/bootstrap.min.css" rel="stylesheet">
<link href="<?php echo get_template_directory_uri(); ?>/js/owl.carousel/owl.carousel.min.css" rel="stylesheet">
<?php wp_head();?>
</head>
<?php the_title(); ?>
<?php echo do_shortcode("[post_grid id='605']"); ?>
<?php get_footer(); ?>
It looks like you are missing the <body> tag and also may be missing the WordPress loop in between the <body>...</body> tags.
Try this:
<body>
<?php while ( have_posts() ): the_post(); ?>
<?php the_title(); ?>
...
<?php endwhile; ?>
</body>
Additionally the <?php get_header(); ?> already contains the HTML <head></head> and all the links and meta within, so you are essentially duplicating/overwriting it.
Try doing this:
<?php
/*
* Template Name: Blog Post
*/
?>
<?php get_header(); ?>
<body>
<?php while ( have_posts() ): the_post(); ?>
<?php the_title(); ?>
...
<?php endwhile; ?>
</body>
<?php get_footer(); ?>
Do also make sure that your header.php file doesn't actually contain the opening <body> tag out of the box though (footer.php should contain the closing tag), as this will determine whether you need the <body></body> tags in my code above.
Related
So I am going through a Wordpress theme course, and we are creating our page template setup. The page is loading fine with
<?php get_header(); ?>
<section id="page-template">
<div class="container">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
</div>
</section>
<?php get_footer(); ?>
All my css files are linked into the header, but for some reason when I load up the pages I create, they don't load up the CSS we created for the page. We are importing all the css files into one main.css file, this is the one I am having trouble with.
#import "pagetemplate/page.css";
and in that file we have some basic css to test it out and make sure it connects.
#page-template {padding: 80px 0;}
#page-template .container {padding: 0 15px;}
Sorry if it's all over the place, I will be glad to expand on any questions.
I should add, my header.php page has the css link of
<link rel="stylesheet" href="<?php echo get_bloginfo('template_directory'); ?>/css/main.css">
Change the php code to
<?php bloginfo("template_directory"); ?>
So you link look like
<link rel="stylesheet" href="<?php bloginfo("template_directory"); ?>/css/main.css">
Ok, so I just figured it out. I am not sure if it's good practice the way I did it but I got it! I just linked the css folder and file straight into the page.php.
<link rel="stylesheet" href="<?php echo get_bloginfo('template_directory'); ?>/css/page-template/mypage.css">
I added this regular css link into my page.php template, since my get_header() is not recognizing my css link from my main page.
Here is the final view.
<link rel="stylesheet" href="<?php echo get_bloginfo('template_directory'); ?>/css/page-template/mypage.css">
<?php get_header(); ?>
<section id="page-temp">
<div class="container">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
</div>
</section>
<?php get_footer(); ?>
The problem is that on my one pager website the title tag doesn't get populated.
page.php looks like this:
<?php
locate_template( 'page-home.php', true );
exit();
page-home.php looks like this:
<?php get_header(); ?>
<?php get_template_part('template-sections/slider'); ?>
<?php get_template_part('template-sections/services'); ?>
<?php //etc. ?>
<?php get_footer();
header.php looks like this:
<!doctype html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="profile" href="http://gmpg.org/xfn/11"/>
<base href="<?php echo get_site_url(); ?>/">
<?php wp_head(); ?>
</head>
<body itemprop="hasPart" itemscope="" itemtype="http://schema.org/WebPage" <?php body_class(); ?>>
<!-- etc -->
And footer.php looks like this:
<?php wp_footer(); ?>
</main>
<aside class="aside">
<div class="aside__content">
</div>
</aside>
</div>
</body>
</html>
Yes. There is a page present called home in the backend. And I would like Wordpress to pick that title up and use it as a title tag in header.php.
Now as far as I know, Wordpress normally automatically populates the title tag. So what's the problem here? Thanks!
PS: I am not using the wp_title filter anywhere in my custom Wordpress theme.
Ok, the solution I found might help others. So I felt free to post it here.
Part 1. Comparing with the standard twentyseventeen theme. I found that Wordpress needs add_theme_support( 'title-tag' ); to be able to manage the title. (Otherwise you should just add a <title> tag yourself in header.php, I guess.
Part 2. I needed to add a custom filter to functions.php to display the title in a format that is desired. For example (using a SEO plugin):
function custom_title( $title_parts ) {
$page_id = site_get_page_id(); // custom function, you might want to use global $post here
$seo_title = #get_post_meta( $page_id, '_aioseop_title' );
if ( isset( $seo_title[0] ) ) {
$title = $seo_title[0];
} elseif ( isset( $page_id ) ) {
$title = get_the_title( $page_id );
}
$page_title = isset( $title ) ? $title : 'Page not found in backend';
$title_parts['title'] = $page_title;
return $title_parts;
}
In the browser tab info of my site I want to replace the dash with a vertical line.
So instead of Site Name - Site Tagline it would be Site Name | Site Tagline. It would also be like that on category pages, for example right now it is Site Name - Site Category but I would like Site Name | Site Category. I am using the Goodlife theme but I have added the header.php below. Does anyone know how I could change this?
header.php
<!doctype html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=1">
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
<?php wp_site_icon(); ?>
<?php
$header_style = ot_get_option('header_style', 'style1');
$general_boxed = (ot_get_option('general_boxed') == 'on' ? 'boxed' : '');
?>
<?php
/* Always have wp_head() just before the closing </head>
* tag of your theme, or you will break many plugins, which
* generally use this hook to add elements to <head> such
* as styles, scripts, and meta tags.
*/
wp_head();
?>
</head>
<body <?php body_class(); ?>>
<div id="wrapper" class="open">
<!-- Start Mobile Menu -->
<?php do_action( 'thb_mobile_menu' ); ?>
<!-- End Mobile Menu -->
<!-- Start Content Container -->
<section id="content-container">
<!-- Start Content Click Capture -->
<div class="click-capture"></div>
<!-- End Content Click Capture -->
<?php
get_template_part( 'inc/header/fixed' );
get_template_part( 'inc/header/subheader' );
get_template_part( 'inc/header/'.$header_style );
get_template_part( 'inc/header/pageskin' );
?>
<div role="main" class="<?php echo esc_attr($general_boxed); ?>">
According to this article, you need to add the following code inside functions.php:
function wploop_change_separator()
{
return '|';
}
add_filter('document_title_separator', 'wploop_change_separator');
I am trying to make my website mobile friendly and it works when using inside head
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<?php $this->head(); ?>
</head>
<body>
<?php $this->beginBody() ?>
<?php echo $this->render('//layouts/_top_js'); ?>
<?= Alert::flashes() ?>
<?php echo $this->render('//layouts/_header'); ?>
<?= $content ?>
<?php echo $this->render('//layouts/_footer'); ?>
<?php echo $this->render('//layouts/_bottom_js'); ?>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
But when I start using the following code:
php $this->beginBody()
php $this->endBody()
it is completely ignored. Is the viewport code disabled when using the php code to load my pages?
The viewport needs to be explicitly set in the <head> section of your HTML. You should start the page with beginPage() instead of beginBody(), as the second one only renders the <body></body> part of the HTML.
PHP only outputs HTML on the page, in the case of Yii using layouts.
You need to check your layout files to make sure they contain the following line:
<meta name="viewport" content="width=device-width,initial-scale=1">
I need help for something please. I'm working on my structure, but I've some problems...
I created a page called "page-container.php" and the content is:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?= $page_title; ?></title>
<link href="css/style.css" rel="stylesheet">
<link href="css/fonts/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Patrick+Hand" rel="stylesheet">
</head>
<body id="<?= $page_id; ?>">
<?php include "includes/header.php"; ?>
<div class="wrapper">
<div class="page-content">
<?php if(isset($sidebar)): ?>
<div class="main-container">
<div class="main-content">
<?php endif; ?>
<h1 class="page-title"><?= $page_title; ?></h1>
I WANT TO HAVE MY CONTENT HERE FOR ALL MY PAGES
</div>
</div>
</body>
</html>
You can see the "I WANT TO HAVE MY CONTENT HERE FOR ALL MY PAGES".
What I mean is that when I write the content in my other pages (for example, my registration page), I want that all the content is placed at this location, like this:
http://prntscr.com/a3oz5k
All my other pages are like this (exemple with index.php):
<?php
$page_title = "Home";
$page_id = "home";
?>
<?php require "includes/page-container.php"; ?>
If I want to write some content in this page, I need to do like this:
<?php
$page_title = "Home";
$page_id = "home";
?>
<?php require "includes/page-container.php"; ?>
<div id="mycontent">
<p>Heellloo</p>
</div>
But look the result: http://prntscr.com/a3p32y
In the code source this is not normal... http://prntscr.com/a3p3kg
My content is below the html and body tag and I want it to be placed just below my h3 title. How can I do please?
Simple example using ob_start(), ob_get_clean().
<?php
ob_start();
?>
<div id="mycontent">
<p>Hello</p>
</div>
<?php
$page = ob_get_clean();
require "includes/page-container.php";
?>
And then in page-container.php just do echo $page;.
Your code will be still formatted as HTML in your editor instead if it would be in a variable.
You can also split your page-container.php into two parts and include the first part before the content and the second one after.
Reference: ob_start(), ob_get_clean()
You can keep another vartiable say $page_content and use as below :
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?= $page_title; ?></title>
<link href="css/style.css" rel="stylesheet">
<link href="css/fonts/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Patrick+Hand" rel="stylesheet">
</head>
<body id="<?= $page_id; ?>">
<?php include "includes/header.php"; ?>
<div class="wrapper">
<div class="page-content">
<h1 class="page-title"><?= $page_title; ?></h1>
<?= $page_content; ?>
</div>
</div>
</body>
</html>
And for some content in another page
<?php
$page_title = "Home";
$page_id = "home";
$page_content = "content";
?>
<?php require "includes/page-container.php"; ?>
`