work outside of loop

57 views
Skip to first unread message

Hunk

unread,
Sep 30, 2009, 9:06:12 PM9/30/09
to Magic Fields
since of version 1.1 I added the feature for this work outside of the
loop.

if your you want get a value of a field outside of the loop you must
put the post_id of post which it contains the custom field.


The function "get" you can pass these values

get ($fieldName, $groupIndex=1, $fieldIndex=1, $readyForEIP=true,
$post_id=NULL)
$fieldName - string containing field name
$groupIndex - integer representing the index of the group in case the
group is duplicated.
$fieldIndex - integer representing the index of the field in case the
field is duplicated.
$readyForEIP - if true and the field type is textbox or multiline
textbox, the resulting value will be
wrapped n a div that is ready for EIP.
$post_id - if you want work outside of loop you must put post_id (id
of the post/page)


examples

echo get('name_field',1,1,0,20) return value of the post 20 with name
name_field
echo get('name_field',1,1,1,40)

function get_audio
get_audio ($fieldName, $groupIndex=1, $fieldIndex=1,$post_id=NULL)
$fieldName - string containing field name
$groupIndex - integer representing the index of the group in case the
group is duplicated.
$fieldIndex - integer representing the index of the field in case the
field is duplicated.
$post_id - if you want work outside of loop you must put post_id (id
of the post/page)

echo get_audio('my_audio',1,1,40) return player with audio of the
post/page 40

function get_image
get_image ($fieldName, $groupIndex=1,
$fieldIndex=1,$tag_img=1,$post_id=NULL)
this function create one thumbnails (only once) if your you placed
parameters in the field (Max Height, Max Width or Custom) return url
of the thumbnail , if you did not place parameters for the field of
the image return the URL of the image.
$fieldName - string containing field name
$groupIndex - integer representing the index of the group in case the
group is duplicated.
$fieldIndex - integer representing the index of the field in case the
field is duplicated.
$tag_image - if your you do not want that tag of image returns it
places 0, defualt is 1 (return tag image)
$post_id - if you want work outside of loop you must put post_id (id
of the post/page)

echo get_image('my_image',1,1,1,40) return tag of image with value of
the field my_image of the post 40
echo get_image('my_image',1,1,0,20) return url of the image of the
post with the id 20

*new function* since version 1.1
function gen_image ($fieldName, $groupIndex=1,
$fieldIndex=1,$param=NULL,$attr=NULL,$post_id=NULL)

this function create a thumbnail (only once if this image was created
before then is get from the cache) if you set a new parameters in
the $params (array) return url of the new thumbnail , if you didn't
set parameters return the URL of the image.

$fieldName - string containing field name
$groupIndex - integer representing the index of the group in case the
group is duplicated.
$fieldIndex - integer representing the index of the field in case the
field is duplicated.
$param - array with params of the phpthumb
$attr - array with params of the tag image, (alt, class, id, rel, etc)
$post_id - if you want work outside of loop you must put post_id (id
of the post/page)

examples.

$new_params = array("w"=> 100, "h" => 100, "zc" => 1, "q" => 1);
$add_tag = array("alt" => "one image", "class"=>" class_1
class_2","rel" => "one rel");

echo gen_image('my_image',1,1,$new_params,$add_tag,40);
echo gen_image('my_image',1,1,NULL,$add_tag,40);
echo gen_image('my_image',1,1,$new_params,NULL, 40);

function getFieldOrder

getFieldOrder($field_name,$group=1,$post_id=NULL)
return one array with id of the field index of the one field duplicate

$fieldName - string containing field name
$group - id of group, if the field is in a group
$post_id - id of the post, if you want outside of loop

examples

$my_field_duplicate = getFieldOrder('my_field',1,40);
foreach($my_field_duplicate as $k => $v){ ;
echo get('my_field',1,$v,0,48);
}

function getGroupOrder
function getGroupOrder($field_name,$post_id=NULL)

return array with id of group index in order of the group duplicate
$field_name - a field that is in the group
$post_id - id of the post, if you want outside of loop

$my_group_duplicate = getGroupOrder('one_field',38);
foreach($my_group_duplicate as $k => $v){
echo get('jo',$v,1,1,38);
}

these are examples about how using the functions of the front-end
outside loop. if you are working inside of the loop you only need
omit the field $post_id
Reply all
Reply to author
Forward
0 new messages