Morgan
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: Unable to locate WordPress Content directory (wp-content).This appears to be a bug in the php-ssh2 extension. I was able to get this working by uninstalling
php-ssh2
:sudo apt-get remove php-ssh2
and then installing the pecl extension:
sudo apt-get install -y libssh2-1-dev php-pear sudo pecl install ssh2-1.0 sudo ln -s /etc/php/7.0/mods-available/ssh2.ini /etc/php/7.0/fpm/conf.d/20-ssh2.ini sudo service php7.0-fpm restart
Then my config worked as before.
- This reply was modified 7 years, 11 months ago by Morgan.
I have the same problem. Any solution?
Test site: https://www.ashtonnolley.com
Forum: Themes and Templates
In reply to: get_template_part() fails but include() worksFigured it out. It was kinda tricky. It has to do with variable scope.
First of all, thanks for the suggestion, changing the filename didn’t work, but changing the contents of the included file was the key. My included file would only output content if certain variables were declared but not otherwise. I put in an
echo 'foo';
and found out that the file was always loading, regardless of which method I used.So here’s the tricky part. Assume you’ve got an index.php file in your theme that looks like so:
<?php $foo = 'bar'; get_header(); get_template_part( 'main' ); get_footer(); ?>
And your main.php file looks like this:
<?php echo $foo; ?>
What I expected would happen was that you’d see ‘bar’ in the output. That doesn’t happen. However, if your index.php file looks like this instead:
<?php $foo = 'bar'; get_header(); require TEMPLATEPATH . '/main.php'; get_footer(); ?>
then ‘bar’ shows up in the output. The difference is that the code you
require()
from main.php shares the variable scope of the index.php file (as in the second method above). On the other hand, if you useget_template_part()
to bring in the code, main.php does NOT share the same variable scope as index.php.This surprised me as I thought
get_template_part()
was essentially a replacement for usinginclude()
orrequire()
.So here’s my next question: Is there any easy way to set a bunch of variables that will be accessible from any of the template files regardless of when or how they’re loaded? I’m thinking I could assign values to the variables in a function inside the functions.php file and assign it to the right action hook, perhaps?
Forum: Fixing WordPress
In reply to: get_the_date Problem??use get_the_time() instead
Forum: Fixing WordPress
In reply to: how to only show future posts in a catYou can use get_the_time() instead.
Also, in the loop I used something like:
if ( strtotime(get_the_time()) > strtotime('yesterday') ) { // display stuff }
to get the functionality described in this post.
Forum: Plugins
In reply to: Can the default calendar be set to display posts from only one category?It’s a little bit of work, but you can do it.
- Open up (or create if it doesn’t exist) the functions.php file in your theme folder
- Write a function to output your stylized calendar. What I did was to copy and modify the wp_widget_calendar() and get_calendar() functions out of /wp-includes/widgets.php
- Register your function as a replacement for the default calendar with the following:
wp_register_sidebar_widget('calendar', __('Calendar'), 'your_custom_calendar_callback');
The key with this method is to tweak the SQL queries in the get_calendar() function so that they return only posts from the category you’re interested in.
HTH