Add Custom URL field to Categories and Show it on Category Page

Posted in: Newspaper
Post count: 104

Hello,

I have my website running in English and Hindi Language.

http://www.naukrinama.com
http://www.naukrinama.com/hi/

I have different categories created for Hindi and English site. Now i want to link the categories of both these site with each other.

How can I add a custom URL field in the category section of my website where I can place the URL of the other language category.

And then I want to show this URL in form of a button ahead of the category name in the category listing page.

Please let me know how can this be achieved.

Post count: 104

Hello,

I write this code to add custom fields to my category page :

//add extra fields to category edit form hook
add_action ( ‘edit_category_form_fields’, ‘extra_category_fields’);
//add extra fields to category edit form callback function
function extra_category_fields( $tag ) { //check for existing featured ID
$t_id = $tag->term_id;
$cat_meta = get_option( “category_$t_id”);
?>

<input type="text" name="Cat_meta[img]" id="Cat_meta[img]" size="3" style="width:60%;" value="”>
<input type="text" name="Cat_meta[extra1]" id="Cat_meta[extra1]" size="25" style="width:60%;" value="”>
<input type="text" name="Cat_meta[extra2]" id="Cat_meta[extra2]" size="25" style="width:60%;" value="”>
<?php
}

// save extra category extra fields hook
add_action ( 'edited_category', 'save_extra_category_fields');
// save extra category extra fields callback function
function save_extra_category_fields( $term_id ) {
if ( isset( $_POST['Cat_meta'] ) ) {
$t_id = $term_id;
$cat_meta = get_option( "category_$t_id");
$cat_keys = array_keys($_POST['Cat_meta']);
foreach ($cat_keys as $key){
if (isset($_POST['Cat_meta'][$key])){
$cat_meta[$key] = $_POST['Cat_meta'][$key];
}
}
//save the option array
update_option( "category_$t_id", $cat_meta );
}
}

add_action ( 'category_add_form_fields', 'extra_category_fields');

Post count: 104

Hello,

I have found out the solution to add custom field to a category and have added it as well. Here is the screenshot for the same : http://imgur.com/qbLrDNo (See the field name “Hindi Category URL” in it)

Now i just want to get the value of this field printed in front of the category name on the category page. See this screenshot : http://imgur.com/d7SFElu

Can you tell me the file in the theme code where the category title is generated, so that I can get the necessary code added there ! I think there would be a function named get_category_title for it.

Post count: 22421

Hello,
You can find the file in which the title is called here: http://screencast.com/t/5RppuO8Z
Best of luck on your project!
Thank you!

Post count: 104

Hello Bogdon,

Thanks for your reply !

I have resolved the issue at my end and achieved the desired result as I wanted 🙂

Thanks for the help !

Viewing 5 posts - 1 through 5 (of 5 total)
The forum ‘Newspaper’ is closed to new topics and replies.