I am new to drupal, I need to create in my .install custom module file a taxonomy, and assign this taxonomy to a specific content type. Any idea how to do it ? Thanks !
I assume that with "create a taxonomy" you mean "create a taxonomy vocabulary". If this is the case, you need to populate an array such as:
$vocabulary = array(
'name' => t('<VOCABULARY_NAME>'),
'multiple' => 0, // or 1, if you need multiple terms associated to any single node
'required' => 0, // or 1, if the association is required
'hierarchy' => 1, // or 0, if is a tag-like term
'relations' => 0,
'module' => '<YOUR_MODULE_NAME>',
'weight' => 0,
'nodes' => array('<YOUR_NODE_TYPE>' => 1),
);
and save the vocabulary by issuing
** EDIT **
$ret = taxonomy_save_vocabulary($vocabulary);
If $ret == 1 you have correctly saved your vocabulary and $vocabulary['vid'] will have the vid of the newly created vocabulary. If you want to add terms to it, you create arrays:
$term = array(
'vid' => <VOCABULARY_VID>,
'name' => "<TERM NAME>",
'description' => "An optional description for the term",
'weight' => <AN_INTEGER_OPTIONAL_VALUE_FOR_WEIGHT>,
);
$ret = taxonomy_save_term($term);
and again $ret will be set to a status value of your save operation and $term['tid'] will be the term id of the new term.
Related
I have bodytext and image so like this type of list where can I found? Can I get page list in select box?
$GLOBALS['TCA']['tt_content']['types']['text_image_left'] = [
'showitem' => '
--palette--;palette.general;general,
header, subheader, header_layout,menu,
bodytext;bodytext_formlabel,
--div--;tabs.images,
image,
--div--;tabs.appearance,
--palette--;palette.frames;frames,
--div--;tabs.access,
hidden;field.default.hidden,
--div--;tabs.extended
',
'columnsOverrides' => ['bodytext' => ['config' => ['enableRichtext' => true]]]
];
Hm, not sure if I get your question right. You asked
1. for a list of TCA types
2. how to get a list of pages in a select field (?)
You can find the complete TCA Documentation here:
https://docs.typo3.org/m/typo3/reference-tca/master/en-us/
Interesting part for you is the [column][*][config] part:
https://docs.typo3.org/m/typo3/reference-tca/master/en-us/ColumnsConfig/Index.html
In order to create a select with a page list, you need following kind of configuration.
I would suggest to use "group" type for field.
'page' => [
'exclude' => true,
'label' => 'List of Pages',
'config' => [
'type' => 'group',
'internal_type' => 'db',
'allowed' => 'pages',
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
]
]
I am currently working on a new wordpress website which uses the Newspaper theme, which lets me compose pages with the tagdiv composer plugin.
This plugin makes it fairly easy to show posts of your choosing; with blocks/modules that have built in filters, that allow you to select the posts to be shown based upon the categories, authors, etc. that you choose.
However I would like to show custom taxonomies in there as well, so that I can choose for instance album reviews, which have the custom taxonomy of the letter A attached to it.
For my client I would need to do that since he requested a glossary (alphabetical index).
So far I have created a custom taxonomy called "alphabetical_letter", which houses all 26 characters with the linked posts to it.
The code which I need to alter is this one, preferrably I'd have a drop down list. However I keep failing in getting it right. Could anyone point me in the right direction please ?
/**
* the filter array (used by blocks and by the loop filters)
* #return array
*/
static function get_map_filter_array ($group = 'Filter') {
return array(
array(
"param_name" => "separator",
"type" => "text_separator",
'heading' => 'Filters',
"value" => "",
"class" => "",
'group' => $group
),
array(
"param_name" => "post_ids",
"type" => "textfield",
"value" => '',
"heading" => 'Post ID filter:',
"description" => "Filter multiple posts by ID. Enter here the post IDs separated by commas (ex: 10,27,233). To exclude posts from this block add them with '-' (ex: -7, -16)",
"holder" => "div",
"class" => "tdc-textfield-big",
'group' => $group
),
array(
"param_name" => "category_id",
"type" => "dropdown",
"value" => td_util::get_category2id_array(),
"heading" => 'Category filter:',
"description" => "A single category filter. If you want to filter multiple categories, use the 'Multiple categories filter' and leave this to default",
"holder" => "div",
"class" => "tdc-dropdown-big",
'group' => $group
),
array(
"param_name" => "category_ids",
"type" => "textfield",
"value" => '',
"heading" => 'Multiple categories filter:',
"description" => "Filter multiple categories by ID. Enter here the category IDs separated by commas (ex: 13,23,18). To exclude categories from this block add them with '-' (ex: -9, -10)",
"holder" => "div",
"class" => "tdc-textfield-big",
'group' => $group
),
array(
"param_name" => "alphabetical_letter_id",
"type" => "dropdown",
"value" => td_util::get_alphabetical_letter_id_array(),
"heading" => 'Custom taxonomy:',
"description" => "alphabetical letter custom taxonomy",
"holder" => "div",
"class" => "tdc-dropdown-big",
'group' => $group
),
array(
"param_name" => "tag_slug",
"type" => "textfield",
"value" => '',
"heading" => 'Filter by tag slug:',
"description" => "To filter multiple tag slugs, enter here the tag slugs separated by commas (ex: tag1,tag2,tag3)",
"holder" => "div",
"class" => "tdc-textfield-big",
'group' => $group
),`enter code here`
Edit:
in the meantime I have tried to figure out the td_util I keep seeing.
There is a file called td_util.php one folder up from where this file is, and it mentions the category2id_array so I am currently trying to find out if the problem lies here.
for completeness, this is the bit of text that refers to the category2id array function above (or the other way around more likely).
/**
* generates a category tree, only on /wp_admin/, uses a buffer
* #param bool $add_all_category = if true ads - All categories - at the begining of the list (used for dropdowns)
* #return array
*/
private static $td_category2id_array_walker_buffer = array();
static function get_category2id_array($add_all_category = true) {
if (is_admin() === false) {
return array();
}
if (empty(self::$td_category2id_array_walker_buffer)) {
$categories = get_categories(array(
'hide_empty' => 0,
'number' => 1500
));
$td_category2id_array_walker = new td_category2id_array_walker;
$td_category2id_array_walker->walk($categories, 4);
self::$td_category2id_array_walker_buffer = $td_category2id_array_walker->td_array_buffer;
}
if ($add_all_category === true) {
$categories_buffer['- All categories -'] = '';
return array_merge(
$categories_buffer,
self::$td_category2id_array_walker_buffer
);
} else {
return self::$td_category2id_array_walker_buffer;
}
}
And a bit further down the file it pops up one last time
class td_category2id_array_walker extends Walker {
var $tree_type = 'category';
var $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
var $td_array_buffer = array();
function start_lvl( &$output, $depth = 0, $args = array() ) {
}
function end_lvl( &$output, $depth = 0, $args = array() ) {
}
function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
$this->td_array_buffer[str_repeat(' - ', $depth) . $category->name . ' - [ id: ' . $category->term_id . ' ]' ] = $category->term_id;
}
function end_el( &$output, $page, $depth = 0, $args = array() ) {
}
}
I have checked lot and tried many things, but I am still not getting the product multiselect selected values label on product view page.
I have product attribute called package which is multiselect,
Code that create the product attribute
$this->addAttribute(
'catalog_product',
'package',
array(
'group' => 'Package',
'backend' => 'eav/entity_attribute_backend_array',
'frontend' => '',
'class' => '',
'default' => '',
'label' => 'Package',
'input' => 'multiselect',
'type' => 'text',
'source' => 'npm_recurrex/package_source',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'is_visible' => 1,
'required' => 0,
'searchable' => 0,
'filterable' => 0,
'unique' => 0,
'comparable' => 0,
'visible_on_front' => 0,
'user_defined' => 1,
)
);
this works fine, I am successfully saving the product.
But in frontend product view page when I say
Mage::log(print_r($_product->getData('package'), true));
Its prints the result as 1,2
But I wanted to display option labels of multiselect not option id's.
So I tried with this code
Mage::log(print_r($_product->getAttributeText('package'), true));
It prints nothing, just blank space :(.
I have checked this link but no use.
I am confused with this, Where I am wrong? and what is the wrong thing?
Can anybody explain me what is happening in my case?
If you need to show Drop Down or Multiple select value of an attribute product you should do something like this:
$attributes = $_product->getAttributes();
$customAttributeValue = $attributes['custom_attribute']->getFrontend()->getValue($_product);
Mage::log($customAttributeValue);
I have created an archive page for my 'Event' custom post ape called archive-event.php.
I used the content from the standard archive.php template and it listed my 4 events in the order they were posted.
The next step was to change the order by the custom field event_date. I did this no problems. Then I wanted to not show any events that event_date had passed. The below code does this perfectly.
The issue I now have is my pagination is all messed up. I have the default reading settings set to 2 posts per page and I have a 'Load more' button to bring up the next two.
When I click 'Load more' it duplicates the two events already showing. Any ideas where I've gone wrong?
<?php
$today = date("Ymd");
$args = array (
'post_type' => 'event',
'meta_key' => 'event_date',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'event_date',
'value' => $today,
'type' => 'numeric',
'compare' => '>=',
)
),
);
$wp_query = new WP_Query( $args );
while( $wp_query->have_posts() )
{
$wp_query->the_post();
?>
<div>Content goes here</div>
<?php } wp_reset_postdata(); ?>
Depending on how the plugin builds the UI it may or may not be respecting the pagination functionality built into WordPress.
Try forcing the paged setting into your query like so:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array (
'post_type' => 'event',
'paged' => $paged, // this will be set to what WordPress thinks is the proper page to start
'meta_key' => 'event_date',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'event_date',
'value' => $today,
'type' => 'numeric',
'compare' => '>=',
)
),
);
Next, if this still doesn't work, you can test the assumption that the paged parameter isn't working for some reason by changing the default paged value like so (again, just to test):
$paged = 2; // just force it to start on the second page to see if that works
If the above test works, I would say that get_query_var() believes you're on the first page.
I have a Custom Post Type using the Custom Post Type UI plugin called Case Studies. I'm also using the Custom Fields to add a capability field to the Case Studies.
How can I query Case Studies where the capability is equal to some ID?
$query = array('post_type' => 'case-studies','posts_per_page' => 3);
is my query so far
It could be
$query = array(
'post_type' => 'case-studies',
'meta_key' => 'capability',
'meta_value' => 10, // some ID
'posts_per_page' => 3
);
$the_query = new WP_Query( $query );
while ( $the_query->have_posts() ) : $the_query->the_post();
// echo here
endwhile;
wp_reset_postdata();
You need to set your key to capability, and then query value by your post ID.
'meta_query' => array(
array(
'key' => 'capability',
'value' => $post->ID,
'compare' => 'example'
)
)