Page Content In Wordpress Is Not Displaying - php

I am creating a wordpress theme from scratch and I think I'm having problems with my page.php file. When I go into the admin panel, add a new page and fill out the content I want then view the page I only see the title of the page while the rest is blank. For some reason the content of the page is not displaying.
The code in my page.php file is..
<?php /*
Template Name: Page Template
*/
get_header(); ?>
<div class="page">
<h1 class="entry-title"><?php the_title(); ?></h1>
<hr>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php endwhile; // end of the loop. ?>
</div>
<?php get_footer(); ?>
I only get to see up to the horizontal rule and then the footer but everything else in between is blank. Am I maybe missing something in my functions.php file?

Try to var_dump( get_template_part('content', 'page') ) or even var_dump(the_post()), you should get important debugging info...

I found the problem. It was a piece of code in my functions.php file.
function PLEASE_the_tags($content='') {
global $post;
$html.="<div class='tags'>\n";
$html.="<a href='#' rel='tag'>".$post_the_tags."</a>\n";
$html.="</div?\n";
$content.=$html;
return $content;
}
add_filter('the_content', 'get_the_tag_list');
After I removed this, the content started showing again. I have no idea how this caused the problem but thank you for everyone's help.

Related

Wordpress: Trying to create a PHP page template to replicate homepage functionality

I am currently using the cubic theme and ran into some trouble with template creation. I have multiple sections on my site and am trying to replicate the functionality of my home page onto another page where ideally the home page would display featured articles and another page for urban exploration would be able to display posts about urban exploration in the same format. I.e. Images with nicely displayed titles in rows of three link to posts I have created.
So far this is what my template looks like:
<?php /* Template Name: Page Directory */ ?>
<?php get_header(); ?>
<?php the_content(); ?>
<div id='primary' class='content-area'>
<main id='main' class='site-main' role='main'>
</main><!-- .site-main -->
<?php get_sidebar( 'content-bottom' ); ?>
</div><!-- .content-area -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
This allows me to display the header with the integrated side bar and footer, but I cannot figure out how to replicate cubic's home page functionality.
I imagine the PHP function would have to query for tags in order to place the post on the page, then look for a post's featured image and title to display it as a square image covering 1/3 of the page. Any help would be greatly appreciated.
Update:
I found you can use WP_Query to create a loop to pull information then display it using get_template_part as a means of formatting the post information. I can now display the images for my posts however the formatting is off because of the way content.php is written. [Do any users of cubic (a child theme in WordPress) know how the homepage is constructed and how I might be able to reference that file so I can recreate its format on a different page in WordPress?]
<?php /* Template Name: Page Directory */ ?>
<?php get_header(); ?>
<?php the_content(); ?>
<main id='main' class='site-main' role='main'>
<?php
$postid = new WP_Query( array( 'tag' => 'featured' ) );
if( $postid->have_posts() ):
while( $postid->have_posts() ): $postid->the_post(); ?>
<?php get_template_part('content',get_post_format()); ?>
<?php endwhile;
endif;
?>
</main><!-- .site-main -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
You need to add the loop which fetches the posts:
<?php while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>

ARCHIVE.PHP SHOWS ONLY ONE POST PER CATEGORY

I realized my website (www.inunfuturoaprile.it) with a minimal Wordpress theme that does not include the category.php template. I have created the template by me: the goal was to get pages that display a list of the posts belonging to a specific category. Unfortunately, due to my scarce knowledge of php, the code does not seem to work properly: I only see one post per category (e.g. https://www.inunfuturoaprile.it/politica/).
Here's the category.php file code:
<?php
/**
* Template di Categoria
*/
get_header(); ?>
<div id="content">
<?php
// Check if there are any posts to display
if ( have_posts() ) : ?>
<?php
// Since this template will only be used for Design category
// we can add category title and description manually.
// or even add images or change the layout
?>
<h1><strong><?php single_cat_title(); ?></strong>: Elenco Articoli</h1>
<div class="entry">
<?php
// The Loop
while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?> // <small><?php the_time('j F Y') ?></small>
<?php endwhile; // End Loop
else: ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p>
<?php endif; ?>
</div>
</div>
<?php get_footer(); ?>
Someone can help me? Thank you :)
I think your posts_per_page parameter is set to 1.
You can see other posts using pagination:
https://www.inunfuturoaprile.it/politica/page/2/
https://www.inunfuturoaprile.it/politica/page/3/
Check it on Settings->Reading page ( /wp-admin/options-reading.php), parameter "Blog pages show at most"
But it also can be set up somewhere in the theme code.
Changing it may affect your main page - since the main page shows only one post too.
So you can change it only on category.php page. Add this after get_header():
get_header();
global $wp_query;
$wp_query->set('posts_per_page', 10);
// or this - if you need no pagination at all:
// $wp_query->set('nopaging', true);
$wp_query->query($wp_query->query_vars); ?>

Wordpress woocommerce empty my account + car page

I am stuck when trying to install woocommerce. I add managed to do it, but suddenly, I don't know why, the "my account" page and "cart" page are empty, if I look into the source code, the content is here but between and therefore invisible. I have no idea and have been searching for hours on internet and stackoverflow with no luck!
Has anyone an idea of why this is doing this?
I have re-installed three times the plug-in, deleted everything and reinstalled it, it sill does the same error....
I haven't touched anything in the code and the pages are chosen in the backend
EDIT :
My woocommercePage is
<?php get_header(); ?>
<?php woocommerce_content(); ?>
<?php get_footer(); ?>
And my page is :
<?php get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
<?php get_footer(); ?>
The WooCommerce "My Account" and "Cart" pages should just be regular WordPress pages. The WooCommerce functionality is added by using shortcodes in the page content. You may also include other content and shortcodes if you would like, but the following shortcodes are required.
For the Cart use:
[woocommerce_cart]
And for My Account use:
[woocommerce_my_account]
Your page template will need to make a call to the_content() so that the $post->post_content value is passed through the the_content filter which will call do_shortcode() to process the shortcodes.
<?php get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<!-- output the page content here to process shortcodes -->
<?php the_content(); ?>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
<?php get_footer(); ?>

WordPress blog dates are displaying the current date for every post

My WordPress blog, which is running a custom theme, displays the date for each entry post as the same date: today. I display the last three posts on my main home page, but those dates are fine. However my main blog page shows the current date for every post.
I am able to FTP into my site, and have access to all the PHP files, the problem is I don't know which file this error might be in, whether it be index.php, page.php, single.php, I have no idea. If anyone can suggest where the problem might be, I can help by sharing that code.
Here is the index.php
<?php
get_header(); ?>
<div class="wrap blog">
<h1>Blog</h1>
<div class="blog-left">
<div id="main-content" class="main-content">
<?php
if ( is_front_page() && twentyfourteen_has_featured_posts() ) {
// Include the featured content template.
get_template_part( 'featured-content' );
}
?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php
if ( have_posts() ) :
// Start the Loop.
while ( have_posts() ) : the_post();
/*
* Include the post format-specific template for the content. If you want to
* use this in a child theme, then include a file called called content-___.php
* (where ___ is the post format) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
endwhile;
// Previous/next post navigation.
twentyfourteen_paging_nav();
else :
// If no content, include the "No posts found" template.
get_template_part( 'content', 'none' );
endif;
?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar( 'content' ); ?>
</div><!-- #main-content -->
</div>
<div class="blog-right">
<?php get_sidebar(); ?>
</div>
</div>
<?php
get_footer();
Have a look at template hierarchy chart to figure out which file is used to display those posts. It might be archive.php, front-page.php, home.php, index.php depending on the theme and setup. From there, you'll see the function or which file is loaded to display each post's content.
Considering the sample code, its probably in content.php or in case it's a special post format, in content-{format}.php
I'm almost sure that if the theme is using Template Tags, is using the_date function, when it should be using the_timefunction.
You can read the docs for the_date, in the description there's a note you should read.

Wordpress front-page.php template

I have my front page set to a static page and am trying to build my custom template. How do I actually show the selected front page in front-page.php? I have googled and googled but can't seem to figure out how to do it.
The front-page.php actually loads like it should, but I can't seem to find documentation on exactly how to show the page that is assigned as the static home page. Any suggestions?
I have tried
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>
but that didn't seem to work...
Your static page uses a page template (usually page.php for the default template)
You can create a new one for the homepage if you wish. see : Creating_Your_Own_Page_Templates copy page.php to homepage.php and change the template name
Example template (homepage.php) :
<?php
/*
Template Name: Homepage
*/
//the content of page.php and now you can do what you want.
?>
$id = 0; /* The id of your page */
$page = get_page($id);
echo apply_filters('the_content', $page->post_content);
If its a static page, I should not use a loop.
First, take a look to topic to show something only on home page. a related question is Wordpress Post Thumbnail Issue (Only 1 thumbnail on frontpage). Also, it can be useful how to create a static front page in wordpress.
I was missing something obvious. The loop I was using I had copied out of wordpress template. It actually called another template file. What I should have used was:
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header>
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages(array('before' => '<div class="page-links">' . __('Pages:', 'twentytwelve'), 'after' => '</div>')); ?>
</div><!-- .entry-content -->
<footer class="entry-meta">
<?php edit_post_link(__('Edit', 'twentytwelve'), '<span class="edit-link">', '</span>'); ?>
</footer><!-- .entry-meta -->
</article><!-- #post -->
<?php endwhile;?>

Categories