Pushing custom field data to an array within a plugin - php

Good Morning
I not very proficient in PHP, on a plugin I am using for car listings there is 'car data' which is filled in while adding a car, I want to add a new option and entry field. I have used a separate plugin to add a custom field to the vehicle listing post type, the problem is outputting the value to the post page.
Within the car listing plugin I found the below php file
https://github.com/barrykooij/wp-car-manager/blob/master/src/Vehicle/Data.php
I added another entry to the array directly and it displayed in the place I want, the questions I have are;
Can I write a function in functions.php to append something to this array?
How would I specify for the values used to be that of my custom field?
Maybe I am barking completely up the wrong tree here but some advice would be appreciated.
Thanks

Related

How can I retrieve values of Custom Field Suite plugin nested loop one by one?

I used Custom Field Suite to make a custom field using it's loop function and cannot get around retrieving the values one by one. The structure of the custom field is somewhat like this:
I'm just an amateur with regards to php so I haven't tried anything but scour the web for possible answer, but CFS has so little documentation on the web.
https://gyazo.com/6929bd0063d8a6ad0bd3881a368579d7
I would want to retrieve each post content on different parts of my php file. For example;post-content0 on top of the page and post-content5 on the last part of the page.

Display custom field tabs in front end article edit page in Joomla 3.x

I have been looking for a solution to display custom field tabs in the Joomla
front article edit page.
http://www.aixeena.org/extensions/aixeena-easy-cck
Aixeena Easy CCK
I installed the plugin of aixeena, two custom field tabs: the Extra content and Extra content 2 are displayed in the backend admin article edit page, which is great. But we also need to let regular edit their article and enter values in custom fields under those two tabs. Any idea how to achieve this?
I tried a couple of other sites posting the solution of adding custom fields in article, such as Rating region described in the site:
https://docs.joomla.org/Adding_custom_fields_to_the_article_component
I was not able to make the Rating tab displayed in the front end article edit page neither.
I tried the fieldattach, it does supports custom field tab ( which is the group name of custom field), the list field type only contains static values, we have to define fieldset and field type through xml file.
Any help is greatly appreciated.
I just finished writing a couple pluginsto do this similar thing. I wrote my own plugin to add the extra fields - but it looks like the one you've already used is very similar.
I had a really hard time figuring out how to add the fields for frontend editing as well. But I finally figured it out.
First, you're going to need to copy the com_content form edit.php into a template override (/templates/your_template_name/html/com_content/form/edit.php).
In that file, add the extra fields you have. You'll need the name of the field that you put in the xml file for your plugin you already have. Add them right before/after the fields that are already in the file, that you want your fields to appear before/after. Example:
<!-- CUSTOM begin custom fields -->
<?php echo $this->form->renderField('video_url', 'attribs'); ?>
add all your fields in there - replacing 'video_url' with your own field name. The plugin you already have already saved these fields to the 'attribs' part of the article, so you can leave that there.
The plugin that I used to create the fields for the backend is a really simple one based off of this tutorial https://zunostudios.com/blog/development/203-how-to-add-custom-fields-to-articles-in-joomla
What I'd suggest is to go ahead and create that plugin too. Except in the zfields.php file, change "$app->isAdmin()" to "$app->isSite()" - make sure the xml files have the same names as your other plugin xml files, so they save to the same place, and you're done. The fields will show up on the frontend edit form now.
What I'd really recommend is to get rid of the Aixeena plugin, and just make that easy plugin using the tutorial above - it's super easy. When you make it, duplicate the "if ($app->isAdmin())" section, copy it right below it, and change "isAdmin" to "isSite" - and now you've got the entire thing, all your custom fields, both frontend and backend, all in one place. Now just do the edit.php template override, and you'll have them displayed in both the front and backend. I hope that helps - if you need I can upload more example code.

Modify how Drupal builds fields on a per form basis

I want to change the way Drupal builds specific fields on a specific node edit/add form on my site. For example, when I use print drupal_render($form['textarea']); in my node--CONTENTTYPE--form.tpl.php file, I get the default Drupal render of the field widget. I want to modify the HTML markup of the field widget.
There are three ways I can think of that might solve this problem:
Using a forms equivalent of the theme_field() hook. This seems ideal, but after searching for the last few hours, I haven't found anything on this.
Building custom field widgets for every field type I'm using on that node. This is definitely not ideal and I have to believe there's an easy way to do this in Drupal from a theme point of view.
Manually build the HTML markup for the form and field in node--CONTENTTYPE--form.tpl.php with print $form['textarea']['und'][0]['title']; and the like.
Is there a hook in Drupal to do this, or must the code for every field I want to modify be manually generated?
I think the hooks you are looking for are hook_form_alter and hook_form_BASE_FORM_ID_alter. Refer to the Form API to know what you can set on the render array.

Joomla K2 - Displaying an item's extra field data elsewhere on the site

i'm building a website for a house builder and each house plot (k2 item) has a few extra fields associated with it such as 'price' and 'availability'.
i would like to display this extra field data elsewhere on the site perhaps in a table that lists 5-6 plots and displays their current price and availability.
the idea is to be able to change the price of a house in the extra fields section and then have this change reflected in other parts of the site that call on this extra field data.
i've read this article..
http://jurawa.com/notes/item/27-update-making-k2-more-like-a-true-cck-custom-admin-templates-and-calling-specific-extra-field-data
..which explains a process of displaying extra field data but i've not managed to get this to work. i also think that this method would only work if displaying extra field data while already inside the item that it relates to. i'm trying to display this extra field data around other parts of the site.
i'm trying to replicate something like the table that appears on this page (just above the map)
http://www.orionhomes.co.uk/development/brunswick-place
running the latest version of jooma and k2 and have full access to server and database.
hope someone can help..!
many thanks
I have used the Raxo All-In-One module to accomplish this in the past:
http://www.raxo.org/raxo-all-mode-k2.html
This, along with ability to insert a module in an article, would allow you to place the specific K2 content/fields wherever you need them and have them updated dynamically by K2.
Another option would be to create a new template for K2 and only output the extra fields in your item list. This would allow you to create the table view you are looking for.
There is a great plug-in for Joomla/K2 that does this for you at:
http://joomcar.net
It's called K2 Filter and Search Module and it will display a table with the extra fields as you have demonstrated in at:
http://www.orionhomes.co.uk/development/brunswick-place
You can definitely display those extra fields wherever you need them on the site.
This step-by-step tutorial may help you to create the extra fields.
Then you just need to enable the extra fields in your view and modify your template.

How to place multiple content types on a Drupal page?

I've created a new content type called Homepage, which has a number of fields. The fields are node references to the Single Image Promo content type. Single Promo Box has fields for title, text and image. The idea is that I can create multiple copies of a Single Promo Box, each with different field values. I then want to place a few of them on the homepage.
So I can place a specific Single Image Promo on the homepage fine now. But what template file do I need to create to style the way Single Image Promo is shown when it's a node reference on the homepage?
Thanks,
Maria
It sounds like you are over complicating things.
If you want to create some different boxes on your homepage, using node reference is not the right way to go about this. There are some few different ways to do what you want, the easiest i probably to create a block view of the node you want to display. When you turn a node into a block, you get the ability to place it in any of your theme's defined regions.
You could also just create a view and from there get the different Single Image Promo you want without using node reference at all. Views has a lot of different filters, which will enable to you create a view that always displays the right nodes. This solution wont work well, if you want to place the nodes in different regions though.
To answer your question, when nodes are being displayed, they will by default be rendered with the node.tpl.php template file. To make specific templates for each of your node types, you can create a new template named node-nodetype.tpl.php, where nodetype is what you called the node type when you created it.
node-nodetype.tpl.php can work to a certain degree, but in that file you are styling the entire page, with the content type's fields delivered wholesale to the tpl via a single $content variable. Maybe it is enough for you, but if you need finer grained control:
You can edit and style the individual content type's fields with the Content Template (contemplate) module. It provides access to all of a content type's fields within the $content variable (which is delivered wholesale to the node-nodetype.tpl.php. The contemplate is php, so you can add logic and conditional formatting for the node-reference fields (usually clearly labeled in the contemplate).
And don't overlook the simple solution of the content type's 'display fields' tab (next to manage fields tab), where you can control some field outputs right out of the gate.

Categories