Below, you’ll find a detailed guide on how to add the WP Links Page Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the WP Links Page Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the WP Links Page Plugin and the shortcodes it provides:
WP Links Page [wp_links_page] Shortcode
The wp_links_page shortcode is a versatile tool within the WP Links Page plugin. It generates a grid or list display of links, complete with images, titles, and descriptions. It offers customization options, like setting the display type, column count, order, and image size. It also allows for specific styling of images, titles, and descriptions. The shortcode is robust, providing a dynamic way to showcase links on your WordPress site.
Shortcode: [wp_links_page]
Parameters
Here is a list of all possible wp_links_page shortcode parameters and attributes:
ids
– Specifies the IDs of the posts to be displayed.type
– Defines the type of posts to be displayed.display
– Sets the display style for the posts (default is ‘grid’).cols
– Determines the number of columns in the grid layout.order
– Sets the order of posts (default is ‘DESC’).orderby
– Defines how the posts should be ordered (default is by ‘ID’).sort
– Specifies the sorting method for the posts.img_size
– Sets the size of the images in the posts.img_style
– Defines the CSS style for the images.title_style
– Determines the CSS style for the post titles.desc
– Defines whether the post description should be displayed.description
– Specifies the description text for the posts.description_link
– Determines whether the description should be linked.desc_style
– Sets the CSS style for the post description.
Examples and Usage
Basic example – A simple shortcode usage to display the links in grid format.
[wp_links_page display='grid' /]
Advanced examples
Displaying the links in list format, ordered by their ID in ascending order and with the image size set to ‘thumbnail’.
[wp_links_page display='list' order='ASC' orderby='ID' img_size='thumbnail' /]
Displaying the links in grid format with 4 columns, ordered by their title in descending order, and the description is set to ‘yes’.
[wp_links_page display='grid' cols='4' order='DESC' orderby='title' description='yes' /]
Displaying specific links by their IDs in list format, ordered by their ID in ascending order, with the image size set to ‘thumbnail’, and the description link set to ‘no’.
[wp_links_page ids='1,2,3' display='list' order='ASC' orderby='ID' img_size='thumbnail' description_link='no' /]
PHP Function Code
In case you have difficulties debugging what causing issues with [wp_links_page]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('wp_links_page', 'wplf_shortcode');
Shortcode PHP function:
function wplf_shortcode($atts){
if (get_option('wplp_grid') != false) {
$dis = get_option('wplf_grid');
} else { $dis = 'grid'; }
if (get_option('wplp_width') != false) {
$col = get_option('wplf_width');
} else { $col = '3'; }
if (get_option('wplpf_grid') != false) {
$dis = get_option('wplff_grid');
} else { $dis = 'grid'; }
if (get_option('wplpf_width') != false) {
$col = get_option('wplff_width');
} else { $col = '3'; }
$vars = shortcode_atts( array(
'ids' => '',
'type' => '',
'display' => 'grid',
'cols' => '3',
'order' => 'DESC',
'orderby' => 'ID',
'sort' => '',
'img_size' => 'medium',
'img_style' => '',
'title_style' => '',
'desc' => '',
'description' => '',
'description_link' => 'yes',
'desc_style' => '',
), $atts );
$default_num_posts = get_option( 'posts_per_page' );
$display = esc_attr($vars['display']);
$type = esc_attr($vars['type']);
if ($type != '' && $display == 'grid') {
$display = $type;
}
$cols = esc_attr($vars['cols']);
$order = esc_attr($vars['order']);
$meta = '';
$orderby = esc_attr($vars['orderby']);
$sort = esc_attr($vars['sort']);
if ($sort == 'random' && $orderby == 'ID') {
$oderby = 'rand';
}
if ($orderby == 'title') {
$orderby = 'meta_value';
$meta = 'wplp_display';
}
$img_size = esc_attr($vars['img_size']);
$img_style = esc_attr($vars['img_style']);
$title_style = esc_attr($vars['title_style']);
$desc = esc_attr($vars['desc']);
$description = esc_attr($vars['description']);
if ($description == 'yes' && $desc == '') {
$desc = 'content';
}
$description_link = esc_attr($vars['description_link']);
$desc_style = esc_attr($vars['desc_style']);
$ids = esc_attr($vars['ids']);
wp_enqueue_style('wplf-display-style');
wp_enqueue_script('wplf-display-js');
global $wpdb;
$grid = '';
$list = '';
$gallery = '';
$i = 0;
$query_args = array('post_type' => 'wplp_link', 'order' => $order, 'posts_per_page' => '-1', 'orderby' => $orderby, 'meta_key' => 'wplp_display', 'metakey' => $meta, 'post_status' => 'publish');
if ($ids != '') {
$idarr = explode(',', $ids);
$query_args['post__in'] = $idarr;
}
remove_all_filters('posts_orderby');
$custom_query = new WP_Query( $query_args );
//print('<pre>'.print_r($custom_query,true).'</pre>');
while($custom_query->have_posts()) : $custom_query->the_post();
$post_id = get_the_ID();
$mk = wplf_filter_metadata( get_post_meta( $post_id ) );
if (isset($mk['wplp_display'])) {$mdisp = $mk['wplp_display'];} else {$mdisp = '';}
$url = the_title("","",false);
// Image
$thumb = get_post_thumbnail_id($post_id);
$img = wp_get_attachment_image($thumb, $img_size, false, array('style' => $img_style));
// Title
$title_display = $mdisp;
// Description
$description = '';
if ($desc == 'content') {
$description = apply_filters('the_content',get_the_content());
$description = '<p class="wplf_desc" style="'.$desc_style.'">'.$description.'</p>';
}
if ($description_link == 'yes') {
$description = $description.'</a>';
} else {
$description = '</a>'.$description;
}
if ($display == 'grid') {
$gallery .= '<figure id="gallery-item-'.$i.'" class="gallery-item wplf-item">
<div class="gallery-icon landscape">
<a class="wplf_link" href="'.$url.'" target="_blank">
'.$img.'
<p class="wplf_display" style="'.$title_style.'" >'.$title_display.'</p>
'.$description.'
</div>
</figure>';
} elseif ($display == 'list') {
$list .= '<div id="wplf_list-item-'.$i.'" class="list-item wplf-item">
<a class="wplf_link" href="'.$url.'" target="_blank">
<div class="list-img">'.$img.'</div>
<p class="wplf_display" style="'.$title_style.'" >'.$title_display.'</p>
'.$description.'
</div>
<hr>';
}
$i++;
endwhile;
if ($display == 'grid') {
$output = '<div style="clear:both;"></div><div id="gallery-wplf" class="galleryid-wplf gallery-columns-'.$cols.' wplf-display">'.$gallery.'</div><div style="clear:both;"></div>';
} elseif ($display == 'list') {
$output = '<div style="clear:both;"></div><div id="list-wplf" class="listid-wplf wplf-display">'.$list.'</div><div style="clear:both;"></div>';
}
wp_reset_query();
return $output;
}
Code file location:
wp-links-page/wp-links-page/wp-links-page-free.php
Conclusion
Now that you’ve learned how to embed the WP Links Page Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply