I am trying to add two custom fields to my categories (which I have done thanks to this answer - Any examples of adding custom fields to the category editor?)
And now I need to call them within my template (via a Headway custom code block).
I have seen a bunch of almost there examples, but I just can't get it to work!
If you can please let me know the exact php I would need to use to call one of the fields I would be oh so grateful! Otherwise I'm resorting to a plugin (and I already have way too many!)
Here is the code
<h1 class="collapseomatic" title="Click for more" id="<?php the_ID();?>">
<?php single_cat_title(); ?>
</h1>
<p>FIELD ONE </p>
<div id="target-<?php the_ID(); ?>"
class="collapseomatic_content force_content_collapse"
style="background: white; min-height: 16px; padding: 5px; width: 95%;">
<?php echo '<div class="seo_text"><p>'FIELD TWO'</p></div>'; ?>
<?php echo '<div class="seo_text"><p>'.category_description( $category_id ).'</p> </div>'; ?>
</div>
UPDATE
I have now tried to create a custom function
function ddgseo_title1() {
//get the current term
$term = get_term_by(
'slug',
get_query_var('term'),
get_query_var('taxonomy')
);
//get the saved category custom fields
$fields = get_option(MY_CATEGORY_FIELDS);
if ( isset($fields[$term->term_id]) ) {
//extract just the needed term fields
$term_fields = $fields[$term->term_id];
//Now $term_fields holds all of your category fields so to get a specific field:
if ( isset($term_fields['_ce4-categoryTitle']) )
echo $term_fields['_ce4-categoryTitle'];
}
}
And am trying to call the title into the theme html with .ddgseo_title1()
but again no luck
$field=get_option('FIELD-NAME');
andecho $field['SUB-FIELD'];
?get_option(MY_CATEGORY_FIELDS)
and it showed "Array" I tried addingget_option(_ce4-categoryTitle)
andget_option('_ce4-categoryTitle')
and they both came up blankI also tried<?php $field=get_option('_ce4-categoryTitle');?>
again, blank. And have tried a bunch of other combinations ... I really have no idea! I need to know the exact php that would go in between either<p> </p>
or H2 tags.var_dump($fields);
to see the contents of the variable. Another one which prints the var with better formatting isecho '<pre>' . print_r($fields, true) . '</pre>';
. The PHP Manual is always nice to consult, in the comments section you'll find lots of useful stuffvar_dump($fields);
what do I put around it, and how does it know which of the two field to show? Would you be able to give me an example using the first bit of code to show either FIELD ONE of FIELD TWO?