Custom Ribbons
This topic contains 9 replies, has 5 voices, and was last updated by Kyle Thomas 8 years, 4 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
June 29, 2016 at 3:28 am #217912
I am posting this here to let other know that i have managed to add custom css Ribbons to my geodirectory website using the select custom field.
Using the selected value from the field, my css generates the matching ribbon.
The process is actually rather simple, but took a while for me to figure it out.I have disabled the New and Featured ribbons and are using my custom ones instead now.
If any one else is interested in doing this, i can post a detailed how to.
Thanks
June 29, 2016 at 3:56 am #217915Hi Kyle,
Thanks for sharing this. It would be better if you could briefly explain what you’ve done to change that as someone might bump into this thread. 🙂
Thanks!
June 29, 2016 at 5:12 am #217979Sure thing, get ready for lengthy post!
This requires some html and css knowledge.The steps I took are as follows:
– Created a ‘select’ field with a few options. E.g.: Special, Limited
– I then opened my ‘listing-listview.php’ template file.
If you are unsure how to edit template files see here: https://wpgeodirectory.com/docs/customizing-geodirectory-templates/– In ‘listing-listview.php’ do the following:
1. Navigate to ‘do_action(‘geodir_after_badge_on_image’, $post); ?>’ underneath is a php tag ‘<?php } ?>’ and under that is a closing div tag ‘</div>’– Between the ‘<?php } ?>’ and </div>’ tag add the following code:
<div class="ribbon"> <span class="<?php echo get_post_field('geodir_variable_name', $post_id); ?>"><?php echo get_post_field('geodir_variable_name', $post_id); ?></span> </div>
Change ‘geodir_variable_name’ with the HTML variable you defined for your select field. Keep in mind that geodirectory field names begin with ‘geodir_’. So for example if your HTML variable name is ‘ribbon_field’ you will put ‘geodir_ribbon_field’.
In the above code we are creating a div with the class of ‘ribbon’, inside that div we have a span whose class is the current value selected from the ‘select’ field. E.g. If the field has the value of Special, then the span class will also be special. This will allow us to target the assigned value and style is as a ribbon.
Inside the span we are also displaying the value of the field as text.Now we need to go into our style sheet and add our styles. My styles are below, but you can change these as you like:
.ribbon { position: absolute; right:-5px; top:-5px; z-index:1; overflow:hidden; width:75px; height:75px; text-align: right; } .ribbon .Limited{ font-size:10px; font-weight:bold; color:#FFF; text-transform:uppercase; text-align: center; line-height:20px; transform:rotate(45deg); -webkit-transform:rotate(45deg); width:100px; display:block; background-color:#d9534f; position:absolute; top:19px; right:-21px; } .ribbon .Limited::before { content:""; position:absolute; left:0px; top:100%; z-index:-1; border-left:3px solid #d43f3a; border-right:3px solid transparent; border-bottom:3px solid transparent; border-top:3px solid #d43f3a; } .ribbon .Limited::after { content:""; position:absolute; right:0px; top:100%; z-index:-1; border-left:3px solid transparent; border-right:3px solid #d43f3a; border-bottom:3px solid transparent; border-top:3px solid #d43f3a; } .ribbon .Special{ font-size:10px; font-weight:bold; color:#FFF; text-transform:uppercase; text-align: center; line-height:20px; transform:rotate(45deg); -webkit-transform:rotate(45deg); width:100px; display:block; background-color:#449450; position:absolute; top:19px; right:-21px; } .ribbon .Special::before { content:""; position:absolute; left:0px; top:100%; z-index:-1; border-left:3px solid #388048; border-right:3px solid transparent; border-bottom:3px solid transparent; border-top:3px solid #388048; } .ribbon .Special::after { content:""; position:absolute; right:0px; top:100%; z-index:-1; border-left:3px solid transparent; border-right:3px solid #388048; border-bottom:3px solid transparent; border-top:3px solid #388048; }
This is a nice chunk of css, but you can chop and change it as you please this is just an example.
Firstly, you can see that I have assigned styles to the div with the class Ribbon. After that you can see styles assigned to .ribbon .Limited and .ribbon .Special. This targets the spans inside the .ribbon class, which reflect values you assigned in your ‘Select’ field, thanks to the code we added in our listing-listview.php template.
The :before and :after class target the corners of the ribbons.For each value inside ‘select’ you create a new css rule targeting that value and simply change the colours.
So if I were a add a new value inside the Select field called Featured and I wanted the ribbon to be blue I would need to add styles for ‘.ribbon .Featured’ as below:
.ribbon .Featured{ font-size:10px; font-weight:bold; color:#FFF; text-transform:uppercase; text-align: center; line-height:20px; transform:rotate(45deg); -webkit-transform:rotate(45deg); width:100px; display:block; background-color:#0000ff; position:absolute; top:19px; right:-21px; } .ribbon .Featured::before { content:""; position:absolute; left:0px; top:100%; z-index:-1; border-left:3px solid #0033cc; border-right:3px solid transparent; border-bottom:3px solid transparent; border-top:3px solid #0033cc; } .ribbon .Featured::after { content:""; position:absolute; right:0px; top:100%; z-index:-1; border-left:3px solid transparent; border-right:3px solid #0033cc; border-bottom:3px solid transparent; border-top:3px solid #0033cc; }
Rounding Up
Just a quick run down of the above:
1. Create a select field and assign the values
2. Edit the listing-listview.php adding the code provided (Changing ‘geodir_variable_name’ with your variable name). No need to remove or change existing code.
3. Add the css inside your stylesheet.
4. Good to go, if you add or change the Select field values simply update the css accordingly.
5. Now when the value on your custom ribbon select field is updated, it will appear as a css ribbon.Quick tip: If you would like a ribbon to appear when a listing is posted, assign the Default value as the ribbon you would like to appear.
There may be another way of doing this, but this seems to work without editing existing code. You can also add background images in your css if you would rather use an image for your ribbon as opposed to purely css.
June 29, 2016 at 5:23 am #218014FYI: The above code will add ribbons to the list view but not the listing detail, I am still working that one out. You may need to edit the css to suit your themes style or layout.
June 29, 2016 at 6:45 am #218028Hi Kyle,
Awesome! Thanks for sharing this. Well, let us know if you need anything further.
Thanks!
June 29, 2016 at 4:57 pm #218344Hi Kyle,
thanks so much for sharing this, would you mind us making a blog post with it? Obviously you’ll get credits for it.
Let us know,
Thanks!
June 29, 2016 at 11:26 pm #218746Sure no problem, if others can benefit from this thats fine by me. Still need to work on getting them on the listing detail page, that will be a bit more complicated
June 30, 2016 at 8:21 am #218832cool, thank you very much. Thumbs up. Love to see more content like this.
June 30, 2016 at 12:42 pm #218950This is great! Would it be possible to put this under a “Tips and Tricks” section or under the Code Snippets part of the Wiki?
There are often very cool things that users come up with that I lose track of but if they were consolidated in one place that would be very helpful.
July 4, 2016 at 11:46 pm #221331Thanks everyone! Good to see positive feedback. A tips and hints section would be good. I have come up with a few little ‘hacks’ I use with this plugin. I would love to see what other users have come up with. If any of you guys have issues with the above feel free to contact me.
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket