Project

General

Profile

Support #2249

Support re: Provost's WP website

Added by erin glass almost 5 years ago. Updated over 1 year ago.

Status:
Resolved
Priority name:
Normal
Category name:
WordPress (misc)
Target version:
Start date:
2012-11-14
Due date:
% Done:

0%


Description

Hi Dominic,

I'm hoping you might be able to guide me in two issues I'm experiencing while setting up the Provost's webpage. Before launching into those questions, however, I will first explain my haphazard understanding of how you made the slider automatically load. With this in mind, I hope you can better understand my following questions. I apologize in advance for the length!

You wrote:

"There is only a small amount of customization at this point. I created the functions.php file and added to it some code that tells WP that we don't want to use the fadeslide.js file that comes with the parent theme. Instead, WP should deregister that script and instead load our version which resides in /luna-cfr/js/fadeslide/fadeslide.js. That file contains the edited javascript that forces the slider on the homepage to begin it's transitions on the initial page load."

As I understand, the functions.php file (if needed) rests alongside the style.css file within the child theme folder. I also understand that most WP themes have multiple .php files. When altering .php files within a child theme, does one only need a new functions.php file? Or, did you make this file because the fadeslide.js rests within the functions.php file of the parent theme? I confess the Luna theme folder you sent me is a bit disorienting as I'm not quite sure what to make out of all the different folders and files. I have no familiarity with how .js files work, or why, for example, the flexsider file (within the js folder) is a .css file. I ask, because this will help me locate appropriate files to change when addressing the following questions:

1. As you know, I'm trying to make the homepage's header (Chase Robinson, etc) consistent across all pages. I'm guessing this inconsistency is due to code in the page.php file. If so, do I adjust this by creating a page.php file in the child theme folder, or, would I change the page.php file from the functions.php file you already created within the child theme?

2. I'm also trying to remove the featured image from appearing in the actual blog post. So far, I've done that with this code:

.single-blog-post img {
display: none;
}

It works great at removing the image, but will not allow ANY image to show up within the post. (This use of two different images is necessary in order to have a good crop for the featured image). I suspect I need to change the loop-entry.php file. So my question is similar to #1. Do I create a new loop-entry.php file, or do I modify the code in the child theme functions.php file?

Thanks for your enormous patience with these questions. I think once I get a feel for how to modify php (and possibly js) files within a child theme, my troubleshooting skills will be wildly more independent!

Best,

Erin

page.php View (1.03 KB) erin glass, 2012-11-26 04:03 PM

single.php View (4.54 KB) erin glass, 2012-11-26 04:29 PM

History

#1 Updated by Dominic Giglio almost 5 years ago

  • Target version set to Not tracked

As I understand, the functions.php file (if needed) rests alongside the style.css file within the child theme folder.

Yes. the functions.php files is optional, and it does need to be alongside style.css. A WordPress theme has only two requirements: a styles.css and a template (PHP) file. In the case of child themes, the template file requirement is satisfied by the parent theme. As I briefly explained in my email, a child theme is nothing more than an "extension" of the parent. When you enable a child theme WordPress looks in that directory first for any files it may need; if it can't find what it needs to render the requested page, it looks to the parent. Kinda like when you're young and you get your first apartment. The rental agent looks first to you for the rent, and if you can't come up with the funds, they go to your co-signer (most likely your parents). :-)

It's important at this point for you to fully understand the reasoning behind parent/child themes. I'll use an example to explain. Let's fast forward 6 months into the future. You and I have worked closely together to make the Provost's site the envy of the entire Commons community. We receive requests daily to speak at CUNY events about how we implemented such advanced functionality into a WordPress blog. Unfortunately, we never setup a child theme. All of our enhancements, changes and groundbreaking features were done inside of Luna. Fast forward one more month. We get an email from Matt with Luna 2.0 all zipped up and ready to be uploaded to The Commons. We immediately look at each other and can see the shame in each others eyes as we realize that all the hours we spent making the site into the greatest collection of pixels to ever grace a monitor have effectively prevented us from upgrading to the latest and greatest version of Luna! We scream into the heavens: "oh lord, our kingdom for a child theme!" You see, if we'd started with a child theme, the Luna parent would have remained untouched. And therefore, an upgrade to the parent is as simple as dropping the new theme folder into the themes directory and refreshing the page. WordPress keeps looking in our child theme (where our enhancements and custom functionality belong) and only going to the parent when it needs to.

The loading of the functions.php file is no different. Without getting too technical, when WordPress is going through its initial page load process (the sequence of events that happen every time a page is requested from your site) the child theme's functions.php is technically loaded before the parent's. The reason for this is that functions.php is a "local" customization file. You can think of it as a special plugin that belongs only to your theme. You can do all kinds of cool stuff that applies only to your theme. You can register menus and widgets and sidebars. You can add actions and filters that change the way text and images are output to your pages. You can even define custom functions that are to be used by only your theme. I once defined a function that output a customized word count on my blog posts. The loading of the child's functions.php FIRST is important because it allows us to customize a child theme and to define specific functionality that will override the features already in the Luna parent.

This is actually a perfect learning example (for both of us). Here's why:

The Luna parent theme is a little more complicated then I would like to use for an example, but we'll work with what we've got. The theme defines so much custom functionality that the author has split functions.php into multiple files. This is known as code modularity and it makes the features provided easier to organize and understand. Line 3 of Luna's functions.php includes a file named /includes/custom/custom-functions.php. That file contains a lot of 'general' WordPress features and options, but it's lines 38 and 77 that pertain to the custom fadeslide.js code that we're using in our child theme. Upon further investigation, while writing this reply, I noticed that line 38 is using the function get_stylesheet_directory_uri(). This has a very subtle but important impact. That function, and it's cousin get_template_directory_uri(), serve one purpose: to return a relative path to a file. The difference between them is that the former understands parent/child theme setups while the latter does not. get_template_directory_uri() basically says "load the file from the directory I'm currently in" and get_stylesheet_directory_uri() says "load the file from a child theme if that's where I am, and if not load from the parent." Good theme authors understand this difference. The Luna authors knew that some users would be using a child theme so line 38 uses get_stylesheet_directory_uri(). This means that the fadeslide.js from our child will be loaded by the parent functions.php. So our custom version of functions.php is technically not necessary. I'll probably remove it in the next release. The whole reason I added that to functions.php was because we weren't using a child theme when Matt opened the issue to adjust the javascript code. But at least it's given us an interesting topic to discuss. :-)

I also understand that most WP themes have multiple .php files. When altering .php files within a child theme, does one only need a new functions.php file?

No. The incredibly short answer is: to customize a child theme, you copy whatever file you want to change from the parent's directory to the child's and then edit to your heart's content. Let's use another example for the long answer.

The file header.php is very important. It defines all the important information that must be included at the top of a web page. Things like <html> and <head> and all the <meta> tags that tell the browser what it needs to know about the current page. Let's assume that you'd like to change the way the <title> element works starting on line 24. Think back to how the parent/child relationship works. There's currently NO header.php in our luna-cfr child theme folder. So when WP goes looking for that file it can't find it; but it does know where our parent folder is and looks there. Finding the file in that folder it loads it up and moves on to look for the next template file it needs. So by copying header.php to our child directory WP will find it there first. This is how you change the way a theme works. It also goes back to my example above where we couldn't update our parent because we made all our changes in the parent. By copying files to the child and editing them there, you can customize the functionality and still update the parent without overriding your customizations.

why, for example, the flexsider file (within the js folder) is a .css file

Don't pay any attention to this. Technically it shouldn't be in there. Good organizational style would dictate this file existing in the /css directory. I assume the Luna authors kept it in the /js folder to keep all fadeslider files together. It's confusing but doesn't really affect anything. It's like keeping Excel files in the same folder as Word files on your computer. It doesn't hurt anything other than understanding the organizational structure.

With all that outa the way, I hope I can move onto answering your actual questions now. LOL

1. As you know, I'm trying to make the homepage's header (Chase Robinson, etc) consistent across all pages. I'm guessing this inconsistency is due to code in the page.php file. If so, do I adjust this by creating a page.php file in the child theme folder, or, would I change the page.php file from the functions.php file you already created within the child theme?

You are very, very close. You're obviously understanding the parent/child relationship. But I would suggest approaching the problem from a different direction. The first thing you want to do is locate the code that makes that header appear. Once you find the code you can determine how it's being implemented, which will lead you to discovering how to take the code and apply it elsewhere in other template files. A WP page is nothing more than a collection of stitched together templates. To help save you some time I've found the code responsible for that header:

        <?php
            if(get_option('luna_hide_welcome')!="true") {
                ?>
                <!--SLIDE TEXT-->
                <div class="slide-text">
                    <h1><?php echo get_option( 'luna_welcome_title' ); ?></h1>
                    <span class="subtext"><?php echo get_option( 'luna_welcome_subtitle' ); ?></span>
                </div>
                <?php
            }
        ?>

That code currently exists in two templates: homepage-alt.php and index.php. index.php is a "catchall" or "default" template. If your theme does not define a specific template for a page or a post, WP uses index.php. Our job now is to locate the templates that are being used to render the pages on our site and then copy them to the child theme folder so we can add this code to them. For right now I'm going to leave this job up to you. If you have trouble finding out what template is loaded on what page, write back and we'll figure it out together.

2. I'm also trying to remove the featured image from appearing in the actual blog post.

This is a similar problem. But it's a little stickier cause you're talking about images and working with the WordPress Loop. Aside from your css code removing all images it also doesn't help performance of the site. Because what's actually happening is the images are still rendered to the page but the visitor can't see them. Ideally we want to edit the appropriate code to only render the images we want. Let me investigate this a little further before we move forward to an answer/solution. When you aren't getting the proper image sizes that you'd like in WP there are other ways of changing how the images look and where they show up. I'll get back to you on this one.

I think once I get a feel for how to modify php (and possibly js) files within a child theme, my troubleshooting skills will be wildly more independent!

I believe you're a lot closer than you think.

This got a lot longer than I thought it would. I'll probably take this info and turn it into one of the first posts on the upcoming Digital Fellows tutorial blog. Let me know if any of this doesn't make sense.

#2 Updated by Matt Gold almost 5 years ago

awesome work. thank you, dom.

#3 Updated by erin glass almost 5 years ago

Thank you so much, Dominic! I will go through this and respond to you soon!

#4 Updated by erin glass almost 5 years ago

Woo hoo! Success on part one -- I think! I switched out some code on the "page.php" file with title code from the homepage-alt.php file. On my local dev site the homepage header is now consistent across all pages. I'm attaching this new page.php file for the LUNA-CRF child theme. Is there a better way to submit this?

#5 Updated by erin glass almost 5 years ago

And success on part two (again, I think)! By removing some code from the single.php file (in the child theme folder) I've been able to keep the featured image from showing up in the blog post. I'm attaching this file as well, but let me know if I should formally submit these two files for the child theme in another manner. Many thanks!

#6 Updated by Dominic Giglio almost 5 years ago

I'm about to head back to the city from my Long Island holiday weekend. I'll take a look at your new code when I get home tonight.

For now this is really the only way to submit your code for inclusion in upcoming Commons releases. When we're dealing with single files we can just exchange them here. But if (when) you start changing more than one template, we'll just exchange a zip file so I can move all the changes in and out at once.

Boone, Matt and I will be having some more discussions as we move forward about improving the submission of custom theme files for Commons sites.

#7 Updated by Dominic Giglio almost 5 years ago

Erin,

This update is only about pages, I will address featured images separately. You are partly correct about the success of your custom editing. However, as I said previously, Luna is pretty advanced as far as features and how those features are offered to you as the site's admin. Your customizations of page.php will accomplish what you're trying to do, just not all the time.

To keep this simple, lets just look at the page: Biography. If you edit that page in the admin you will see that its "Template" in the Page Attributes metabox is currently set to Fullwidth. Remember, the options in that drop down are populated by the line Template Name: [WHATEVER] in a custom template file. In this case that file is template-fullwidth.php. The WP template hierarchy (the subsystem responsible to deciding what template to use when rendering a page) dictates that page.php will be used as a template of last resort if no other custom template has been defined or specifically chosen in the admin. This effectively means that your custom code will cause the header to appear on some pages but not on those that have defined a template. The template hierarchy is a cascading system, custom templates chosen in the admin come first, then template files in the theme directory with a specific naming convention come second and finally page.php will be used if no other template was found.

In situations like this, where there are a lot of custom templates defined by the parent theme author, I like to take a minute and look at the issue from a different perspective. Remember, WP pages are like a quilt. Each piece of fabric (template) is stitched together by WP (the seamstress) to be delivered to your site's visitor as a complete page. This means that when you find yourself looking at editing many different templates to add some functionality, you might instead be able to find a single template that gets "stitched" into all these others. In this case, the custom code is located at the top of each template; which should lead you to think: "what comes before each of these page templates?" That would be header.php. I looked at the header template, and unfortunately due to the structure of the HTML layout, it's "too early" to add the code there (which happens more often than I'd like). But I wanted to point out this line of thinking so you can begin to look at templates in the same way.

This example only takes into account the Biography page. I did not discuss archives, category pages, etc, which we will also have to take into consideration. So we need to make a decision about whether replicating the header across all pages is still a desired feature, and if so, we need to work together to implement the changes uniformly.

Additionally,

1.) there are pages that don't appear to be used. There is a "Home" page and a "No Title" page. Are these left over from some earlier work that was abandoned? Are they going to be used? If not, I suggest getting rid of them. It's just good housekeeping; the longer they sit there the more likely you are to forget why they exist which makes them harder to delete in the future.

2.) The Biography page is currently a child page of some unnamed page. You can tell because it has a dash in front of it when viewing the list of all pages. If you edit the Biography page you can see that the "Parent" drop down in the "Page Attributes" meta box is blank. That should be set to "(no parent)" if this is not a subpage. Again, just good housekeeping.

3.) Your permalinks have not been changed from the default. You can view your permalink settings on the Settings -> Permalinks admin page. Changing this is important for a few reasons. One, it makes your URLs a little bit more descriptive which gives your visitors a little more info about where they are on your site. And two, it is important for SEO (Search Engine Optimization). This is beyond the scope of this update, but basically search engines take the structure of your URLs into account when calculating your page rank and relevance to different search queries. I always set my permalinks to "Month and name." This produces a good looking and informative URL that also includes YEAR and MONTH when viewing a blog post.

If it's all right with you, since today is the 1.4.12 release and this site is pretty high profile and important on The Commons, I'd like to hold off on adding your new code until 1.4.13 (which will be on Dec 11th). I think we need to address these customizations further to ensure we don't introduce any issues that are going to break pages or layouts. I also need a little more time to investigate the image customizations you made. We're coming into the end of the semester which makes the balance of studying and work that much more difficult. I should have another update about images later tonight, although there are some issue I have to address for tonights release before that - so it might be tomorrow.

#8 Updated by erin glass almost 5 years ago

Thanks so much for your help, Dominic, especially during this very busy time! I see what you're saying about the code not working all of the time. I think I somewhat anticipated this but when testing it out on my local dev site thought it worked enough of the time. Thanks to your lucid explanation I have a better idea now of why it won't work consistently.

I agree that it's preferable to have the header consistent if possible. If the header.php file is "too early," should I then start poking around in other files to find out if there's another file that will change all of the templates? Or should we manually adjust every template to pull the desired header? If that's too complicated then we can discuss whether it's necessary to have a consistent header. This is really quite an odd feature of the Luna theme!

Thanks for pointing out 1-3. I made changes accordingly. I thought a "home" page was necessary, but I guess not, as the site still works after its deletion! Also, I changed the permalink setting to "post name." Was that what you had in mind?

Again, thanks for your help. I completely understand (all too well I'm afraid!) how difficult it is to juggle work and school during this very busy time of the semester. Let me know at your convenience how I should proceed with you on the header issue.

Best,

Erin

#9 Updated by erin glass over 4 years ago

Hi Dominic,

Hope you've had a great winter break! I wanted to follow up with you on the two outstanding issues regarding Chase Robinson's website.

To refresh your memory, we were working on:
A) Allowing the featured image of the blog post to not be the same as the image displayed in the blog post.
B) Making the site homepage header consistent across all pages.

I sent you some code for both, but I've decided that in the interest of time A is no longer important. (The theme forces the featured & displayed image to be the same, which is not aesthetically ideal when one has cropped book photos to show up on the homepage...but bearable, I suppose).

But it would be great if we could figure out B. You had some concerns with the code I sent you for B (see page.php) because it would not work in all cases. I think this is true, but I also think it will work in all current cases. Is that a good enough fix or should we explore a more thorough patch? My vote at the moment, though I could be convinced otherwise, is that we use the best solution we can come up with in the least amount of time as new projects are just around the corner.

Thanks again for all your help!

Best,

Erin

#10 Updated by Dominic Giglio over 4 years ago

Hey Erin,

I had a very nice break, thank you. I hope you did as well.

I'm right between classes right now; just finishing up my first week back and into the new spring semester.

I will respond in more detail when I get home tonight so we can get back on the same page and knock out the outstanding issues on the Provost's site.

#11 Updated by erin glass over 4 years ago

Thanks for your quickest of replies! I look forward to your ever-helpful guidance!

#12 Updated by erin glass over 4 years ago

Also -- one more tiny thing -- do you think it would be easy to make hotlinks in the review widget (bottom middle footer widget of chaserobinson.net)? This theme seems to complicate a lot of these matters, but if it is possible, I know the Provost would appreciate it.

#13 Updated by Matt Gold over 4 years ago

Hi Dom -- I'm meeting with Erin now and wanted to bump this ticket. Can you see whether Erin's page.php works as a short-term fix while we also think about other/better possibilities? It would be nice to get the immediate issue fixed on the Provost's website. Thanks!

#14 Updated by Dominic Giglio over 4 years ago

Just sat down for my 3 hour break between classes. Checking into it now.

#15 Updated by Matt Gold over 4 years ago

Thanks, Dom.

#16 Updated by Dominic Giglio over 4 years ago

OK, in an effort to keep things simple as well as accomplish the task at hand, I've identified the six templates that are currently being used by the Provost's site. They are:

blog.php
page.php
single-news.php
single.php
template-fullwidth.php
template-right-sidebar.php

These are the templates that needed to be edited to add the consistent header across all pages.

Erin,

I hope I didn't confuse you back in comment 7. What I was trying to explain was that when you're working in a child theme environment, you must recreate any template from the parent that you wish to customize in your child theme's folder. After you work with parent/child themes for a while you begin to see that when you're faced with the requirement of overriding may templates you can often find an earlier template where you can make your edits so they affect all the templates below. What I mean is, it would have been nice if the header.php template from the luna parent would have been the place where the site name and title were being generated. Then we could have overrode and edited a single template in our child and been done with it. But since the code in question comes a little later, in the actual page templates themselves, we were forced to override many templates in this specific case.

I've updated the appropriate templates and pushed those changes up for inclusion in the next release (2/11).

Commit: https://github.com/castiron/cac/commit/a22a2e75d590f64926861c8da8b725ad9b46f892

Next, could you be a little more specific about the problems that you're having with images?

Allowing the featured image of the blog post to not be the same as the image displayed in the blog post.

I'm not sure I understand exactly what the problem is here. A slightly more detailed description of the problem, and the solution you are hoping for, would be greatly appreciated.

Finally, regarding the reviews widget. I double checked the widget admin page and I see that those reviews are provided by a custom Luna widget. It doesn't appear to have options for linking to any external (or internal) content. What do you mean by "hotlinks?" Do you mean "hyperlinks?" What exactly do you want to link to? The review itself? The reviewers home page? We might be able to whip up a custom action or filter in our child's functions.php, but depending on what you want, it may not be simple.

Sorry for the delays, I've been trying to get myself into a rhythm now that spring classes have started but it hasn't been working as well as I'd hoped. :-)

#17 Updated by erin glass over 4 years ago

Hi Dom,

Thanks so much for adjusting all of the relevant templates! I think we can leave the image issue alone for the time being. (The problem is that blog posts automatically inserts the featured image (that shows up on the homepage) also inside the post. This is a problem if you want the featured image to be different than the image inside the post, but I think I can live with the constriction for the time being.)

Sorry for my confusing language regarding the Luna review widget. Yes, I meant "hyperlinks." If not too much trouble, it would be nice to make the review link either to another post on the blog, or to another place on the web where the review is posted. At the moment, the widget does not seem to allow for html.

Many thanks again for all your help. Hope your semester is getting off to a great start!

Best,
Erin

#18 Updated by Dominic Giglio over 4 years ago

Erin,

I think I have an answer for you on the Featured Images. It sounds to me like you're trying to do something that WP doesn't support. You say above:

The problem is that blog posts automatically insert the featured image (that shows up on the homepage) also inside the post. This is a problem if you want the featured image to be different than the image inside the post

This is just the way featured images work. If a featured image is set on a post, the Luna theme uses it on the homepage and also shows it at the top of the post. There is no way to have more than one featured image. You can't have one featured image for the homepage and another for the post itself. You can add additional images to a post though. Those won't show up on the homepage. The best we could do would be to remove the code that shows a featured image on the post itself. It looks like we've already removed that code from the single.php template in the luna-cfr child theme. But, this post:

http://chaserobinson.net/news-item/taxing-trading-and-ruling-in-the-early-islamic-jazira/

still displays the featured image. This is because it uses the single-news.php template. That template does exist in the child theme folder, but you will need to remove lines 45-50 if you'd like to prevent the featured image from being displayed at the top of the post.

Let me know if you'd like it removed for the next release.

As far as the Reviews widget goes, the theme just doesn't provide the necessary options or code/html structure to do what you'd like it to. It's a very basic widget. It appears to strip out HTML tags from a review post. I tried to add a link to the body of one review but it didn't render as a link on the page when I refreshed. There is one thing you could try. In the title of the review, type in an actual (<a></a>) link code. For example, in the title of the Adam Silverstein review, I replace "Adam Silverstein" in the title with "<a href="/">Adam Silverstein</a>". When I refreshed the page, his name at the bottom of the page was rendered as a link to the homepage. So you should be able to replace "/" with a link to Adam's site and be good to go. I know it's not perfect but the theme leaves us little alternatives in this situation.

#19 Updated by erin glass over 4 years ago

Thanks for looking into these two issues. I see what you're saying about the featured images. At the time, I was hoping to disable the automatic insert of featured images into blog posts so that I could choose a different image and manually insert it into the post. However, I did my best to crop images so that they would be appropriate enough to show up both ways. At this point I think dismantling this feature might make more work then it's worth as I'd have to go back and insert images for every post. But thanks for clarifying -- it's good to know for the future.

Also, I've noticed that the Twitter widget on the Provost's page no longer works (bottom left footer area). Do you think that's because of the most-recent update? Would be good to know in case the Twitter feed for the Fellowship page also stops working when we make the child theme updates.

Thanks again!

#20 Updated by Dominic Giglio over 4 years ago

The twitter widget problem is not being caused by the new code. The new code will not be released to the production site until the 11th.

I logged into twitter and searched for chasefrobinson and his page just sits there with a spinning ajax widget. I don't think the problem is on our end. I think there is a problem with his twitter account.

#21 Updated by Matt Gold over 4 years ago

Hi Dom -- thanks for checking into this. FWIW, here is the twitter account in question: https://twitter.com/chasefrobinson

#22 Updated by Dominic Giglio over 4 years ago

Yup, that's the one I was looking at. It seems to be loading fine now.

I wonder if it has something to do with the fact that there hasn't been a tweet from that account since 3/21? It's a bit of a stretch but I'd definitely tweet something out and see if it shows up in the footer. I looked at the Luna Twitter widget code and there isn't any obvious date related restrictions but the widget works fine on Fellowships and Funding. This leads me to think there might be something going on with the actual twitter account.

There aren't any errors in Chrome's console so I know the javascript is working the way it's supposed to. Might want to try enabling another twitter widget plugin to see if it can successfully grab tweets. That should tell us if the problem is on twitter's end or somewhere on ours.

#23 Updated by erin glass over 4 years ago

Dom, you're right -- it's an issue with the Provost's twitter feed. I plugged in a different twitter account and the widget worked just fine. Perhaps it is due to inactivity. Matt, should I suggest some tweet possibilities to the Provost?

#24 Updated by Dominic Giglio over 4 years ago

I would definitely recommend a few tweet suggestions. That's the best way to check if the widget is still working. If he tweets and nothing shows up in the footer then we'll know there's a problem elsewhere.

#25 Updated by Dominic Giglio over 4 years ago

Erin,

Have you had a chance to try some new tweets to test the twitter widget in the footer? Can we mark this issue as resolved?

#26 Updated by Boone Gorges over 1 year ago

  • Status changed from New to Resolved

Also available in: Atom PDF