Customize WordPress pagination - wordpress

Good day, I am creating a plugin that will automatically posts a slideshow article with page break using <!--nextpage--> , my problem is i want to custom the pagination style instead of page: 1,2 i want to show up as next-page and previous-page. how can i achieved this one? i want to put the code inside the plugin i don't want to add codes in the theme.
I have already tried adding this code in my plugin but did not work:
$defaults = array(
'before' => '<h1>' . __( 'Pages:' ),
'after' => '</h1>',
'link_before' => '',
'link_after' => '',
'next_or_number' => 'next',
'separator' => ' ',
'nextpagelink' => __( 'Next page' ),
'previouspagelink' => __( 'Previous page' ),
'pagelink' => 'Page %',
'echo' => 1
);
wp_link_pages( $defaults );
This is the code in my plugin:
$x = "";
foreach ($leadamajig_data->questions as $post)
{
$lead_title = '<p><h1 id="title">' . $post->title . '</a></h1></p>';
$lead_choices = '<p><h1 id="clicked"><a hre="#">' . $post->choices->a . '</a></h1></p>';
$lead_choices2 ='<p><h1 id="clicked2"><a hre="#">' .$post->choices->b . '</a></h1></p>';
$lead_choices3 = '<p><h1 id="clicked3"><a hre="#">' . $post->choices->c . '</a></h1></p>';
$x = $x . $lead_title . $lead_choices . $lead_choices2 . $lead_choices3 . '<!--nextpage-->';
}
$my_post = array(
'post_title' => questions,
'post_content' => $x,
'post_status' => 'publish',
'post_author' => 1
);
wp_insert_post( $my_post );

wp_link_pages() returns the pagination markup you have defined with your $default array of parameters. So you probably already have the html that you want to show returned from the wp_link_pages() function.
Assign wp_link_pages() to a variable and then echo or print out the content where you want your pagination to appear.
Like this:
$defaults = array(
'before' => '<h1>' . __( 'Pages:' ),
'after' => '</h1>',
'link_before' => '',
'link_after' => '',
'next_or_number' => 'next',
'separator' => ' ',
'nextpagelink' => __( 'Next page' ),
'previouspagelink' => __( 'Previous page' ),
'pagelink' => 'Page %',
'echo' => 1
);
$pagination = wp_link_pages( $defaults );
//Put this where you want your pagination to appear:
echo $pagination;

Related

WP Bakery woocommerce show product subcategory (FREE)

I wanted to share this work with you since I did not find any solution on the internet, so I had to build mine.
The problem was that the client wanted to show the subcategories within the main category using a shortcode. Only the name of the subcategories, without thumbnail or number of products.
So create a file called "products-subcategory.php" in plugins/bezel-addons/vc/shortcodes/.
And I incorporated it in plugins/bezel-addons/vc/shortcodes.php
In my case my template is the Bezzel https://themeforest.net/item/bezel-creative-multipurpose-wordpress-theme/20014332
But I think you can implement it in anyone using Visual Composer or WP Bakery.
products-subcategory.php.
<?php
/* Product subcategory */
vc_map(
array(
'name' => 'Product subcategory',
'base' => 'bezel_products_subcategory',
'icon' => 'ti-align-left',
'description' => 'Product subcategories',
'category' => __( 'Bezel', 'bezel-addons'),
'params' => array(
array(
'type' => 'dropdown',
'param_name' => 'orderby',
'heading' => 'Order BY',
'value' => array(
'Name' => 'name',
'ID' => 'term_id'
),
),
array(
'type' => 'dropdown',
'param_name' => 'order',
'heading' => 'Order',
'value' => array(
'Upward' => 'ASC',
'Falling' => 'DESC'
),
),
array(
'type' => 'dropdown',
'param_name' => 'empty',
'heading' => 'Show empty subcategories',
'value' => array(
'Yes' => 0,
'No' => 1
),
)
)
)
);
add_shortcode( 'bezel_products_subcategory', 'bezel_products_subcategory' );
function bezel_products_subcategory( $atts ) {
global $wp_query;
extract( shortcode_atts( array(
'taxonomy' => 'product_cat',
'orderby' => 'name',
'order' => 'ASC',
'empty' => 0,
'hierarchical' => 1
), $atts ) );
$cat = get_queried_object();
$category_id = ($cat->parent) ? $cat->parent : $cat->term_id;
$args2 = array('taxonomy' => $taxonomy,'parent' => $category_id,'hierarchical' => $hierarchical, 'orderby' => $orderby, 'order' => $order,'hide_empty' => $empty);
$categories = get_categories( $args2 );
$categories_cnt = count(get_categories( $args2 ));
$selcat[$cat->term_id] = 'current-cat';
if ($categories_cnt != 0){
$sub_cats = get_categories( $args2 );
if($sub_cats) {
$output = '<div class="vc_wp_categories wpb_content_element">';
$output .= '<div class="widget widget_categories">';
$output .= '<ul>';
foreach($sub_cats as $sub_category) {
$output .= '<li class="cat-item cat-item-'.$sub_category->term_id.' '.$selcat[$sub_category->term_id].'">'.$sub_category->cat_name.'</li>';
}
$output .= '</ul>';
$output .= '</div>';
$output .= '</div>';
}
}
return $output;
}
?>

How can I render Nested elements on Visual Composer (WPBakery) for wordpress?

I'm trying to do some custom elements for Visual Composer plugin (WP-Bakery) for wordpress.
I have no problem with simple custom elements, but I'm trying to do some nested elements (a parent containing some child elements). I have no problems creating child elements, and if I create them alome, they are shown on wordpress, but when I try to create parent element, I can see setting elements without problem, but it's no rendered.
I think the problem is the render function (html) on parent class, but I can't get solve it.
PARENT CLASS
<?php
class vcInfoCardContainer extends WPBakeryShortCodesContainer {
// Element Init
function __construct() {
add_action( 'init', array( $this, 'vc_infocardcontainer_mapping' ) );
add_shortcode( 'vc_infocard', array( $this, 'vc_infocardcontainer_html' ) );
}
// Element Mapping
public function vc_infocardcontainer_mapping() {
// Stop all if VC is not enabled
if ( !defined( 'WPB_VC_VERSION' ) ) {
return;
}
// Map the block with vc_map()
vc_map(
array(
'name' => __('VC Info Card Container', 'ex5_vc_elements'),
'base' => 'vc_infocardcontainer',
'description' => __('Info Card Container for VC', 'ex5_vc_elements'),
'category' => __('Ex5 Elements', 'ex5_vc_elements'),
'icon' => get_template_directory_uri().'/assets/img/vc-icon.png',
'as_parent' => array('only' => 'vc_infocard'),
'is_container' => true,
'js_view' => 'VcColumnView',
'params' => array(
array(
'type' => 'textfield',
'heading' => __('Button text','ex5_vc_elements'),
'param_name' => 'button_text',
'description' => __('Default is \'Más info\'', 'ex5_vc_elements'),
'group' => 'Button',
)
),
));
}
//render
public function vc_infocard_html( $atts, $content = null ) {
// Params extraction
extract(
shortcode_atts(
array(
),
$atts
)
);
$html = '<div class="ex5-vc-info-card-container">' . do_shortcode($content) . '</div>';
return $html;
}
}
new vcInfoCardContainer();
CHILD CLASS
<?php
class vcInfoCard extends WPBakeryShortCode {
// Element Init
function __construct() {
add_action( 'init', array( $this, 'vc_infocard_mapping' ) );
add_shortcode( 'vc_infocard', array( $this, 'vc_infocard_html' ) );
}
// Element Mapping
public function vc_infocard_mapping() {
// Stop all if VC is not enabled
if ( !defined( 'WPB_VC_VERSION' ) ) {
return;
}
// Map the block with vc_map()
vc_map(
array(
'name' => __('VC Info Card', 'ex5_vc_elements'),
'base' => 'vc_infocard',
'description' => __('Info Card for VC', 'ex5_vc_elements'),
'category' => __('Ex5 Elements', 'ex5_vc_elements'),
'icon' => get_template_directory_uri().'/assets/img/vc-icon.png',
'as_child' => array('only' => 'vc_infocardcontainer'),
'params' => array(
array(
'type' => 'attach_image',
'heading' => __( 'Main image', 'ex5_vc_elements' ),
'param_name' => 'image',
'group' => 'Images',
),
array(
'type' => 'attach_image',
'heading' => __( 'Icon', 'ex5_vc_elements' ),
'param_name' => 'icon',
'group' => 'Images',
),
array(
'type' => 'colorpicker',
'heading' => __( 'Icon background color', 'ex5_vc_elements' ),
'param_name' => 'icon_background_color',
'value' => __( '#000000', 'ex5_vc_elements' ),
'group' => 'Images',
),
array(
'type' => 'textfield',
'heading' => __('Title','ex5_vc_elements'),
'param_name' => 'Title',
'group' => 'Texts',
),
array(
'type' => 'textfield',
'heading' => __( 'Text', 'ex5_vc_elements' ),
'param_name' => 'text',
'group' => 'Texts',
),
array(
'type' => 'checkbox',
'class' => 'one-third',
'heading' => __( 'Show link button', 'ex5_vc_elements' ),
'param_name' => 'show_button',
'value' => 'show',
'description' => __( 'Indicates if link button is shown)', 'ex5_vc_elements' ),
'group' => 'Button',
),
array(
'type' => 'textfield',
'heading' => __('Button text','ex5_vc_elements'),
'param_name' => 'button_text',
'description' => __('Default is \'Más info\'', 'ex5_vc_elements'),
'group' => 'Button',
),
array(
'type' => 'vc_link',
'heading' => __( 'Button link', 'ex5_vc_elements' ),
'param_name' => 'button_link',
'group' => 'Button',
),
),
));
}
//render
public function vc_infocard_html( $atts ) {
// Params extraction
extract(
shortcode_atts(
array(
'image' => '',
'icon' => '',
'icon_background_color' => '#000000',
'title' => '',
'text' => '',
'show_button' => '',
'button_text' => 'Más info',
'button_link' => '',
),
$atts
)
);
if (empty($button_text)) $button_text = __( 'Más info', 'ex5_vc_elements' );
if ($show_button === 'true') {
if (!empty($button_link)) {
$button = '<div class="ex5-vcic-button">
<a href="'. $button_link .'" target="_self" class="ex5-vcic-link" title="' . $button_text . '">
<span class="ex5-vcic-button-text">' . $button_text . '</span>
</a>
</div>';
} else {
$button = '<div class="ex5-vcic-button">
<span class="ex5-vcic-button-text">' . $button_text . '</span>
</div>';
}
} else {
$button = '';
}
$image = wp_get_attachment_image_src($image);
$icon = wp_get_attachment_image_src($icon);
//vc_build_link(
$html = '
<div class="ex5-vc-infocard">
<div class="ex5-vcic-content">
<div class="ex5-vcic-image">
<span>
<img src="' . $image[0] . '" title="history_inner_14" alt="http://oxigeno.">
</span>
</div>
<div class="ex5-vcic-icon" style="background-color: ' . $icon_background_color . '">
<img src="' . $icon[0] . '" />
</div>
<header class="ex5-vcic-headline">
<h3>' . $title . '</h3>
</header>
<div class="ex5-vcic-text">
<p>' . $text . '</p>
</div>' .
$button
. '</div>
</div>';
return $html;
}
}
new vcInfoCard();
There was a problem with the name of container shortcode. It had to be
add_shortcode( 'vc_infocardcontainer', array( $this, 'vc_infocardcontainer_html' ) );
But there's still a problem. I have a problem with do_shortcode_tag function
Attempting to parse a shortcode without a valid callback
Anybody knows how can I solve it?
I had solved it. The shortcode call was wrong because it had the wrong function name too.
public function vc_infocard_html( $atts, $content = null ) {
must be
public function vc_infocardcontainer_html( $atts, $content = null ) {

Wordpress Pagination Button working in desktop but not working in mobile or small screen

I am making a blog site.
It has next button for every image using page break.
The next button is working in desktop perfectly but its not working in mobile.
$args = array(
'before' => '<center><p style="float:none;">' . __( '<span
style="margin-top:7px;font-size:18pt;">Page '.$page.'-
'.$numpages.'</span>' ),
'after' => '</p></center>',
'link_before' => '',
'link_after' => '',
'next_or_number' => 'next', //change into number for numeric
pagination
'separator' => ' ',
'nextpagelink' => __( '<button style="cursor:pointer;color:white;
background:#ff8000; border-
radius:40px;height:50px;width:250px;font-
size:15pt" class="btn"><span style>Next
</span><span class="dashicons dashicons-arrow-right-alt2"></span></button>' ),
'previouspagelink' => __(''),
'pagelink' => '%',
'echo' => 3
);
wp_link_pages( $args );
This works perfectly in desktop but does not respond in mobile
Try changning button to an anchor with the same styling, here's your updated code:
$args = array(
'before' => '<center><p style="float:none;">' . __( '<span
style="margin-top:7px;font-size:18pt;">Page '.$page.'-
'.$numpages.'</span>' ),
'after' => '</p></center>',
'link_before' => '',
'link_after' => '',
'next_or_number' => 'next', //change into number for numeric pagination
'separator' => ' ',
'nextpagelink' => __( '<span style="cursor:pointer;color:white;
background:#ff8000; border-
radius:40px;height:50px;width:250px;font-
size:15pt" class="btn">Next
</span><span class="dashicons dashicons-arrow-right-alt2"></span>' ),
'previouspagelink' => __(''),
'pagelink' => '%',
'echo' => 3
);
wp_link_pages( $args );

How to add next and prev button in wordpress post

I have created a wordpress post. Used page break to break the page. Page numbers are working. But how can i add prev and next button insted of page number pagination??
Try this following code
<?php
$args = array(
'before' => '<p>' . __( 'Pages:' ),
'after' => '</p>',
'link_before' => '',
'link_after' => '',
'next_or_number' => 'next', //change into number for numeric pagination
'separator' => ' ',
'nextpagelink' => __( 'Next page' ),
'previouspagelink' => __( 'Previous page' ),
'pagelink' => '%',
'echo' => 1
);
wp_link_pages( $args );
?>
reference : https://codex.wordpress.org/Function_Reference/wp_link_pages
hope it helps

Setting a default option using CMB2 select field type

I am using CMB2's select to pull in a list of posts that a user can choose from in a custom meta box.
I have added a "blank" option to the options array, but I can't figure out how to make that the default option (ie. <option selected="selected" value="">I'm blank</option>).
I need to do this so I can use an if statement that says if the field is blank, don't show the output box on the site. Right now, even if the user hasn't specifically chosen an option, an option with a value is passed through.
Here's the meta box code:
$link_post_types = array('charter', 'page');
$meta_boxes['ms_metabox'] = array(
'id' => 'ms_metabox',
'title' => __( 'Page Links', 'cmb2' ),
'object_types' => array( 'page' ),
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
'fields' => array(
array(
'name' => __( 'Page Link', 'cmb2' ),
'desc' => __( 'Choose the page this will link to', 'cmb2' ),
'id' => $prefix . 'page_link',
'type' => 'select',
'options' => ms_get_posttype_options($link_post_types),
),
),
);
function ms_get_posttype_options($argument) {
$get_post_args = array(
'post_type' => $argument,
'posts_per_page' => -1,
'orderby' => 'type',
'order' => ASC
);
$options = array();
foreach ( get_posts( $get_post_args ) as $post ) {
$post_type = get_post_type( $post->ID);
$title = get_the_title( $post->ID );
$permalink = get_permalink( $post->ID);
$options[] = array(
'name' => $title . ' : ' . $post_type,
'value' => $permalink,
);
}
$empty_option[] = array(
'name' => 'Please select an option',
'value' => '',
);
$options = array_merge($empty_option, $options);
return $options;
}
There is a default argument but when I tried to apply it as in the example, it didn't work.
Thanks for any help!
I halfway figured it out. The posts I was having problems with were old ones where I had already been messing with the values before I added the blank option - when I created new posts, the default option was the blank one (since it was the first array in the merge).
If anyone has a more foolproof solution I'd like to hear it though!
You can add the following to the meta box fields array:
show_option_none' => true

Resources