Jump to content
Stef's Coding Community

Custom post types..


Recommended Posts

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?

Link to post
Share on other sites

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.wordpress.org/Custom_Fields

http://justintadlock.com/archives/2007/10/24/using-wordpress-custom-fields-introduction

Link to post
Share on other sites

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.magnustannfors.se/nordchark_wp33/?type=grovkorv

 

Your help is amazing, thanx!

 

Best,

Mang

Link to post
Share on other sites

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/manual/en/language.operators.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/extend/plugins/custom-field-template/

Link to post
Share on other sites

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

Link to post
Share on other sites

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.magnustannfors.se/nordchark_wp33/?product=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.charkdelikatesser.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

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...