I don't seem to be able to find any information on whether this is possible. Instead of a piece of text as an attribute I would like to display a tick symbol.
i.e. My attribute is called Vegetarian the value is "yes". Instead of displaying the word "yes" I would like to display a tick symbol.
Does anyone know where I could make an edit to achieve this?
Ok, I've found the file that needs to be edited to achieve this. You need to make a copy and save it to your template in /single-product/product-attributes.php
After the foreach loop paste:
<?php global $product;
$vegetarian = $product->get_attribute( 'vegetarian' ); ?>
<?php if($vegetarian){
echo '<li>Vegetarian <i class="fa fa-check-square-o"></i></li>';
}?>
Then make sure that the Vegetarian attribute is not "Visible on the product page" by unchecking that box in the product options in admin. Now it will appear with a tick at the end of the attribute list.
i.e.
Attribute: attribute value
Attribute: attribute value
Vegetarian: <i class="fa fa-check-square-o">
Related
The only way to set a category to a new post seems to be to select the appropriate one via a check-box before submitting it.
At best, you can set a default category as an option in case no box has been checked by the user.
This is really a problem for me as my admin menus are and have to be the categories themselves.
As I mentioned, in my WordPress admin I have a custom menu listing category names. Clicking on one leads directly to the generic "add a new post" page.
What makes it less generic is that I have inserted the category ID within this link, like this: "wp-admin/post-new.php?cat=5".
At this point,I would like not to check a category from a box before submitting the new post. Instead, I want WordPress to use the variable provided in the URL and submit the category ID accordingly when my new post is ready to be published.
Is it possible?
Which file would I have to edit in order to achieve this?
Any other idea that would lead to the same result?
You can use an extension that you will develop. It is better than trying to modify Wordpress core files.
I did something that may help you in one of mine. Using this :
if(is_admin()){
add_action('post_submitbox_misc_actions', 'plugin_add_custom_box');
}
function plugin_add_custom_box(){
?>
<div class="al2fb_post_submit">
<div class="misc-pub-section">
<?php
echo '<input type="checkbox" id="plugin" name="plugin_action" value="1"/>';
echo '<label for="plugin">';
_e("Label", 'myplugin_textdomain');
echo '</label> ';
?>
</div>
</div>
<?php
}
This add a custom checkbox. Using the same name for the checkbox here than checkboxes already displayed by Wordpress and checking it analysing your URL, you will probably be able to store the category you want without modifying core files.
This sounds simple, but I just can't get it...
I need to display a simple drop down list of the last 10 nodes of type X. I can't seem to be able to create it with a simple view, it only lets me create static lists of nodes, and not drop down lists.
Thank you.
Ok first create a simple view with Row Style as fields and Style as unformatted. Use node title as a field and make sure HTML tags are stripped out. This should give you a list of node titles in plain text. These will be used as the options for the HTML select element.
Next we need to create a template to theme the output. You can do this by overriding the default view templates.
Click Information next to Theme: to show your template options. You want to theme the whole result set so we need to override the Style output (unformatted template). Next to style output is a list of template suggestions for this example I chose:
views-view-unformatted--drop-down-test.tpl.php
choose the suggestion after the bold one (this applies to all displays).
put this in the file:
`
<select>
<?php foreach ($rows as $id => $row): ?>
<option value="<?php print $id; ?>">
<?php print $row; ?>
</option>
<?php endforeach; ?>
</select>
`
Stick the file in your theme folder and click rescan template files and your template should get picked up and appear bold in the views interface.
Hit preview and now your results with be in a glorious drop down.
I have a Text Field added to a Content Type and I want to add a PayPal button in this field.
When I display the page, it shows the HTML in its entirety... rather than just the button.
Anyone know a work around or an override for this formatting?
Thx in advance :)
You need to create a template file and rewrite the html and php. For example the file will be called field--field_pay_pal.tpl.php (or whatever the machine name is) and and you will access the value using the $label value. It may be in an associative array so to check the value use the dpm($label) to get the values. Here is some more information below on the reference
http://api.drupal.org/api/drupal/modules!field!theme!field.tpl.php/7
An example would be
<img src="<?php print $label[0][value]; ?>" />
I'm trying to make my single.php page show more details about each project/item in a portfolio, with multiple larger image files that will display with captions to the right of the project description.
I'm thinking the best way to approach this would be to use the 'featured image' for the thumbnail display on the homepage which seems to be working now, but I've been trying to figure out Custom Fields to use for my other images (image1, image2, image3). I can't figure it out.
I go to "Enter new" under Custom Fields from the admin screen, enter image1 for the name. What goes in the Value field? How do I get it to work? I know I need to add some code to my single.php page... but what? And when/where do I upload the images themselves?
Any help would be greatly appreciated! I'm a little dense in the PHP department...
Have look at your single.php file. You will find the following lines, one near the top, the other lower down.
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
...
...
<?php endwhile; // end of the loop. ?>
Anything between these two lines will be applied over and over, once per blog post that happens to be displayed by that template file. So you should put your magic between those lines.
What you put there will be a mix of HTML and PHP. For instance, you might use this line:
<img src="<?php echo get_post_meta($post->ID, 'image1', true) ?>"/>
which combines
<img src=""/>
with
<?php echo get_post_meta($post->ID, 'image1', true) ?>
The PHP line looks up whatever value you have entered for the custom field named 'image1'. If you look at the HTML I used, you will see that this value is being placed inside the 'src' attribute. In other words, the value associated with 'image1' should be the url of that image.
You can expand upon this basic idea, but that's where your own creativity will have to come in.
[Is this not a repeated question?]
I have a simple view that grabs 4 fields, basically it grabs the fields of a specific content type. The fields are as follows:
CSS class (plain text)
Image (image)
Title
Body
Pretty simple stuff. I've got the view created, but I need to output things in a specialized way and I can't determine how this stuff breaks down in conjunction with my custom markup from my build. I need to wrap each row in a container and each row breaks down into it's own containers, take a look at the following code.
<div id="homepage-folio-portlets">
<div class="homepage-folio-portlet [CSS class]">
<div class="homepage-folio-portlet-image"><img src="[Image]" width="450" height="330" alt="" class="[CSS class]-image" /></div>
<div class="homepage-folio-portlet-text">
<strong>[Title]</strong>
<p>[Body]</p>
</div>
</div> <!-- /homepage-folio-portlet -->
</div> <!-- /homepage-folio-portlets -->
So I've got a container, homepage-folio-portlets, and inside of that I want to iterate over views creating a new container using the class homepage-folio-portlet for each row returned including the CSS class from the row.
My biggest hurdle is figuring out how to build either my .tpl files or my theme functions in template.php. I understand the naming conventions, but once inside I don't really know what to do. I have a feeling I'll need to do a little magic in template.php either way to make sure that my row output is aware of the CSS class from the content, but who knows. Any help and direction is appreciated.
After watching the aforementioned video it became a little more clear how to accomplish what I set out to do. The biggest "ah-ha" was that the default code for the "Row style output" template was confusing to me because of the foreach loop. I didn't recognize that I could simply output each field in whatever way I see fit in this file without the loop. The video showed how you could reference your fields individually with the following shorthand $fields['ID-of-field']->content. To get the 'ID-of-field' it's as scrolling past the "Display output", "Style output", and "Row style output" links in the "Theming information" option pane of your specific view.
I used the "Theme information" found in the edit screen of my view to determine the most specific .tpl for "Row style output" to create and created it, in this case view-view-fields--my-view-name--default.tpl.php.
view-view-fields--my-view-name--default.tpl.php - Row output .tpl file
(No longer making use of the default foreach because instead of looping over the fields I know the fields I want and I can simply output them anyway I see fit)
<div id="homepage-folio-portlets">
<div class="homepage-folio-portlet <?php print $fields['CSS_class']->content ?>">
<div class="homepage-folio-portlet-image"><img src="<?php print $fields['Image']->content ?>" width="450" height="330" alt="" class="<?php print $fields['CSS_class']->content ?>-image" /></div>
<div class="homepage-folio-portlet-text">
<strong><?php print $fields['Title']->content ?></strong>
<p><?php print $fields['Body']->content ?></p>
</div>
</div> <!-- /homepage-folio-portlet -->
</div> <!-- /homepage-folio-portlets -->
After that, I did a little recursion into the "Style output" and "Display output" .tpl files to get rid of all that extra markup Drupal adds. Note that all I really cared about was printing out $row (with it's foreach loop) in style .tpl and $rows in the display tpl. It's outputting EXACTLY what I want and I couldn't be happier. Finally, it's making some sense. Hopefully this helps a bunch of other people.
Just for reference...
views-view-unformatted--my-view-name--default.tpl.php - Style .tpl file
(Want to keep the foreach loop in here so each row gets outputted)
<?php foreach ($rows as $id => $row): ?>
<?php print $row; ?>
<?php endforeach; ?>
views-view--my-view-name--default.tpl.php - Display .tpl file
<?php print $rows; ?>
By removing all the extra markup I am losing important stuff specific to views like admin links and such, but for my purposes that's fine.
On the Edit tab for your view, under Basic Settings, look for "Theme:" and click on the "Information" link. Then in the "Default: Theming information" section, the bold filenames are the ones currently being used to theme a particular sub-section of that view. The other names are "suggestions" that can be used to override the defaults and they are ordered from least specific to most specific.
In your case, to start, it sounds like you want to override the "Row style output":
Click on the "Row style output" link, copy the default template code.
Choose one of the suggested filenames to use for the row style, based on whether you want this style to be used for all views, this view, a particular display of this view, etc.
Paste the code copied in Step #1 into the filename chosen in Step #2
Edit the code as necessary, to add the specific classes
Click on the "Rescan template files" to rebuild the template cache
Repeat steps 1-5 for any additional sub-templates you want to customize.
Have you tried using the template files for rows? You should see it in the views module (in the admin). By clicking on "Information" in the lower box on the left side when you are creating the view. You will need to refresh the template cache (you will see a button to do this).