RSS item elements not being not being read by XML Reader - drupal

I don't know if i am asking this correctly but plz help me.
I am using Drupal Views to display RSS for my site. I am using the 'Views RSS: Core Elements' module to map the RSS fields with the custom fields added by me in the views. All works well. But a requirement forces me to add custom item elements in the RSS display. I am implementing the hook_views_rss_item_elements() to add custom item elements. When i view the RSS page i get the see the custom items but when i try to read the RSS using a RSS reader, the items are not being read. What am i doing wrong, or am i missing something?
Here is my code to add custom items to the 'SHOW ITEM ELEMENTS : CORE' for RSS display:
function Mymodule_views_rss_item_elements() {
$elements['blogs_title_image'] = array ( 'title' => t('Blogs Title Image'), 'description' => t('Blogs Title Image'), );
$elements['blogs_additional_tags'] = array ( 'title' => t('Blogs Additional Tags'), 'description' => t('Blogs Additional Tags'), );
$elements['blogs_short_desc'] = array ( 'title' => t('Blogs Short Description'), 'description' => t('Blogs Short Description'), );
return $elements;
}

After some research i did manage to find my way out:
I implemented hook_views_rss_namespaces to add a custom namespace and the custom items under the namespace:
function Mymodule_views_rss_namespaces() {
$namespaces['blogs'] = array(
'prefix' => 'xmlns',
'uri' => 'http://base.google.com/ns/1.0',
);
return $namespaces;
}
Note: Use the same 'prefix' and 'uri' as given in the above code or else namespace uri error will arise.

Related

Adding the Classic Editor to a Gutenberg Block Template

NOTE: Here is a video that helps explain my question: https://drive.google.com/file/d/1c3pS-j8yq75GAwGDrrMMh9X7fDrCKV5R/view?pli=1
I am creating a custom post type that includes a set of blocks as a template. My basic code looks like this:
function register_article_post_type(){
$post_settings = array(
'label' => 'Articles',
'public' => true,
'show_in_rest' => true,
'template_lock' => 'all',
'template' => array(
array( 'core/heading',
array(
'placeholder' => 'Add Categories Heading...',
'className' => 'tour_categories_heading'
)
),
)
);
register_post_type('article', $post_settings);
}
That will create a Custom Post Type called Articles which has a singular Heading block. The thing is, I don't want a heading block, I want the Classic Editor block.
But I can't figure out how to add it. I can easily change the Heading block to a different block (say the paragraph block) if I change array( 'core/heading', to array( 'core/paragraph',.
But when I check the code in Gutenberg for the name of the Classic editor, nothing shows up. As such, I cannot figure out how to add a Classic editor to the custom post type.
Any ideas.
Try core/freeform - should be the slug for the classic editor block

Output a "advanced-custom-fields"-field programmatically in wordpress backend

I created a custom field with the "advanced-custom-fields"-plugin. Now I want to get and output the custom field programmatically in my template file (backend, edit page), because my template is called via ajax if user want's to add a new region to the page.
Is there any function which returns the complete field? I only found functions which gave me values, but not the field as "form".
I found a solution. I duplicated the plugin folder into my theme root directory and put the following code into my functions.php:
function relationshipField() {
$newField = new acf_field_relationship();
$field = array(
'post_type' => array('post'),
'max' => '',
'taxonomy' => array('all'),
'filters' => array('search'),
'result_elements' => array('post_title', 'post_type'),
'return_format' => 'object'
);
return $newField->create_field($field);
}
In addition I append a custom input field (created in function.php) which stores only the post id's in database.

Create content types on the fly in Drupal

One of our website requirements is to have a content type that let's you decide on the total amount of content types on the fly.
For instance, if I specify a number 10, then it ought to generate the content types consecutively, one of type 'textarea' and another of type 'radio' are created 10 times.
essentially to break it programmatically, it will create:
<?php
for(i=0;i<10;i++)
{
echo "<input type = 'textarea'></input>";
echo "<select><option>1</option><option>2</option></select>";
}
?>
This is pretty straightforward if I was dabbling with simple PHP files, but with Drupal 7's content types (CCK), it is posing a bigger challenge than what it ought to be IMHO. I have tried exploring modules that let you create content types on the fly and considered creating a custom content type programmatically which seems like another challenge altogether.
I am curious if anybody has an alternative for this and has dabbled with this challenge before. Your answers are most appreciated.
Thanks guys
To create content dynamic types in drupal 7 you will need to follow the below process:
Updated *
1) Create a menu path using hook_menu() which uses drupal_get_form(). This will allow you to gather all data for your users input for the dynamic content creation.
Example:
$items['newpost'] = array(
'title' => 'Create Post',
'description' => 'The main noticeboard',
'page callback' => 'drupal_get_form',
'page arguments' => array('customvishal_create_content'),
'access callback' => TRUE,
);
return $items;
2) Then use:
function customvishal_create_content($form, &$form_submit) // To create your form on that page
function customvishal_create_content_validate($form, &$form_state) // for any kind of validation
function customvishal_create_content_submit($form, &$form_state)
In this function you can submit the values into your new content type.
Here is where you will call the below functions.
3) Create an array which will hold the meta data about your content type.
// Define the node type.
$mystuff = array(
'type' => 'mystuff',
'name' => $t('my new Stuff'),
'base' => 'node_content',
'description' => $t('This is an example node type.'),
'body_label' => $t('Content')
);
// Set defaults.
$content_type = node_type_set_defaults($mystuff);
4) use node_type_save() to save/declare your content type.
node_type_save($content_type);
5) Create fields and then attach to your content type.
foreach (_mystuff_installed_fields() as $field) {
field_create_field($field);
}
// Create instances of fields.
foreach (_mystuff_installed_instances() as $instance) {
$instance['entity_type'] = 'node';
$instance['bundle'] = $mystuff['type'];
field_create_instance($instance);
}

Wordpress: How to integrate the media uploader with a custom meta box field?

I'm writing a plugin which creates a custom post_type called "dictionary_entry" which has several custom meta boxes and fields. I'd like to add an addition field which allows the custom post author to upload an audio clip.
I've done some digging and tried the code offered here but I can't get it to work.
I think one possible answer to my question would be the "type" parameter for fields. I've seen "text", "textarea", "time", "color", "radio", etc. but I haven't been able to find a list of all the possibilities. Is it wishful thinking that there might be a field type: "file" or "upload"?
I'm going to skip the code for adding the custom post_type, but here's an example of my code for adding the meta boxes (in case somebody else is trying to use this, remember to use your custom post_type in the 'pages' parameter):
//meta box code
$meta_boxes = array();
$meta_boxes[] = array(
'id' => 'examples', // meta box id, unique per meta box
'title' => 'Examples', // meta box title
'pages' => array('dictionary_entry'), // post types, accept custom post types as well, default is array('post'); optional
'context' => 'normal', // where the meta box appear: normal (default), advanced, side; optional
'priority' => 'high', // order of meta box: high (default), low; optional
'fields' => array( // list of meta fields
array(
'name' => 'Example 1', // field name
'desc' => 'Use it in a sentence? EX: Kanien\'kéha kahrónkha.', // field description, optional
'id' => $prefix . 'example1', // field id, i.e. the meta key
'type' => 'text', // text box
'std' => '', // default value, optional
'validate_func' => 'check_apos' // validate function, created below, inside RW_Meta_Box_Validate class
),
array(
'name' => 'Translation 1', // field name
'desc' => 'What does the sentence mean? EX: I speak Mohawk.', // field description, optional
'id' => $prefix . 'ex_translation1', // field id, i.e. the meta key
'type' => 'text', // text box
'std' => '', // default value, optional
'validate_func' => 'check_apos' // validate function, created below, inside RW_Meta_Box_Validate class
)
)
);
foreach ($meta_boxes as $metabox) {
add_meta_box... //see the codex for add_meta_box()
}
I figured out how to do this by digging into the code found here. If you take a look, you'll recognize parts of my code quoted above. I was originally using this class, but didn't fully realize it. It's a custom class which can be called to add various meta boxes / fields.
It turns out that the "type" parameter I was wondering about actually belongs to this Class (as opposed to the Wordpress API) and that it does allow for a type: 'file' which brings up a default file picker window (not the built-in media uploader). For my purposes this is okay, because I don't need all the slick options.
If you're reading this, you've probably already googled this question and seen a wide variety of posts that partially explain how to do this. For what it's worth, I found this to be the easiest way to add this functionality that ALSO works for custom post_types (without a fair amount of hacking). I hope this is useful to someone else.

Use node-menu on page

I would like to use the node-menu (see image) on a page in Drupal.
Is this possible and, if yes, how?
If the page you are referring is a custom page output from your module, and "mymodule/page" is the path for that page, for which you want the tabs "View" and "Edit," then you should implement hook_menu() using code similar to the following one:
function mymodule_menu() {
$items = array();
$items['mymodule/page'] = array(
'page callback' => 'mymodule_page_view',
'access arguments' => array('view mymodule page'),
);
$items['mymodule/page/view'] = array(
'title' => 'View',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['mymodule/page/edit'] = array(
'title' => 'Edit',
'page callback' => 'mymodule_page_edit',
'access arguments' => array('edit mymodule page'),
'weight' => 0,
'type' => MENU_LOCAL_TASK,
);
return $items;
}
If the page you are referring is a page that is shown at example.com/mymodule/page, and that should show what you see at example.com/node/7, then you can implement the following code, in Drupal 7:
function mymodule_url_inbound_alter(&$path, $original_path, $path_language) {
if (preg_match('|^mymodule/page|', $path)) {
$path = 'node/7';
}
}
The equivalent for Drupal 6 is writing the following code in the settings.php file:
function custom_url_rewrite_inbound(&$result, $path, $path_language) {
if (preg_match('|^mymodule/page|', $path)) {
$result = 'node/7';
}
}
I didn't write the symmetric code for hook_url_outbound_alter(), and custom_url_rewrite_outbound() as I suppose you are not interested in rewriting example.com/node/7 to make it appear as example.com/mymodule/page, but you are interested in making appear example.com/mymodule/page the same as example.com/node/7.
Okay; a node page usually has those View and Edit tabs. So my next question is to wonder why they aren't appearing on your node page already. Have you by chance created a custom page template for this node type and removed the code that prints the tabs? Or is there a chance you're logged in as a user that doesn't have permission to edit this type of node?
There must be a reason why you're not getting those tabs; they should be there, by default.
If you do have a custom page template for this node type, look for code that looks something like this:
<?php if ($tabs): ?>
<div class="tabs"><?php print $tabs; ?></div>
<?php endif; ?>
If you don't see code like that, try adding it.
If you DO see code like that, try to isolate what's different about this content type compared to other content types where you DO see those tabs.

Resources