Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Mike1o1
Sep 5, 2004
Tiluvas
Hi guys,

Great thread so far. Have learned a lot from going through the posts.

I'm new to WP and php/html/css in general, but I do have programming skills in C based languages, so the logic part I understand.

I'm working on helping a friend move from a generic blogger blog to a more official looking web-site for his web-site and podcast. After tons of googling, I decided to start off with a base theme using Thematic. Is that still the suggested approach for writing custom themes? I'm having a hard time keeping things straight as when I do web-searches there is a lot of old and conflicting information out there that seems to change quite a bit between WP versions.

I ripped out the thematic loop and replaced it with my own, where I have php code interspersed with hand-coded html and divs for formatting how articles are meant to be displayed on the main blog page.

I'm wondering if this was the correct approach? I keep reading that the best part of thematic is all the hooks and actions, but I feel like I'm not utilizing any of that and instead I'm just writing my own. I'm a bit worried it might come back to bite me or that I might have to rewrite a lot of code.

What exactly are filters used? Say for example, if I want a new post to appear a certain way on index.php then I write my own filter for how articles are displayed and then that gets re-used on the main loop, search results, category lists, etc.? I'll admit I'm having trouble grasping the concept of filters and actions.

I've only been working on the main page right now - I haven't really even touched how single posts look like, or author pages or anything else. I've spent a lot of time setting up a custom options page for my child theme, and write my own custom widget which displays the most recent podcast. Originally I just yanked out the sidebar loop and hand-wrote my own which made me think I was wasting time, and have since replaced that piece with my own widget.

The work in progress page is https://www.mike1234.com/blog - again, just the main page is what I've been working with so far, I haven't touched single.php or anything yet. Any feedback is appreciated.

Adbot
ADBOT LOVES YOU

rugbert
Mar 26, 2003
yea, fuck you
I think the answer is no but, is it possible to update multiple wordpress sites across domains (but on the same host, not that it matters) from one WP?

One of my clients has a really wonky set up and was wondering if he posts on his personal WP, the same post could automatically post on his shop WP.

cocteau
Nov 28, 2005

The best Darcy.

Mike1o1 posted:

After tons of googling, I decided to start off with a base theme using Thematic. Is that still the suggested approach for writing custom themes? I'm having a hard time keeping things straight as when I do web-searches there is a lot of old and conflicting information out there that seems to change quite a bit between WP versions.

I ripped out the thematic loop and replaced it with my own, where I have php code interspersed with hand-coded html and divs for formatting how articles are meant to be displayed on the main blog page.

I'm wondering if this was the correct approach? I keep reading that the best part of thematic is all the hooks and actions, but I feel like I'm not utilizing any of that and instead I'm just writing my own. I'm a bit worried it might come back to bite me or that I might have to rewrite a lot of code.

The site looks pretty good and the way you're doing it is fine. I like to utilize the WP hooks whenever possible in part because I like WP doing the heavy lifting (and it keeps the code consistent across the site), and makes your site more compatible with future versions of WP and plugins. It can also be easier to implement CSS changes.

A lot of developers that I know either build off of the default theme (now Twenty Eleven) or Studio Press' Genesis, but in fact Thematic was built by Ian Stewart, the main guy behind Twenty Ten (and I assume, Twenty Eleven) so how could that be bad? In the end, when working with WordPress there are a thousand different ways to develop a site, and sometimes you just go with something that works.

Bastard
Jul 13, 2001

We are each responsible for our own destiny.
Is there any easy way to customize the output WP generates for functions such as get_archives, list_pages, or are you really forced to use regexp to change things up a bit (such as adding classes to links)?

McGlockenshire
Dec 16, 2005

GOLLOCKS!

Bastard posted:

Is there any easy way to customize the output WP generates for functions such as get_archives, list_pages, or are you really forced to use regexp to change things up a bit (such as adding classes to links)?
While not an immediate solution, consider something like phpQuery or another server-side DOM manipulator.

Bastard
Jul 13, 2001

We are each responsible for our own destiny.

McGlockenshire posted:

While not an immediate solution, consider something like phpQuery or another server-side DOM manipulator.

Thanks, but those are workarounds, just like using a regexp. I just want WP to give me an multidimensional array of pages, not a completely pre-formatted list. Why is the WP codebase so crappy every now and then/most of the time? :(

Ned
May 23, 2002

by Hand Knit

Bastard posted:

Thanks, but those are workarounds, just like using a regexp. I just want WP to give me an multidimensional array of pages, not a completely pre-formatted list. Why is the WP codebase so crappy every now and then/most of the time? :(

Write your own function to do it? You can use the wp_get_archives code as your base and just have it return an object with the results and then format those.

wp_list_pages could easily be replace by a regular get_posts query.

These two functions have been around forever and were basically ways to put archives/pages in a sidebar. They are both template tags - the archives has been around since 1.2 and list_pages has been around since 1.5.

Asking for a multidimensional array of pages is actually a bunch of queries if you have lots of child/parent relationships. For each individual page you'll have to get any children for that page and continue until the children run out of children. You could definitely write something to do it. I recommend storing any output as a transient in order not to have to constantly run all those queries and just have it update when a new page is created.

Try this: http://codex.wordpress.org/Function_Reference/get_page_hierarchy

If you want to add classes to specific links you'll have to parse the object and build your own html.

Bastard
Jul 13, 2001

We are each responsible for our own destiny.

Ned posted:

Write your own function to do it? You can use the wp_get_archives code as your base and just have it return an object with the results and then format those.

That's my point. For example, wp_get_archives returns a preformatted string, and there's no easy way to format that in any other way.

And of course you can create your own functions, that isn't the problem. It's just that a lot of WP built-in functions seem to completely poo poo on the concept of separating data and views.

Maybe it's just me, but the more I work with the WP code itself instead of just installing plugins/themes, the less developer-friendly it seems.

Ned
May 23, 2002

by Hand Knit

Bastard posted:

That's my point. For example, wp_get_archives returns a preformatted string, and there's no easy way to format that in any other way.

And of course you can create your own functions, that isn't the problem. It's just that a lot of WP built-in functions seem to completely poo poo on the concept of separating data and views.

Maybe it's just me, but the more I work with the WP code itself instead of just installing plugins/themes, the less developer-friendly it seems.

A lot of the template tags are about displaying things in standard ways. Regular functions are about getting back data. You can tell wp_get_archives to use a custom format and then tell it what goes before and after each link. Are you looking to add a class to a specific link in the archives or do you want to add a class to all of them?

I believe WP is very developer friendly. Maybe it is because I am somewhat of an evangelist but when I look at the docs and then take a look at a link to the code in the repository I understand how it works and what options I have when dealing with the functions and then have the ability to make an appropriate decision about how I want to go about handling things.

It doesn't hurt to put a tiny bit of jQuery after a template tag if you want to parse the data and add a class to a part of it. It doesn't hurt to run the output through simple HTML DOM and modify it on that level either.

Captain Corny
Dec 16, 2000

Ned posted:

A lot of the template tags are about displaying things in standard ways. Regular functions are about getting back data. You can tell wp_get_archives to use a custom format and then tell it what goes before and after each link. Are you looking to add a class to a specific link in the archives or do you want to add a class to all of them?

I believe WP is very developer friendly. Maybe it is because I am somewhat of an evangelist but when I look at the docs and then take a look at a link to the code in the repository I understand how it works and what options I have when dealing with the functions and then have the ability to make an appropriate decision about how I want to go about handling things.

It doesn't hurt to put a tiny bit of jQuery after a template tag if you want to parse the data and add a class to a part of it. It doesn't hurt to run the output through simple HTML DOM and modify it on that level either.
Naah, he has a point. What you're proposing are workarounds that make your code less readable and more difficult to maintain and debug. Although the templating system is decent, Wordpress has a bad habit of having hardcoded HTML in the core, which is inconvenient if you want to work on the data. It would be a lot better if, for example, wp_get_archives is split in two. The first function should have all the queries and return an array of posts, the second would call the first, loop through the array and generate the HTML. Developers who want to do something non-standard can call the first function and work on the array.

Although in Wordpress's defense, I've looked under the hood of some other free PHP software, and have seen much, much worse than Wordpress. I still have nightmares from when I wanted to make PHPBB do something non-standard. Wordpress has its inconveniences, but it's easy enough to work with.

Captain Corny fucked around with this message at 10:55 on Jul 20, 2011

Ned
May 23, 2002

by Hand Knit
Just borrow the query you want from the wp_get_archives code and go to town.
code:
$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts 
FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC $limit";
$key = md5($query);
$cache = wp_cache_get( 'wp_get_archives' , 'general');
if ( !isset( $cache[ $key ] ) ) {
	$arcresults = $wpdb->get_results($query);
	$cache[ $key ] = $arcresults;
	wp_cache_set( 'wp_get_archives', $cache, 'general' );
	} 
else {
	$arcresults = $cache[ $key ];
}
if ( $arcresults ) {
	foreach ( (array) $arcresults as $arcresult ) {
            //do stuff with $arcresult
        }
}
If you take out the caching it's even shorter. I'm not going to apologize for the wp_get_archives function because it is really old and is just meant to display a list of archive links. It could be a lot better. But compared to other CMS platforms WordPress is very dev friendly.

cocteau
Nov 28, 2005

The best Darcy.

Captain Corny posted:

Although the templating system is decent, Wordpress has a bad habit of having hardcoded HTML in the core, which is inconvenient if you want to work on the data.

A lot of this is dependent on the theme developer. Some themes are MUCH worse about this than others.

Captain Corny
Dec 16, 2000

Ned posted:

Just borrow the query you want from the wp_get_archives code and go to town.
code:
$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts 
FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC $limit";
$key = md5($query);
$cache = wp_cache_get( 'wp_get_archives' , 'general');
if ( !isset( $cache[ $key ] ) ) {
	$arcresults = $wpdb->get_results($query);
	$cache[ $key ] = $arcresults;
	wp_cache_set( 'wp_get_archives', $cache, 'general' );
	} 
else {
	$arcresults = $cache[ $key ];
}
if ( $arcresults ) {
	foreach ( (array) $arcresults as $arcresult ) {
            //do stuff with $arcresult
        }
}
If you take out the caching it's even shorter. I'm not going to apologize for the wp_get_archives function because it is really old and is just meant to display a list of archive links. It could be a lot better. But compared to other CMS platforms WordPress is very dev friendly.
I don't like this primarily because it duplicates code, but also because there may be core updates that change the way the database is accessed in that segment, and that means you have to redo your own copy of that code. Or more in a practical sense: the website may randomly fail to work in the future.

cocteau posted:

A lot of this is dependent on the theme developer. Some themes are MUCH worse about this than others.
What I was saying had nothing to do with themes.

cocteau
Nov 28, 2005

The best Darcy.

Captain Corny posted:

What I was saying had nothing to do with themes.

Sorry... I guess I'm confused by what you meant.

Gyshall
Feb 24, 2009

Had a couple of drinks.
Saw a couple of things.
Any suggestions for a good, clean, modern corporate theme?

cocteau
Nov 28, 2005

The best Darcy.

Gyshall posted:

Any suggestions for a good, clean, modern corporate theme?

I can think of a lot of good themes.

What kind of content are you going to have? A lot photos? Is it a blog or standard website? Do you need a lot of content areas?

Gyshall
Feb 24, 2009

Had a couple of drinks.
Saw a couple of things.
Standard website, with minimal CMS type of stuff. Maybe a blog, but that would be easy enough to hack through later.

It is a corporate restaurant supply chain, for what that is worth. They sell basically any type of food/meat/ingredient to major restaurants. The main feature of their (early 2000s page) is a "Products" page which lets you see the different order #s and products they have.

Ned
May 23, 2002

by Hand Knit

Gyshall posted:

Standard website, with minimal CMS type of stuff. Maybe a blog, but that would be easy enough to hack through later.

It is a corporate restaurant supply chain, for what that is worth. They sell basically any type of food/meat/ingredient to major restaurants. The main feature of their (early 2000s page) is a "Products" page which lets you see the different order #s and products they have.

You should try to make a custom post type for products and put all of the info in there. It will pay off in the long run.

rugbert
Mar 26, 2003
yea, fuck you
How can I use the is_single function with an array variable?

I know I can do this
code:
<li<?php if(is_single(array("originals", "prints", "t-shirts", "books"))) echo " class=\"expand\""; ?>>
But thats not very dynamic, if I have an array that Im adding stuff to Id like to be able to use that with is_single. Is that possible?

Ned
May 23, 2002

by Hand Knit

rugbert posted:

How can I use the is_single function with an array variable?

I know I can do this
code:
<li<?php if(is_single(array("originals", "prints", "t-shirts", "books"))) echo " class=\"expand\""; ?>>
But thats not very dynamic, if I have an array that Im adding stuff to Id like to be able to use that with is_single. Is that possible?

Do it like this.
code:
$single_check = array('originals', 'prints', 't-shirts', 'books');
$expand = false;
foreach ($single_check as $single) {
   if (is_single($single)) {
      $expand = true;
   }
}
if ($expand == true) {
   echo '<li class="expand">';
}
else {
   echo '<li>';
}

Captain Corny
Dec 16, 2000

cocteau posted:

Sorry... I guess I'm confused by what you meant.
No need to be sorry, I must have sounded irritated but I wasn't. The problems I pointed out have to do with fairly low-level Wordpress custom theme programming, particularly interfacing with the core, so they don't apply to everyone.

EvilTwig
Jan 31, 2001
I'm trying to modify a theme by creating a child theme. In the parent's theme the functions.php file contains a function I want to modify slightly. If I change that function and save the resulting file in the child theme, Wordpress gets angry about me defining a function a second time, due to the way functions.php and child themes work.

I'd rather not modify the parent theme's function, as any updates will overwrite the change.

Is my best bet to create a new function for my purpose and change any calls in the theme code, or is there another approach someone can suggest?

Ignis
Mar 31, 2011

I take it you don't want my autograph, then.


You'd have to unregister the parent's function first. Try following this: http://venutip.com/content/right-way-override-theme-functions

poxin
Nov 16, 2003

Why yes... I am full of stars!
Edit: Disregard, made a stupid mistake.

poxin fucked around with this message at 21:09 on Jul 24, 2011

cocteau
Nov 28, 2005

The best Darcy.

EvilTwig posted:

I'm trying to modify a theme by creating a child theme. In the parent's theme the functions.php file contains a function I want to modify slightly. If I change that function and save the resulting file in the child theme, Wordpress gets angry about me defining a function a second time, due to the way functions.php and child themes work.

I'd rather not modify the parent theme's function, as any updates will overwrite the change.

Is my best bet to create a new function for my purpose and change any calls in the theme code, or is there another approach someone can suggest?

Unlike with other php files in your child theme, you don't copy your old functions.php file into your child theme if you want to make modifications/additions; you need a new functions file that just includes the new functions. Or if you need to modify an existing function, you can follow Ignis' tip to do that.

Daynab
Aug 5, 2008

I don't know if this is the place for "HALP my site is broken!" and I also don't know any code yet but I'd appreciate any answer. I'm trying to get a recent posts widget with post thumbnails. This isn't the problem in itself since there are many supposedly working ones. Last night I was trying this one: http://www.lucagrandicelli.com/special-recent-posts-plugin-for-wordpress/

Anyways the problem: The plugin is supposed to take the first picture of each post and make a thumbnail, but some simply wouldn't display and one even took the wrong picture. Now I don't understand why because there's literally no difference between my post images (all my posts have the same format).

I could dismiss that as a nonfunctional plugin, but I've tried another one who did something similar, so I have no idea what the gently caress.
One thing: my posts do not have a Featured Image, so maybe I should do that?

Thanks in advance!

cocteau
Nov 28, 2005

The best Darcy.

Daynab posted:

One thing: my posts do not have a Featured Image, so maybe I should do that?

Yes. Usually themes/plugins will be looking for this. Try it and if it doesn't work, report back.

Daynab
Aug 5, 2008

Okay I have two weird as hell problems related to featured images.
One, if I set featured images manually, they get inserted into the post and stretched horizontally to the max.

Second, if I use a tool to generate featured images based on my posts, I get the exact same thing as the plugin last night. That is, some simply do not display (and text of my post appears again) and some are plainly wrong (belonging to other posts).
I don't understand why this happens because there's nothing related to other images in my posts, not even some HTML residue.
Any help would be appreciated considering this is stopping me from doing anything with images.


E: for what it's worth I use Arras Theme but I don't think it matters.

Daynab fucked around with this message at 00:51 on Jul 26, 2011

Tars Tarkas
Apr 13, 2003

Rock the Mok



A nasty woman, I think you should try is, Jess.


Daynab posted:

Okay I have two weird as hell problems related to featured images.
One, if I set featured images manually, they get inserted into the post and stretched horizontally to the max.

Is that just with the one theme or all themes? One theme I am working with sets the featured image in the top left corner of the post via default until you turn that off, maybe the images are being displayed by the theme set to a certain aspect ratio.

The Thumbnail Size in your media settings might also be set for a weird aspect ration (default is 150 by 150, IIRC)

Also, are you uploading images solely with the built in image uploader? Most of my images are not uploaded that way due to it being easier to upload via ftp and handcode them in than to deal with the one-at-a-time uploader, but then the images don't show up in any of the backend libraries and I still have to upload the featured image separately. A tool to generate thumbnails might be running into the same problem. Sometimes when I uploaded the image and just selected "use as featured image", it got randomly inserted into the post, but that hasn't happened for a few wordpress updates.

Which tool were you using?

Daynab
Aug 5, 2008

I don't know if it's with all themes and I'm afraid of going back to another theme because I already have some views and the site's layout is pretty dependent on this theme. I do remember that default featured images used to always use the max size for some reason, which is why I wasn't using them.

Thumbnail Size is default at 150 x 150 so obviously it's not working somewhere.

Yeah I've used the wordpress uploader and inserted into posts since I only need one post per image usually. It works fine but like I said, wasn't using featureds yet.

I used http://wordpress.org/extend/plugins/auto-featured-image/ which simply is supposed to generate Featured Images based on the first image in the post. I think it would work just fine without all the other issues, but it did the same as my earlier plugin - stretch some images, forget some and choose wrong for some.

rugbert
Mar 26, 2003
yea, fuck you

Ned posted:

Do it like this.
code:
$single_check = array('originals', 'prints', 't-shirts', 'books');
$expand = false;
foreach ($single_check as $single) {
   if (is_single($single)) {
      $expand = true;
   }
}
if ($expand == true) {
   echo '<li class="expand">';
}
else {
   echo '<li>';
}

Awesome thanks! That got me on the right track. The site Im working on is pretty gross...

Daynab
Aug 5, 2008

Well I fixed it. Sort of, anyway. Featured images are a little strange still but working for now. Turns out Arras has its own Thumbnail settings and you have to "regenerate thumbnails" after you change stuff.

cocteau
Nov 28, 2005

The best Darcy.

Daynab posted:

Well I fixed it. Sort of, anyway. Featured images are a little strange still but working for now. Turns out Arras has its own Thumbnail settings and you have to "regenerate thumbnails" after you change stuff.

Yeah, a lot of themes do stuff like this and it's like a drat needle in a haystack to troubleshoot it. You may need to change your image sizes in settings > media (check online to see if Arras has a recommended size for any of them).

EvilTwig
Jan 31, 2001

Ignis posted:

You'd have to unregister the parent's function first. Try following this: http://venutip.com/content/right-way-override-theme-functions

Sorry to both you and cocteau for not saying thanks for the help earlier, I got a little tied up. Ignis, the link you posted is exactly what I am trying to do, so thanks.

Mike1o1
Sep 5, 2004
Tiluvas
I've been working on a simple child theme and I'm trying to make some of my posts a little bit cleaner by not displaying comments when the user views a single post, unless the user specifically went to the_comments url. I'm not really sure how to do this, though.

I know I can use comments.php to modify how the comments are displayed, but I'm not sure what I need to do on single.php. Do I need to use some conditional code to analyze the incoming URL and if "?comments" is in the URL, then display and format the comments?

Also, I'm using the Disqus plugin, but I don't think that should change a simple on/off display switch based on the URL.

I'm not very familiar with PHP, so would appreciate some guidance on whether or not this is the right path to take.

Thanks!

muscat_gummy
Nov 30, 2008
I wrote myself a nice little plugin, and while it works just fine on a single page, it does not work on a network of pages. The problem is that the function current_user_can() for some reason triggers an "You do not have sufficient permissions to access this page" error. What in the world is going on? If I comment out that line the plugin works fine, but I need to check for user level. Even if I just include the function, on it's own outside of any if statement just to see what's going on, it gives me that error. Is there a different function I should be using on a multisite thing?
It works if I install it on each blog separately, but that'll be a pain to do and why would the only thing that breaks on a network-wide activation be the user capabilities function?

Mike1o1 posted:

I know I can use comments.php to modify how the comments are displayed, but I'm not sure what I need to do on single.php. Do I need to use some conditional code to analyze the incoming URL and if "?comments" is in the URL, then display and format the comments?

What's displayed on single.php is defined on loop-single.php (same folder). The function comments_template() close to the end is responsible for the entire comment display, so you can probably build an if statement around that. Someone else might be able to give you more details on what the best way to do that would be.

muscat_gummy fucked around with this message at 21:14 on Jul 28, 2011

Ned
May 23, 2002

by Hand Knit

Mike1o1 posted:

I've been working on a simple child theme and I'm trying to make some of my posts a little bit cleaner by not displaying comments when the user views a single post, unless the user specifically went to the_comments url. I'm not really sure how to do this, though.

I know I can use comments.php to modify how the comments are displayed, but I'm not sure what I need to do on single.php. Do I need to use some conditional code to analyze the incoming URL and if "?comments" is in the URL, then display and format the comments?

There is a global called $paged that will tell you what page of comments is being requested. Check that in your single.php and modify the output accordingly.

Mike1o1
Sep 5, 2004
Tiluvas

Ned posted:

There is a global called $paged that will tell you what page of comments is being requested. Check that in your single.php and modify the output accordingly.

This value always seems to be 0, but I'm not sure if I'm using it correctly - I'm not very good with PHP.

What I did to see what the value contains is I added $paged = get_query_vars['paged']; and then did a simple 'echo $paged' somewhere in my single.php function. Doing so outputs 0 every time. Note that none of my comments exceed more than 1 page of comments, though, so maybe that has something to do with it.

Basically, what I want to do is if the user visits the comments url (i.e. http://www.blah.com/2011/07/12/my-post-name/#comments) then the comments are displayed. If they are just viewing the post url (i.e. http://www.blah.com/2011/07/12/my-post-name/) then the comments aren't displayed, and instead a link is shown.

I'm thinking that since the #comments is just an anchor, and is client side, it isn't being processed by the server, so I have no way of analyzing that server side.

Perhaps I need to add some additional code to add a ?comments=true custom variable to the URL and read it that way?

Ned
May 23, 2002

by Hand Knit
You need to do
code:
global $paged;
echo $paged;
It doesn't actually exist in the URL string but it does exist in the WP Query object.

Adbot
ADBOT LOVES YOU

Kitsch!
Jul 27, 2006

God made Adam and Eve, not Fluffy and Eve.
Can anyone recommend any paid Worpdress templates that offer decent support (forums or otherwise)? I've been using free themes so far but unfortunately, whenever something inevitably goes awry I've had to rely on my very limited CSS knowledge to try to fix things (which usually ends up making things worse and breaking the site).

I've been looking at Simple Themes (http://www.simplethemes.com/wordpress-themes/), but I'm kind of hesitant about purchasing one and wondering if it's even worth it. I basically need something for a blog format that's simple but somewhat customizable.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply