3

I am new to stackexchange and 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;  
}
  • One thing that may help with your question is to enclose your code in a code block (the { } button). Also, it probably helps to see the RSS XML output itself. – mradcliffe Apr 16 '16 at 14:12
  • thanks mradcliffe, i have formatted it. Any suggestion why my code is not working? – shuva mallick Apr 16 '16 at 14:19
3

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.

  • Is there no need of adding : to added custom fields ? such as explained here : drupal.org/node/1346506 And are you able to validate your rss feed using validator ? such as validator.w3.org/feed Looking forward to hear from you. Your comments will be helpful. Thanks! – jas May 16 '17 at 11:23
  • I have done similar for me but following this article drupal.org/node/1346506 – jas May 16 '17 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.