Wordpress woocommerce empty my account + car page - php

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(); ?>

Related

Wordpress Custom Theme: Plugins Won't Load or Display Only Code

This is my first attempt at creating a theme purely from scratch. Before this I just used underscores_me and made most of my changes to style.css and left the majority of PHP alone, because I'm a novice with it.
My issue is that plugins are not working. None of the ones I have installed work. At this point I have been trying plugins that create an event calendar, but I'm assuming that any and all plugins will have issues. In the areas that are meant to display the calendar, there are two things I'm seeing. Plugin-generated pages show nothing at all (aside from the theme visuals) and plugins that are inserted into an admin-created page display plugin-generated code.
I am using WampServer. I have wp_footer(); and wp_head(); in the correct places. My functions.php file was created from the example found at https://scanwp.net/blog/create-a-wordpress-starter-theme-from-scratch/ and the only adjustment I have made to it so far is to remove the fontawesome line of code.
My index.php file looks like this:
<?php get_header(); ?>
<h1><?php echo "&#9755 "; ?><?php the_title(); ?></h1>
if ( have_posts() ) :
while ( have_posts() ) : the_post();
// Display post content
endwhile;
endif;
?>
<?php get_footer(); ?>
And my page.php file looks like this:
<?php get_header(); ?>
<h1><?php echo "&#9755 "; ?><?php the_title(); ?></h1>
<?= get_post_field('post_content', $post->ID) ?>
<?php get_footer(); ?>
First of all, you have to understand that in your displayed files, there are no functions that recall objects that will later show the page content.
Then, in your index.php file there is an error, besides what was said above, because you're calling the_title () (function) that extrapolates the title of a post or page via the post object, which in this case should be extracted within the while loop contained within the if condition.
Then try editing the files as follows.
index.php
<?php
get_header(); ?>
<?php if( have_posts() ) : ?>
<?php while( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php if( is_singular() ) : ?>
<?php the_content(); ?>
<?php else : ?>
<?php the_excerpt(); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php else: ?>
<h1>No posts to display</h1>
<?php endif; ?>
<?php get_footer(); ?>
and page.php
<?php
get_header(); ?>
<?php while( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; ?>
<?php get_footer(); ?>
However, within the wordpress codex you will find all the guides well written on any type of function, look no further.
source: https://codex.wordpress.org/

Display custom field in product (wordpress)

I would like to display custom field on product page.
I made field (Advanced Custom Fields) and add a rule to display in selected category on Posts. It works, I placed there a simple text and would display in product page. In editor I edit template and pasted the code:
<?php the_field( 'my_info' ); ?>
Unfortunately nothing appears.
I try also something like this:
<?php
query_posts('cat=195&posts_per_page=1');
while (have_posts()) : the_post(); ?>
<?php if( get_field('my_info') ): ?>
<?php the_field('my_info'); ?>
<?php endif; ?>
<?php endwhile;
?>
After this code field display, but there is a problem with loading other page sections.
What I make wrong?
Since query_posts() is used, you have to put wp_reset_query(); after the endwhile(). Otherwise use WP_Query .
<?php
$query=WP_Query('cat=195&posts_per_page=1');
while ($query->have_posts()) : $query->the_post(); ?>
<?php if( get_field('my_info') ): ?>
<?php the_field('my_info'); ?>
<?php endif; ?>
<?php endwhile; ?>

Page Content In Wordpress Is Not Displaying

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.

Wordpress shortcodes only working in posts, not pages. Custom theme

I'm building a theme for a friend but some some reason I can't get shortcodes to work in Pages. They only work in Posts.
My page.php file is very simple at the moment:
<?php get_header(); ?>
<?php
if (have_posts()) :
while (have_posts()) : the_post();
echo '<div class="hero-unit"><div class="container"><h1>'.get_the_title().'</h1></div></div>';
echo '<div class="container clearfix" id="main-content">'.get_the_content().'</div>';
endwhile;
endif;
?>
<?php get_footer(); ?>
This is working fine but is just displaying the shortcode as text.
IE I am trying to use the shortcode [wp_sitemap_page] the page just renders '[wp_sitemap_page]' in text.
What could be the issue?
Your post content is displayed via echo get_the_content() which is a function that returns the content WITHOUT applying the default filters (wpautop, do_shortcode etc) that are applied normally when you use the_content() instead.
This should fix it:
<?php
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<div class="hero-unit"><div class="container"><h1><?php the_title(); ?></h1></div></div>
<div class="container clearfix" id="main-content"><?php the_content(); ?></div>
<?php endwhile;
endif;
?>

WordPress show only one category, excerpts only, on a page

I have a page set up to show only posts from one category, which I'm calling using the php query_posts function. How to I make it so that the posts are displayed as excerpts only, not as full articles?
Here's the code I'm using on the page:
<?php query_posts('category_name=news&showposts=10'); ?>
<?php while (have_posts()) : the_post(); ?>
<?php endwhile;?>
*incorporated WordPresses excerpt function:
<?php query_posts('category_name=news&showposts=10'); ?>
<?php while (have_posts()) : the_post(); ?>
<?php the_excerpt(); ?>
<?php endwhile;?>
Now I'm seeing first a list of the excerpts that I want followed by a repeat of the posts in the entirety...
There is a core Wordpress method that does that exactly :
http://codex.wordpress.org/Function_Reference/the_excerpt
And to control the length of the excerpt :
http://codex.wordpress.org/Function_Reference/the_excerpt#Control_Excerpt_Length_using_Filters

Categories