Serious php get_template_part() Wordpress issues - easy fix? - php

I am needing some serious Wordpress expertise from others. I am in the process of building a custom theme, read about the get_template_part() method and decided that would help in cleaning up and organizing my code. I updated my theme to use this method several places and now the site is completely broken...not a single thing will load!! :( I would really appreciate any help! I will copy and paste a few of the php files below. Maybe someone with more experience with using this method can point out the problem. THANKS!
page.php
<?php get_header(); ?>
<div id="content" class="content">
<?php while ( have_posts() ) : the_post(); ?>
<!-- About page -->
<?php if (is_page('about')) ?>
<?php get_template_part( 'page', 'about' ); ?>
<!-- Media & Gallery page -->
<?php if (is_page('media-gallery')) ?>
<?php get_template_part( 'page', 'mediagallery' ); ?>
<?php endwhile; // end of the loop. ?>
</div> <!--/end content -->
<?php get_footer(); ?>
page-about.php
<div id="about">
<div class="text">
<h2 class="about"><?php echo get_the_title(); ?></h2>
<?php the_content(); ?>
</div>
</div>
page-mediagallery.php
<div id="pic-gallery">
<?php include_once 'includes/pwaplusphp/albums.php'; ?>
</div>
index.php
<?php get_header(); ?>
<div class="content">
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<br class="clr"/>
<?php endwhile; ?>
<?php content_nav( 'nav-below' ); ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h3 class="blog"><?php _e( 'Nothing Found' ); ?></h3>
</header> <!-- .entry-header -->
<div class="entry-content">
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.'); ?></p>
</div> <!-- .entry-content -->
</article> <!-- #post-0 -->
<?php endif; ?>
</div> <!--/end content -->
<?php get_footer(); ?>
content-gallery.php
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="post-date"><?php the_time(get_option('date_format')); ?></div>
<h3 class="blog"><?php the_title(); ?></h3>
<div class="post-content"><?php the_content(); ?></div>
</div>
Any thoughts why these may not be working? All of these files are under the root directory of the theme so the get_template_part() method should be finding all of the files. What's weird is no code is being spit out by Wordpress. aka. Since I've started using this method, not a single line of code is spit out in my browser when I inspect the source.
I am using the newest version of Wordpress and Google Chrome for my browser.
I also have this code at the top of each of my .php files, but that shouldn't mess up anything because it's commented as seen below:
<?php
/**
* I put a description of what the file does here.
*
* #package Keynote_WP_Themes
* #subpackage Rhymz_Suhreal
* #copyright Rhymz Suhreal, 2012
* #author Kyle Affolder <myemail#example.com>
*/
?>
I don't have the slightest clue as to what I'm doing wrong. :(
Ideas coding friends?!

Using your page-about.php as an example, you should be calling it like this in the template it's to be place in:
<?php get_template_part( "page-about" ); ?>
The template needs to be in the root of your theme directory so you can use "page-about" without the .php, and not have to indicate the location/directory the file would otherwise be located.

I've run into this a few times before as well - I can't really explain why yet as I'm still digging through the documentation, but it seems you can't call template parts this way when you are inside a post loop ;)
Anytime you are inside the loop, try using this instead:
<?php include(get_query_template('page-about')); ?>

Related

how to get full width in my wordpress page template?

I have to create a full-width page template in Wordpress. But I don't understand why, even if I only call my 'sidebar-bas' I also have the 'sidebar-droite' displayed :/
i hope someone could help me
<?php
/*
Template Name: Full Width
*/
?>
<?php get_header();
if(have_posts()): while(have_posts()): the_post();?>
<section id="pages" class="haut avecAside">
<section id="pages" class="haut">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</section>
<?php endwhile;
endif;
get_sidebar( 'sidebar-bas' );
get_footer();?>
Verify that your sidebar-bas template file does not include get_sidebar( 'sidebar-droite' ) in it.

Been running into a critical error with WordPress Theme

With one of my own WordPress Themes, I would click on any links under the recent posts category and I would receive the "gray screen of death" with the following error:
There has been a critical error on your website.
Learn more about debugging in WordPress.
I did the disable plugins deal but that didn't work. If you click on Archives and Categories, those work without no problems. Long story short, I walked away from studying WordPress and Web Development in early 2019 due to working mainly 55+ hours a week. Back in early 2019, those recent posts links worked, but now in Oct 2020, they don't.
Here's a link to the theme (yes, the footer is off, I'm looking to fix it next):
https://rthomas.xyz/TestAreaA/
Thanks for the help, hopefully I'm making sense here.
After further digging, there was something wrong with my single.php. I did the following to create a debug.log file in the wp-content folder, you can find it on the WordPress website:
Example debugging for wp-config
Next, the debug.log told me of an error on my single.php. It's the reason why the Archives and the Categories links worked but not the single posts.
My single.php had the following code:
<?php get_header(); ?>
<div class="container">
<div class="primary">
<!-- Start the Loop. -->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<hr>
<h2><?php the_title(); ?></h2>
<p class="date-author">Posted: <?php the_date(); ?> by <?php the_author(); ?></p>
<p><?php the_content(); ?></p>
<?php endwhile; ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your critera.' ); ?></p>
<?php
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif; ?>
<hr>
</div><!--/.primary-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
It said that the error was on the last line. After some editing, I reduced it to this:
<?php get_header(); ?>
<div class="container">
<div class="primary">
<!-- Start the Loop. -->
<h2><?php the_title(); ?></h2>
<p class="date-author">Posted: <?php the_date(); ?> by <?php the_author(); ?></p>
<p><?php the_content(); ?></p>
<?php
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif; ?>
<hr>
</div><!--/.primary-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

making first wordpress theme, the loop and template functions not working properly

I am following along with this tutorial and what I have made so far is not working as it should. I have gotten to the point where I am starting to use the loop - this is my code:
index.php
<?php get_header(); ?>
<div class="row">
<div class="col-sm-8 blog-main">
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile; endif;
?>
</div><!-- /.blog-main -->
<?php get_sidebar(); ?>
</div><!-- /.row -->
<?php get_footer(); ?>
</div><!-- /.container -->`
content.php
<div class="blog-post">
<h2 class="blog-post-title"><?php the_title(); ?></h2>
<p class="blog-post-meta"><?php the_date(); ?><?php the_author(); ?></p>
<?php the_content(); ?>
</div><!-- /.blog-post -->
I have two posts but only the latest post is getting displayed (by the loop) and within the post that gets displayed - the only part that is displayed is the title. So it seems like the_date(), the_author(), and the_content() functions are not working for some reason, and the loop is only getting one of the posts (the latest one).
What is wrong? Thanks.
I'm not sure what I did, but I went to WP admin and clicked "customize" for the theme, and it loaded correctly in the theme editor - and then I went to the site, and it was working. I think maybe I didn't save a file, and I didn't realize it - and as I was trying to figure it out, I ended up saving the file, and it started working.

Custom Post Meta Search Template

I'm struggling with getting wordpress to search custom post meta from a page template. I've looked all over the internet and can't seem to find anything that will work. No plugins seem to work either.
On my posts, I have the custom meta: "rate" and the value: "10" - Wordpress delivers no result when searching any of these.
I'd be very appreciated if someone could write me a searchpage.php page template or point me in the right direction (I'm not good with php).
Here's my current PHP code:
<?php
/*
Template Name: Search Custom Meta
*/
?>
<?php get_header(); ?>
<div id="content">
<div class="container clearfix fullwidth">
<div id="left-area">
<?php query_posts('meta_value='.$s); ?>
<?php if (!empty($wp_query->posts)) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
</div> <!-- end #left-area -->
</div> <!-- .container -->
</div> <!-- #content -->
<?php get_footer(); ?>
You checking incorrect variable in if so try removing that one,
query_posts('meta_value='.$s);
while ( have_posts() ) : the_post();
echo '<li>';
the_title();
echo '</li>';
endwhile;

Wordpress deprecated, comments issue

Basiclly, this is my index.php code:
<?php
get_header();
?>
<!-- WRAPPER START -->
<section id="wrapper">
<!-- START DYNAMIC PART -->
<?php
if(have_posts()):
while(have_posts()):
the_post();
?>
<!-- MAIN CONTENT START-->
<section id="main-content">
<!-- SIDEBAR START -->
<aside id="tab-lists">
<?php if(!dynamic_sidebar('telerik-sidebar')): ?>
<?php endif; ?>
<?php if(!dynamic_sidebar('telerik-sidebar2')): ?>
<?php endif; ?>
</aside>
<!-- SIDEBAR END -->
<!-- BIG POST START -->
<div id="big-post">
<article>
<header>
<h2>
<?php the_title(); ?>
</h2>
<p class="post-info">
Posted by <?php the_author(); ?> in on <?php the_date('d-m-Y'); ?> | <?php comments_number( 'no comment', 'one comment', '% comments' ); ?>
</p>
</header>
<?php the_post_thumbnail(); ?>
<div class="post-text">
<?php the_content(); ?>
</div>
</article>
</div>
<!-- BIG POST END -->
<div id="com">
<?php
comments_template('',true);
?>
</div>
</section>
<!-- MAIN CONTENT END -->
<?php
endwhile;
endif;
?>
<!-- END DYNAMIC PART -->
</section>
<!-- WRAPPER END -->
<?php
get_footer();
?>
It worked perfect on my localhost, but when I uploaded it into wordpress I get the Notice: Theme without comments.php is deprecated since version 3.0 with no alternative available. Please include a comments.php template in your theme. in /f5/funkz/public/wp-includes/functions.php on line 2670 - error, so i made a comments.php, and put the just my comments_template('',true); in there (in php tags) and on his place in the index.php i placed comments_template(); to call the file, but then i get memory issue error...I read in some places that can be resolved by increasing it in php.ini , but I didn't find it in my server's folders :( . If you have a solution thank you in advance.
Just use
<?php comments_template( '/templates/comments.php', true ); ?>
and move comments.php in to dir templates.
If you used the 2012 comments.php template, make sure that it is not looking from the line:
#package Wordpress, #subpackage TwentyTwelve #since v1.0.

Categories