nofel — 2012-01-11T09:24:21-05:00 — #1
hi, i am working on a wordpress site and i have couple of images that i want in background, i got like 15 pages and each page will have different background. i wanted to ask what will be the best approach? make a template with a div and hard code image url or make 15 template which seems insane and put images by hard code.
rguy84 — 2012-01-11T09:57:01-05:00 — #2
What determines what image is shown? Category? Author? Random? etc
nofel — 2012-01-11T09:59:07-05:00 — #3
rguy84 — 2012-01-11T10:30:42-05:00 — #4
Some may not like this, but whatever. In styles.css, I would make styles for each image:
Replace name with something you can recognize.
Now in header.php
// continue through authors
For reference: http://codex.wordpress.org/Function_Reference/is_author
nofel — 2012-01-11T10:37:13-05:00 — #5
how about using custom fields?
rguy84 — 2012-01-11T11:03:25-05:00 — #6
Custom fields wouldn't let you swap backgrounds to my knowledge.
rguy84 — 2012-01-11T11:26:45-05:00 — #7
Custom fields hold text, not links. You would need to do major tweaking to the theme to make it work...
nofel — 2012-01-11T11:29:18-05:00 — #8
i guess custom field will work. a question though, how do i set a path to a image in custom field, which r uploaded in wp-content/uploads?
nofel — 2012-01-11T11:36:23-05:00 — #9
I am having issues, i have copied a template but every template shows this on top of heading and also posted by abc, in the template code, what should i remove to get rid of this?
rguy84 — 2012-01-11T11:42:55-05:00 — #10
You need to edit a few files. I found: http://codex.wordpress.org/Using_Custom_Fields_to_attach_images,_links_or_files_to_a_post_easily. Note, using custom fields to do this, you will need to point to the file every post. My way is automatic
rguy84 — 2012-01-11T11:45:04-05:00 — #11
I would need to see code to even take a guess.
nofel — 2012-01-11T12:12:17-05:00 — #12
Well, it served me the purpose i was looking for, i just had to put the url of every image in my custom field, i m not getting into much of php coz i am not a php guru but thanks, i got one issue on every page i get search bar before the title like this and i am guessing it has something to do with get_template_part? how can i get rid of it and the 'posted by' from the code
rguy84 — 2012-01-11T12:18:16-05:00 — #13
Again, I need to see both the php code and the rendered code to be able to help. You're saying why does my car not start, however you won't pop the hood,
nofel — 2012-01-11T12:31:44-05:00 — #14
hahah, nice example you gave. i made it work by using the_content() and get_the_title(); however the permalinks are gone here the template code
Template Name:Backgound images
<div id="content" role="main" style="margin-top:10px;">
/* Run the loop to output the posts.
* If you want to overload this in a child theme then include a file
* called loop-index.php and that will be used instead.
//get_template_part( 'loop', 'index' );
echo "<h2 class=\\"entry-title\\"><a rel=\\"bookmark\\">".get_the_title(). "</a></h2>";
</div><!-- #content -->
</div><!-- #container -->
<img src="<?php echo get_post_meta($post->ID,'bg_images',true); ?>" />
<?php get_footer(); ?>
and the link for live site
nofel — 2012-01-11T15:56:42-05:00 — #15
Just wanted to know, if its possible to use template in post? because i don't see any template drop down, whereas i got template which is showing up in pages
jaagare — 2012-01-12T06:47:04-05:00 — #16
that's not possible by default. There are plugins available that enable templates for posts. Or you can create category / taxonomy based layouts.
nofel — 2012-01-12T06:49:14-05:00 — #17
Ah ok. i will look into it but why doesn't post have templates? without plugin
jaagare — 2012-01-12T09:35:02-05:00 — #18
Well thats because its the way posts are supposed to be. Usually page templates serve a purpose like if you want a specific post with some specific design. In case of posts its a group of different content. Hence say wordpress allows you to say create a category template. If you want to have all posts with say Category - Featured as a different layout you could create that using category templates.
rguy84 — 2012-01-12T10:36:35-05:00 — #19
The piece of code that you posted is actually a template. A bare-bones level of how everything works is, you start a new post, when you hit publish, and go to your homepage, index.php is called. Based on what you specify in you settings, it grabs the last x posts. When you click on a post title, single.php is called.
Side note: My code above is not 100% correct, my apologies. The correct code is:
// continue through authors
The orginal code would change the background based on the latest author, so this included the main page of the blog. In your code block you posted in #14, the line:
echo "<h2 class=\\"entry-title\\"><a rel=\\"bookmark\\">".get_the_title(). "</a></h2>"
is close to permalinks, you just forgot to start the link. You need to change it to:
echo "<h2 class=\\"entry-title\\"><a href=\\"".get_permalink()."\\" rel=\\"bookmark\\">".get_the_title(). "</a></h2>";
You can create templates for specific posts, post categories and author specific. This page mentions the author part: http://codex.wordpress.org/Author_Templates#Which_Template_File_is_Used.3F since you were just 0changing the background image, I detailed how to do it via header.php versus setting up author specific templates. I would have to think a minute, but at first glance, you'd have to edit header.php anyway.:)