Display all custom attributes Woocommerce - woocommerce

I'm working on a project where I want to display product's image and customs attributes from Woocommerce.
I already set attributes like this
I want in my php code display all the attributes (title et terms).
I already try <?php $product->list_attributes(); ?>. It works fine but data are displaying in <table>. I want to customize the display.
Thanks for your help !

Whenever I get stuck with a custom method like this in WooCommerce, I try to resort to the docs to see what is going on.
If you inspect the source for this method, you'll find that it's actually using a custom template single-product/product-attributes.php to output this table you're seeing.
In order to change the output, you have two options:
Override the template via your theme
Observe single-product/product-attributes.php and use the information there to write your own custom loop in your original template.
The second option means that you'll likely use the get_attributes() method, instead of list_attributes().

Related

How to use Wordpress shortcode inside form field value?

I'm attempting to get a shortcode working inside a form field's value="[shortcode]".
This shortcode grabs a URL parameter and prints it. This works everywhere else on the page. It even work in double quotes outside of my form. It also works inside the form as the Submit button text. For some reason, it just won't work within the value="".
This is for an ActiveCampaign form.
Any ideas on how to resolve this? Thanks for your help in advance.
Thanks for the information about using a shortcode outside the content editor. That's useful. The standard Beaver Builder HTML module doesn't accept PHP. I found a plugin called PHP Everywhere that adds the ability to accept PHP anywhere within Wordpress. Using this, I was able to use PHP within the HTML module to use the _GET variable to grab the parameter. Cheers!
Hire one solution. Using dynamic population in Gravity Forms allows you to dynamically populate a field with a value (or values depending on the field type). This value can be passed via Query Strings, Shortcode and/or Hooks. This walk-through will give you an example of how to use each method of dynamic population to dynamically populate a field on your form! https://docs.gravityforms.com/using-dynamic-population/

Drupal page content

I'm new to drupal and reading through docs, but hoping to get an explanation for something.
I have a page called page--type-home-page.tpl.php.
Part of this page prints render($page['content'])). I want to remove something that is rendered as part of the page content from the page, but don't understand where this comes from and where/how to look.
Thanks!
Assuming you're talking about Drupal-7
Well the $page['content'] contains a string, which is a rendered version of what's injected into the content region of your theme.
By default, the only block in this region is the "Main page content" block that is generated by the Drupal core. Many things can generate this content but it always pass through the menu API. For instance, if you're viewing a node, the URL used is: node/12. The node module declares a menu entry for node/%node, this menu entry contains a callback function that will render whatever the module wants to render. The module, then, may use different strategy to render it's content from a simple function to a complex imbrication of templates.
The key to alter what's in the box, sorry, what's in the $page['content'], is to know what is rendered and to understand how it's rendered.
If it's a node, first you want to look if you can achieve your goal through the display settings of the content type. admin/structure/types/manage/page/display: And this is true for all entities (users, comments, taxonomy term etc.) Because this is the first thing the module of these entities will put together when they'll try to render your content.
If this is not enough to achieve your goal, you can look into the module that renders the path to see if it hasn't a .tpl.php. You'll be able to re-use it in your theme. You'll want to copy/paste the file in your theme and edit it.
If the module do not have a tpl file to override, try a template suggestion: here's a list from Drupal.org
Ex: node--type.tpl.php
If all this doesn't satisfy your need, you'll have to dig into preprocess functions; Those functions allow you to modify what's in the variables passed to .tpl.php files. That's a little more advanced and I recommend you to read this previous stackoverflow question/answer
Simply, don't use that $page['content'] which prints all content, but place your custom template code instead and print separate field values where you need them like:
<?php print render($content['your_field_name']); ?>
https://drupal.stackexchange.com/questions/30063/how-to-print-fields-in-node-tpl-php
If you want to do just simple styling, like excluding some field you can use content type display options like mgadrat explained, but if you want to use some complex styling, with totally custom html this solution is easier.

Wordpress: get previous_post_link() based on custom field value

I have a custom post type. Pages of this custom post type are displayed via a special template. in this template i use previous_post_link() and next_post_link() to create links to previous/next posts of this custom post type.
Since I currently only want to show a few of these custom-post-type pages to my users, I created a custom field called release with a boolean true/false value to indicate if these posts should be shown.
Obviously, the previous/next_post_link() functions should also be aware of that. However, they are not currently. That means they also link to pages where the custom field released is set to false. How can I tell these functions to only use pages where a custom field (released) has a specific value (true).
Update: I know that the solution is to apply some filters to the default functions and to somehow adapt the SQL query which is used to retrieve previous/next posts. However I do not know how to put together the puzzle pieces (where/how to apply the filters and how to adapt the SQL)
This may be related to this question, however I dont really know what to do: https://wordpress.stackexchange.com/questions/8823/how-to-order-adjacent-posts-prev-next-by-custom-field-value
This seems also to be related: https://wordpress.stackexchange.com/questions/96670/custom-post-type-navigation-on-custom-field
couldn't get it to work even though I know how it SHOULD work: addFilter() for get_{$adjacent}_post_join and get_{$adjacent}_post_where with custom SQL query code..
However, this plugin did the trick for me: http://www.ambrosite.com/plugins/next-previous-post-link-plus-for-wordpress
I used the in_same_meta key.

Separating Content from Design in Wordpress

I'm not a super-experienced Wordpress guy, but I generally know what I'm doing, and have been programming for years.
I'm in the middle of building a fairly simple Wordpress site, but lots of posts will be added in the future by the client.
It suddenly dawned on me that all my posts are static, so if changes in design are needed they will need to be applied manually across many pages.
I've searched Google but to no avail. What I need is a plugin or method that allows me to have templates for my posts, into which the unique content for each page are added. Then, if design changes are needed, I simply edit the template and the design will change instantly across all the pages using this template.
I've found plugins which seem to offer post templates, but all they seem to do is create a new post with a pre-made design, but do not make it possible to make changes to that design which are reflected across all the posts that use that template. Maybe I'm missing something simple here, as I can't be the only WP author who wants to achieve this?
I'm not talking about dynamic content. ie I have no need to pull constantly updated data like weather or prices from an API. The content is hand-written for each page, but I would like to separate it from the design, so if design changes are needed they can be made only once from some kind of post template manager, and not individually on each page.
Actually, I'm already using the simple post-snippets plugin, and I realise that I could use this or something similar to achieve my aim, but I don't think this would be very user-friendly for non-technical authors. Instead, it would be ideal if I had a set of custom fields under each post which the authors filled in, and the content was then taken from there and inserted in the page's template.
In principle you should be able to change the design just using CSS selectors. Of course that may have its limitations but there is never a design that fits it all.
For bigger changes you will need to change the WordPress template.
Ok, after some research and poking around, this is what I've come up with.
Install the 'Advanced Custom Fields' and 'Custom Post Templates' plugins , although neither are strictly necessary.
Create a group of custom fields which defines the unique data (URL, media selector etc) for each post.
Most importantly, create a new custom post template following the instructions for the 'Custom Post Templates' plugin. In this template remove the line that outputs the post content (the_content()), and replace it with code that outputs all the shortcodes or whatever for this page type, with placeholders string replaced with the values of the custom variables for that post. Then (in my case) I do something like do_shortcode($page_template) to correctly output the correct content for that page.
I create a new post, leaving the content field completely empty, and filling in the custom field's values as required. Also, you must choose the post template, so it matches the new custom template you create.
$v=get_post_custom_values("image_url")[0];//gets the id of the post which contains the image
$image_url = wp_get_attachment_image_src($v, 'medium')[0]; //get the image (URL?) from the reference
$page_template='[one_third last="no" spacing="yes" background_color="" background_image="" background_repeat="no-repeat" background_position="left top" border_size="2px" border_color="#eaeaea" border_style="solid" padding="20px" class="" id=""][imageframe lightbox="no" style_type="none" bordercolor="" bordersize="0px" borderradius="0" stylecolor="" align="none" link="" linktarget="_self" animation_type="0" animation_direction="down" animation_speed="0.1" class="" id=""] <img src="#image_url#" alt="" />[/imageframe][fusion_text]Email Me | Website[/fusion_text][/one_third][two_third last="yes" spacing="yes" background_color="" background_image="" background_repeat="no-repeat" background_position="left top" border_size="0px" border_color="" border_style="" padding="" class="" id=""][fusion_text]#main_text_html#[/fusion_text][/two_third]';
$page_template=str_replace ( "#image_url#" , $image_url , $page_template );
echo do_shortcode($page_template);
The code above contains the page template hard-coded into the $page_template variable, but it could also be loaded by referencing the id of the post which is acting as the template.
This code currently only inserts the correct image URL. Once it's finished it will also insert the personal email link, website link, and main text.

Drupal 7: Add view to content type

I've been making a template for a particular content type, but just ran into a problem: I need to embed a view into the content type.
I am aware this can be done via several different methods, but I don't see one that fits exactly my needs:
I need the view added automatically for all pages of that content type.
Using blocks in a region is not an option, as I want to avoid defining a region in the middle of a page that should only be available for a specific content type.
Translatable label.
Possibility to freely apply a template to all fields in the content type (excluding the embedded view).
I tried doing it via page layout (Panels) and simply adding node content fields and the view to my layout regions, but then I get another problem: I can't style my content fields without doing something that seems a bit over the top:
Currently I have about 20 different content fields in the content type that are wrapped in HTML and styled in my template file. I have a translated label for each of these in the template file. From what I can tell I'd have to add a template for each of the panes containing content fields to add my translated labels and HTML needed to style each field.
I'm not really fond of making 20 templates, 20 theme hook suggestions to get the templates to work and 20 regions in the panel layout just to get a view inserted in the content type.
Am I doing something terribly wrong here? Any suggestions?
You may want to try the Viewfield module or similar modules (search for "view field" or "view reference").
If you are doing something more complex like changing/filtering the view based on some value in your content type, then you may have to use Viewfield module in combination with something else that will help fill in the filter values.
I've never done something like this before so I'm not sure exactly what module combination would work but Rules or Computed Field come to mind as possible helpers.
You have to use "views node field" http://drupal.org/project/viewsnodefield, after installing this module you have to select the "Node content" in the display (like blocks,page). then click the add display. if you want to display the content like this page http://www.richtown.ae/?q=content/arabian-ranches then you have to download the views_galleriffic module and install it and choose the style option "Galleriffic Gallery". You can choose the content type by using the filter in the views.
That's it cheers
i implemented this in my website richtown.ae
if you still unclear please send me the email social#richtown.ae i will reply you & ready to help you we can share information
i am using this module in drupal 6.
I resorted to using the EVA module ( http://drupal.org/project/eva ).
In addition to Woodgnome's answer
Let's say you have a content type named 'Product'
You want to attach a view to it.
Here are the steps using the eva module :
On your view edit page :
Section Displays
+Add : Eva field
Section ENTITY CONTENT SETTINGS
Entity type:Node
Bundles:Product
That's it, going to a node product type will now display the view

Resources