Jump to content


Photo

Custom post types..


  • Please log in to reply
7 replies to this topic

#1 Funkydrummer

Funkydrummer

    New member

  • Member
  • 10 posts

Posted 20 January 2011 - 02:49 AM

Hi,
I just I just watched the custom post types 7-part video tutorial(killersites)
great stuff! But i´m intrested in adding video or maybe
a picture download link through custom fields in the single-product.php file..

similar to this,
http://popcritics.co...ies/adams-apple

I Know that i have to query the custom feilds but how will
the code looks like?

Is there any easy way to pull that of?
  • 0

#2 Ben

Ben

    Administrator

  • Administrators
  • 5,661 posts
  • LocationGainesville, Florida

Posted 20 January 2011 - 04:07 PM

I'll get back to you on this later today.
  • 0
Benjamin Falk
Falken Creative : Twitter

#3 Ben

Ben

    Administrator

  • Administrators
  • 5,661 posts
  • LocationGainesville, Florida

Posted 21 January 2011 - 11:18 PM

Sorry for the delayed response, I have been super busy recently.

There are two ways to do this: with custom post types, or with custom fields.

-- If you do it with custom post types, probably by creating a "Movie" custom post type, you would need to make edits to the "functions.php" file, adding the post types and the code necessary for the fields you want to save data in (in my example code, I added the custom post type fields within product_options() and and wrote the code to save the data in those fields within save_options().

In the file where you want to display your data (in my example, it was single-product.php) I used this code to get the data from the database:

$custom = get_post_custom($post->ID);
$price = $custom['price'][0];
Then, wherever I needed to display the price, I used PHP to echo the variable. You'd need to do the same things with your own custom post type fields.

-- Secondly, you could do this using custom fields. For more info on custom fields, look at

http://codex.wordpre...g/Custom_Fields
http://justintadlock...ds-introduction
  • 0
Benjamin Falk
Falken Creative : Twitter

#4 Funkydrummer

Funkydrummer

    New member

  • Member
  • 10 posts

Posted 23 January 2011 - 08:37 AM

Thanx for your answer!
Im gonna try to use custom feilds.
But just one last thing.. if I want to style the category page
similar to this,

http://www.coolibox.com/produkter.php

Which file shuld i change(floats, the 2 Different post background colors, size of the box,)?

And if i want to have a larger picture on the singe.php and (not the same thumb 200px*200px)

(My test page)
http://www.magnustan.../?type=grovkorv

Your help is amazing, thanx!

Best,
Mang
  • 0

#5 Ben

Ben

    Administrator

  • Administrators
  • 5,661 posts
  • LocationGainesville, Florida

Posted 23 January 2011 - 03:31 PM

If you want to change how a category displays, you'll need to edit the section of code within loop.php that starts with

<?php /* How to display products. */ ?>
(approximately line 136.)

You will need to edit the CSS styles in order to make each item display on its own line -- mainly be removing "float:left" from ".archive .product", but you'll probably need to make additional changes as well.

The alternating background colors would have to be done with some sort of loop within Wordpress to add a class name to each product:

Add "$num = 1"; before "<?php while ( have_posts() ) : the_post(); ?>" (loop.php, line 72) and then replace the existing line 147

<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
with

<div id="post-<?php the_ID(); ?>" class="product type-product hentry <?php if ($num%2) { echo "product-even"; } else { echo "product-odd"; } $num++; ?>">
This uses the modulus operator (% - see http://php.net/manua....arithmetic.php) to divide $num by 2 and check for any remainder. If it results in 0, the row is even, otherwise, the row is odd. This will add a class to each product, and you can use CSS to style the background color of odd or even rows.

You will probably want to use a custom field for the larger picture on the product page. Either you could use a plain text input and add the URL to the image you want to display, or you might look at the Custom Field Template plugin that allows you to add the WYSIWYG toolbar to custom fields: http://wordpress.org...field-template/
  • 0
Benjamin Falk
Falken Creative : Twitter

#6 Funkydrummer

Funkydrummer

    New member

  • Member
  • 10 posts

Posted 24 January 2011 - 09:02 AM

Great Thanx!
But how do i include/show the customfeilds metabox in the new custom post type?
  • 0

#7 Ben

Ben

    Administrator

  • Administrators
  • 5,661 posts
  • LocationGainesville, Florida

Posted 24 January 2011 - 10:21 AM

you need to edit your functions.php to add support for the custom fields within your custom post type. Look for (approx.) line 515:

'supports' => array('title', 'editor', 'thumbnail')
and change it to:

'supports' => array('title', 'editor', 'thumbnail', 'custom-fields')
http://codex.wordpress.org/Function_Reference/register_post_type
  • 0
Benjamin Falk
Falken Creative : Twitter

#8 Funkydrummer

Funkydrummer

    New member

  • Member
  • 10 posts

Posted 24 January 2011 - 01:06 PM

Thanx Ben,

Just minor problems left..
The test "download button" dont show in Internet Explorer but works fine
in the other browser (firefox etc)...

http://www.magnustan...uct=test-korv-4


And i´m also interested in styling the custom meny sidebar wiget(that controls the product nav) or just wrap it with a
background picture? or maybe sliding door version, is that possible?
example link (glossy yellow product nav-box),

http://www.charkdeli...r.se/sortiment/


And the last question, is there a way to have like a table grid that you can control from custom feilds(food declaration)?

Thanx for your great help you are the best!


Best,
Mang
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users