How do I get WordPress authors to show on posts and not pages
August 3, 2012 1:15 PM   Subscribe

WordPressFilter: How can I make a WordPress author have their name show up in the posts they make, but not the pages they make?

So I have a website that is basically a customized theme for Wordpress. It's mostly used as a static site, but I'd like to extend the blog functionality, and will have multiple authors writing in this blog. But when I try to insert the code I've found into what I think is the proper php page (it's custom and called loop-page.php - the actual code references the_author_posts_link and works), it shows the author's name at the top of every single page. I really only want it displayed on the blog pages - I can provide some php code samples or do some wading through the code if anyone thinks they know how to fix this...

Of course if anyone has other solutions to this problem, I'm all ears! Basically, I just want to get rid of all author information on static pages, but keep author information for my new blog setup. Thanks!
posted by antonymous to Computers & Internet (10 answers total) 2 users marked this as a favorite
It it comes to it, there are a number of conditional tags that you can use within the template to distinguish between pages and posts:

The most likely to help you is is_page()
posted by RobotHero at 1:43 PM on August 3, 2012

If you're viewing the blog with multiple posts per page there's a possibility the posts may have different authors. Are you just displaying one post per page no matter what? Either way, I'm pretty sure the snippet doesn't need to be in loop-page unless your theme is doing something funky. Try inserting into single.php and into loop.php after this line (or similar):

<?php while ( have_posts() ) : the_post(); ?>
posted by elerina at 2:08 PM on August 3, 2012

Whoops, I misread part of your question. The theme might not be structured the way I'm used to seeing, and that's fine. If it's showing on the blog pages how you like it, then just check to make sure it's not a Page page (heh) before the snippet (if !is_page() etc).
posted by elerina at 2:19 PM on August 3, 2012

Short answer: you need to edit the files in your active them.

Marginally less short: you're looking for chunks of code that include functions like get_the_author_*. When you compare these theme files to what's being displayed it should be fairly obvious what you're looking for.

What could complicate matters is if the theme is using the same block to display posts and pages. You can either make it so you use different template files or you can use conditionals as is specified above.

Depending on how much time you want to spend on this and how much you care to learn about templates you might just want to pay someone to make various changes for you. WP templates aren't a high wall to scale but they can be particular, specially if you're built on some that are a little sketchy to begin with.
posted by phearlez at 2:57 PM on August 3, 2012

If you have an individual "page.php" file in your theme, edit that and done. If not, then probably you're editing index.php to suit your needs. Which of the template files does your theme actually have?
posted by artlung at 1:16 PM on August 4, 2012

Response by poster: Thanks for the help everyone. Unfortunately I haven't been able to fix the problem. The folks that made our site made quite a few mistakes (IMO), such as not following standard template conventions, hard-coding lots of HTML into PHP files, etc. And the site was just made last year, so it's not like they have excuses. Heck, on the main page that displays the individual blog posts, they even figured out a way to make sure the headlines do NOT link to the individual posts, which makes my attempts to raise the visibility of the site even more problematic frmo an SEO perspective.

It's really too bad because the site looks pretty good, but the underlying foundation is crap - I think I'm going to have to learn some PHP and how Wordpress works in order to solve this problem.
posted by antonymous at 8:41 AM on August 6, 2012

Best answer: antonymous. it's hard to make a truly terrible theme, but I have seen it. I'm pretty certain that some simple refactoring could take your woes away. For example for your issue with headlines not being links - it will probably be as simple as taking something like your example of the titles not being linked using good HTML. It may be as simple as changing:

<h2><?php the_title(); ?></h2>


<h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>

If you have any other questions check - I bet most of your issues are easily solvable.

Also, when evaluating a theme's utility I like this checklist for doublechecking theme solidity.

If you are looking to outsource this please feel free to hit me with a MeFi mail.
posted by artlung at 10:08 AM on August 6, 2012

Oh crud, that checklist page now says (though almost all of it is still good advice) go to this checklist instead. My bad.
posted by artlung at 10:12 AM on August 6, 2012

Response by poster: artlung, thanks for your help - that solves the other major problem I was having, which I had been attempting to fix this morning. I'd actually used very similar code earlier (found somewhere online) and it managed to turn all of my content into a link (even after I fiddled with it to the point where I thought it should work). The code you posted above worked like a charm, thank you very much!

I will go through the checklist and perhaps make a post in stackexchange and will follow up in this thread if I figure it out (or via your MeMail offer if I don't!). After tinkering around more with it this afternoon I've gotten to the point where the individual blog posts have the author info, but the page that displays them all only shows the headline and the content. Of course, I've also introduced new problems, like the nothing-but-HTML sidebar suddenly vanishing on those individual blog posts, but hey, I'm having some fun at least.

FYI, I've got an index.php, a page.php, a companyname.php, a companyname-home.php, etc. and I'm really not sure which is doing what so it might be a day or two before I get this all better sorted out. Again, thanks.
posted by antonymous at 12:54 PM on August 6, 2012

As to "which is doing what" - there's a template hierarchy document that includes a diagram on the order in which templates get used for individual post and page types.
posted by artlung at 7:36 AM on August 7, 2012

« Older I no longer trust dropbox. What better...   |   A medical operation that's SFW Newer »
This thread is closed to new comments.