I am in need to create wordpress shortcode of portfolio with multiple features for the customers to select and after that i am want to integrate with visual composer.
Thanks in advance.
Though very basic, this is what I've done recently to add a element block to Visual Composer in the form of a shortcode:
<?php
// Shortcode function to insert a 'read more' button in VC
function insert_readmore($atts){
extract(shortcode_atts(array(
'link' => '#',
'text' => 'Read more',
'align' => 'left'
), $atts));
$readmore = "<p>" . $text . "</p>";
return $readmore;
}
function register_shortcodes() {
add_shortcode('btnreadmore', 'insert_readmore');
}
add_action( 'init', 'register_shortcodes');
?>
After this I mapped the shortcode
[btnreadmore link=http://google.com align=right text=More]
in the Visual Composer settings. Once mapped, Visual Compser adds a new tab in the 'add element' screen that you can insert in a Visual Composer column.
Related
I am trying to display a set of custom fields on WooCommerce Vendor pages via Advanced Custom Fields. For the base vendor functionality, I am using the following plugin: https://woocommerce.com/products/product-vendors/
I have added the custom fields under ACF Field Groups and set the display rules to "Taxonomy » Vendors". With this in place, the custom fields are displaying within each individual "Edit Vendor" dashboard.
Within the vendor plugin files I have found where I would like to display the custom fields, which is on line 210 of the file WooCommerce Product Vendors / includes / woocommerce-product-vendors/includes/class-wc-product-vendors-vendor-frontend.php
Initially I tried using the following basic ACF code to display the custom fields, to no avail:
<p id="sample"><?php the_field('field_name'); ?></p>
I have also tried saving the field as a variable and then displaying it, again to no avail:
<?php
$variable = get_field('field_name');
echo '<p>' . $variable . '</p>';
?>
In both of these examples, the <p> wrapping elements are showing up on the front end, but the custom fields/variables are not.
One interesting thing I found is that when I use ACF to create an additional options panel within the WordPress dashboard, I am then easily able to display these variables from the options panel within the vendor pages. Following is the functions.php code I use to create this options panel:
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'Additional Theme Options',
'menu_title' => 'Additional Theme Options',
'menu_slug' => 'additional-Theme-options',
'capability' => 'edit_posts',
'redirect' => false
));
}
And then within the plugin file referenced as above, if I insert the following script it displays the options panel fields perfectly:
<?php the_field('sample_option_field', 'option'); ?>
The problem with the options panel route is that these are then global, singular variables and not registered on a per-vendor basis.
Thanks!
Thanks Fresz, defining the terms worked perfectly. Following is the code I inserted into the plugin file to properly display the custom fields from the Vendor taxonomy:
// get the current taxonomy term
$term = get_queried_object();
// vars
$vendorphoto = get_field('vendor_secondary_photo', $term);
$street = get_field('vendor_street', $term);
$city = get_field('vendor_city', $term);
$state = get_field('vendor_state', $term);
$zip = get_field('vendor_zip', $term);
echo '<img src="'.$vendorphoto.'">';
echo '<p id="sample">'.$street. "<br />" .$city. ", " .$state. " " .$zip.'</p>';
The following works for the Product page but it does not work for the Shop page.
<?php
add_filter('woocommerce_sale_flash', 'woocommerce_custom_sale_text', 10, 3);
function woocommerce_custom_sale_text($text, $post, $_product)
{
return '<span class="onsale">PUT YOUR TEXT</span>';
}
Please suggest modifications.
Thanks!
Use This
add_filter( 'woocommerce_sale_flash', 'wooc_custom_replace_sale_text' );
function wooc_custom_replace_sale_text( $html ) {
return str_replace( __( 'Sale!', 'woocommerce' ), __( 'Your Text', 'woocommerce' ), $html );
}
I tried your code and it works perfectly for the shop page as well. You may try increasing the priority or it can be a conflict with some other plugin or theme.
You may also check the following file to confirm it has applied the woocommerce_sale_flash filter
woocommerce\templates\loop\sale-flash.php
We are using carbon field plugin for custom field in WordPress site but problem is that WordPress is not able to store revision for carbon custom filed. Please any one can help?
There are two way to include carbon field plugin in theme.
1) adding carbon field plugin in plugin folder and activate.
2) adding carbon field plugin folder in theme folder.
/* Integrating Carbon Fields Plugin */
use Carbon_Fields\Container;
use Carbon_Fields\Field;
add_action( 'after_setup_theme', 'crb_setup_theme' );
function crb_setup_theme() {
// check if Carbon Fields is not already installed
if ( ! class_exists( "\\Carbon_Fields\\Field\\Field" ) ) {
require( get_template_directory() . '/carbon-fields/carbon-fields-plugin.php' );
}
}
add_action('carbon_register_fields', 'crb_register_custom_fields');
function crb_register_custom_fields() {
require get_template_directory() . '/theme_option/meta_boxes.php';
}
In meta_boxes.php file you need to create metafield. like this
use Carbon_Fields\Container;
use Carbon_Fields\Field;
Container::make('post_meta', 'Date Container') // New Added
->show_on_post_type(array('hotel')) // Hotel is custom post type
->add_fields(array(
Field::make('complex','hotel_details_page_content', 'Images & Content')
->add_fields('Entry Container', array(
Field::make("separator", "crb_image_options", "Image Entry"),
Field::make("image", "row_images", "Image"),
Field::make("text", "row_image_headlines", "Image Headline"),
Field::make("text", "image_row_subheadlines", "Image Sub Headline"),
Field::make("separator", "crb_style_options", "Content Entry"),
Field::make("text", "content_titles", "Title"),
Field::make("rich_text", "content_datas", "Content"),
)),
));
Container::make('post_meta', 'Gallery Container')
->show_on_post_type('gallery') // Gallery is custom post type
->add_fields(array(
Field::make('complex','galleryimages', 'Gallery')
->add_fields('Gallery Entry', array(
Field::make("image", "gallery_images", "Upload Image"),
))
));
In this way you can create multiple fields as repeater and value also save.
and Get values on frontend.
$carbvalue= carbon_get_post_meta(get_the_ID(), 'hotel_details_page_content', 'complex');
foreach ($carbvalue as $carbonvalues) {
$herorimageid = $carbonvalues['row_images'];
$heroimage = wp_get_attachment_url($herorimageid);
?>
<img src="<?php echo $heroimage; ?>" sizes="100vw" alt="heroimage" />
<?php
echo $carbonvalues['row_image_headlines'];
}
I am using Wordpress and the Genesis framework for a site. I'm using a child theme (Ayoshop - not that it matters much) for the theme. I would like to customize the search results page by removing the 'post info' area where it shows the date, author, and 'leave a comment' link, and instead show the featured image for that post. The theme is using the search.php page from the Genesis theme, so I'm not really sure how to proceed in how to customize it.
Here is the code from the Genesis theme search.php:
add_action( 'genesis_before_loop', 'genesis_do_search_title' );
/**
* Echo the title with the search term.
*
* #since 1.9.0
*/
function genesis_do_search_title() {
$title = sprintf( '<div class="archive-description"><h1 class="archive-title">%s %s</h1></div>', apply_filters( 'genesis_search_title_text', __( 'Search Results for:', 'genesis' ) ), get_search_query() );
echo apply_filters( 'genesis_search_title_output', $title ) . "\n";
}
genesis();
It actually did matter that it was the Ayoshop theme, there was a custom filter that was added in a file called theme-tweaks.php that removed the original post info and added a custom post info, so I needed to remove that custom action.
All of the changes were done in the functions.php file.
I made sure to remove the genesis_post_info, and then removed the custom action that Ayoshop added.
remove_action( 'genesis_before_post_content', 'genesis_post_info' );
remove_action( 'genesis_before_post_content', 'ayo_post_info' );
I then added an action to add the image to the post.
add_action ( 'genesis_before_post_content', 'jl_post_info' );
function jl_post_info()
if ( has_post_thumbnail() ) {
printf( '<div class="post-info">' . get_the_post_thumbnail() . '</div>');
}
}
I'm developing a plugin which has its own table. I need to display the data from the table in the Wordpress frontend (for example: category page). I don't need to JOIN this table with posts table, I just need to display the data from the table, with pagination. I need a separate page/custom template from my plugin directory (talking in a context of MVC frameworks — controller), on which this data should be displayed and paginated.
Please give me an advice, what is the best practice to implement it?
Thanks.
If I understood your question then I think you need to add template_include hook to use Custom template/page from your plugin directory and you can do it like
add_filter('template_include', 'my_template', 1, 1);
function my_template($template) {
global $post;
if($post->post_content == '[myPluginPage]')
return dirname(__FILE__) . '/my_pligin_template.php';
return $template;
}
You should paste the code given above in your plugin file and also create a file in your plugin folder with name my_pligin_template.php or whatever you want but in this case in the first return statement you have to change the file name too.
Now you have to create a page in wordpress admin to show the page in the menu bar and just paste [myPluginPage] as the content. Notice if($post->post_content == '[myPluginPage]'), this will check whether it's your plugin page or not whenever you click on any menu item and if it finds the word [myPluginPage] in the content then it will return the custom template and you will be at that page.
Now you need to fetch your data from database and to do it you should write the code in this custom template file (my_pligin_template.php). To do it you can write
global $wpdb;
$pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
$limit = 10;
$offset = ($pagenum-1) * $limit;
$total = $wpdb->get_var( "SELECT COUNT(*) FROM yourtable" );
$num_of_pages = ceil( $total / $limit );
$qry="select * from yourtable LIMIT $offset, $limit";
$result=$wpdb->get_results($qry);
if($result):
foreach($result as $row)
{
// code here
}
//Link for Pagination
$page_links = paginate_links( array(
'base' => add_query_arg( 'pagenum', '%#%' ),
'format' => '',
'prev_text' => __( '«', 'aag' ),
'next_text' => __( '»', 'aag' ),
'total' => $num_of_pages,
'current' => $pagenum
) );
if ( $page_links ) {
echo '<div class="tablenav"><div class="tablenav-pages" style="margin: 1em 0">' . $page_links . '</div></div>';
}
endif;