Related
Please check the URL: https://channelc.net/newsite/podcasts/
The shortcode is not working. The shortcode is displaying as the code itself on the frontend. Can anybody please help me that how can I make the shortcode work in the frontend? Is there somehow the conversion from shortcode to the desired element is being prevented by the code I am using?
The code I am using is:
add_action( 'wp_ajax_demo_load_my_posts', 'demo_load_my_posts' );
add_action( 'wp_ajax_nopriv_demo_load_my_posts', 'demo_load_my_posts' );
function demo_load_my_posts() {
global $wpdb;
$msg = '';
if( isset( $_POST['data']['page'] ) ){
// Always sanitize the posted fields to avoid SQL injections
$page = sanitize_text_field($_POST['data']['page']); // The page we are currently at
$name = sanitize_text_field($_POST['data']['th_name']); // The name of the column name we want to sort
$sort = sanitize_text_field($_POST['data']['th_sort']); // The order of our sort (DESC or ASC)
$cur_page = $page;
$page -= 1;
$per_page = 10; // Number of items to display per page
$previous_btn = true;
$next_btn = true;
$first_btn = true;
$last_btn = true;
$start = $page * $per_page;
// The table we are querying from
$posts = $wpdb->prefix . "posts";
$where_search = '';
// Check if there is a string inputted on the search box
if( ! empty( $_POST['data']['search']) ){
// If a string is inputted, include an additional query logic to our main query to filter the results
$where_search = ' AND (post_title LIKE "%%' . $_POST['data']['search'] . '%%" OR post_content LIKE "%%' . $_POST['data']['search'] . '%%") ';
}
// Retrieve all the posts
$all_posts = $wpdb->get_results($wpdb->prepare("
SELECT * FROM $posts WHERE post_type = 'post' AND post_status = 'publish' $where_search
ORDER BY $name $sort LIMIT %d, %d", $start, $per_page ) );
$count = $wpdb->get_var($wpdb->prepare("
SELECT COUNT(ID) FROM " . $posts . " WHERE post_type = 'post' AND post_status = 'publish' $where_search", array() ) );
// Check if our query returns anything.
if( $all_posts ):
$msg .= '<table class = "table table-striped table-hover table-file-list">';
// Iterate thru each item
foreach( $all_posts as $key => $post ):
$msg .= '
<tr>
<td width = "60%">' . $post->post_content . '</td>
</tr>';
endforeach;
$msg .= '</table>';
// If the query returns nothing, we throw an error message
else:
$msg .= '<p class = "bg-danger">No posts matching your search criteria were found.</p>';
endif;
$msg = "<div class='cvf-universal-content'>" . $msg . "</div><br class = 'clear' />";
$no_of_paginations = ceil($count / $per_page);
if ($cur_page >= 7) {
$start_loop = $cur_page - 3;
if ($no_of_paginations > $cur_page + 3)
$end_loop = $cur_page + 3;
else if ($cur_page <= $no_of_paginations && $cur_page > $no_of_paginations - 6) {
$start_loop = $no_of_paginations - 6;
$end_loop = $no_of_paginations;
} else {
$end_loop = $no_of_paginations;
}
} else {
$start_loop = 1;
if ($no_of_paginations > 7)
$end_loop = 7;
else
$end_loop = $no_of_paginations;
}
$pag_container .= "
<div class='cvf-universal-pagination'>
<ul>";
if ($first_btn && $cur_page > 1) {
$pag_container .= "<li p='1' class='active'>First</li>";
} else if ($first_btn) {
$pag_container .= "<li p='1' class='inactive'>First</li>";
}
if ($previous_btn && $cur_page > 1) {
$pre = $cur_page - 1;
$pag_container .= "<li p='$pre' class='active'>Previous</li>";
} else if ($previous_btn) {
$pag_container .= "<li class='inactive'>Previous</li>";
}
for ($i = $start_loop; $i <= $end_loop; $i++) {
if ($cur_page == $i)
$pag_container .= "<li p='$i' class = 'selected' >{$i}</li>";
else
$pag_container .= "<li p='$i' class='active'>{$i}</li>";
}
if ($next_btn && $cur_page < $no_of_paginations) {
$nex = $cur_page + 1;
$pag_container .= "<li p='$nex' class='active'>Next</li>";
} else if ($next_btn) {
$pag_container .= "<li class='inactive'>Next</li>";
}
if ($last_btn && $cur_page < $no_of_paginations) {
$pag_container .= "<li p='$no_of_paginations' class='active'>Last</li>";
} else if ($last_btn) {
$pag_container .= "<li p='$no_of_paginations' class='inactive'>Last</li>";
}
$pag_container = $pag_container . "
</ul>
</div>";
echo
'<div class = "cvf-pagination-content">' . $msg . '</div>' .
'<div class = "cvf-pagination-nav">' . $pag_container . '</div>';
}
exit();
}
It's working now.
add_action( 'wp_ajax_demo_load_my_posts', 'demo_load_my_posts' );
add_action( 'wp_ajax_nopriv_demo_load_my_posts', 'demo_load_my_posts' );
function demo_load_my_posts() {
global $wpdb;
$msg = '';
if( isset( $_POST['data']['page'] ) ){
// Always sanitize the posted fields to avoid SQL injections
$page = sanitize_text_field($_POST['data']['page']); // The page we are currently at
$name = sanitize_text_field($_POST['data']['th_name']); // The name of the column name we want to sort
$sort = sanitize_text_field($_POST['data']['th_sort']); // The order of our sort (DESC or ASC)
$cur_page = $page;
$page -= 1;
$per_page = 10; // Number of items to display per page
$previous_btn = true;
$next_btn = true;
$first_btn = true;
$last_btn = true;
$start = $page * $per_page;
$author = the_author_meta("ID");
// The table we are querying from
$posts = $wpdb->prefix . "posts";
$where_search = '';
// Check if there is a string inputted on the search box
if( ! empty( $_POST['data']['search']) ){
// If a string is inputted, include an additional query logic to our main query to filter the results
$where_search = ' AND (post_title LIKE "%%' . $_POST['data']['search'] . '%%" OR post_content LIKE "%%' . $_POST['data']['search'] . '%%") ';
}
// Retrieve all the posts
$all_posts = $wpdb->get_results($wpdb->prepare("
SELECT * FROM $posts WHERE post_type = 'post' AND post_status = 'publish' AND post_author = $author $where_search ORDER BY $name $sort LIMIT %d, %d", $start, $per_page ) );
echo $post->post_author;
$count = $wpdb->get_var($wpdb->prepare("
SELECT COUNT(ID) FROM " . $posts . " WHERE post_type = 'post' AND post_status = 'publish' $where_search", array() ) );
// Check if our query returns anything.
if( $all_posts ):
$msg .= '<table width = "100%">';
// Iterate thru each item
foreach( $all_posts as $key => $post ):
$msg .= '
<tr>
<td>' . do_shortcode($post->post_content) . '</td>
<td>' . $post->post_author . '</td>
</tr>';
endforeach;
$msg .= '</table>';
// If the query returns nothing, we throw an error message
else:
$msg .= '<p class = "bg-danger">No posts matching your search criteria were found. </p>';
endif;
$msg = "<div class='cvf-universal-content'>" . $msg . "</div><br class = 'clear' />";
$no_of_paginations = ceil($count / $per_page);
if ($cur_page >= 7) {
$start_loop = $cur_page - 3;
if ($no_of_paginations > $cur_page + 3)
$end_loop = $cur_page + 3;
else if ($cur_page <= $no_of_paginations && $cur_page > $no_of_paginations - 6) {
$start_loop = $no_of_paginations - 6;
$end_loop = $no_of_paginations;
} else {
$end_loop = $no_of_paginations;
}
} else {
$start_loop = 1;
if ($no_of_paginations > 7)
$end_loop = 7;
else
$end_loop = $no_of_paginations;
}
$pag_container .= "
<div class='cvf-universal-pagination'>
<ul>";
if ($first_btn && $cur_page > 1) {
$pag_container .= "<li p='1' class='active'>First</li>";
} else if ($first_btn) {
$pag_container .= "<li p='1' class='inactive'>First</li>";
}
if ($previous_btn && $cur_page > 1) {
$pre = $cur_page - 1;
$pag_container .= "<li p='$pre' class='active'>Previous</li>";
} else if ($previous_btn) {
$pag_container .= "<li class='inactive'>Previous</li>";
}
for ($i = $start_loop; $i <= $end_loop; $i++) {
if ($cur_page == $i)
$pag_container .= "<li p='$i' class = 'selected' >{$i}</li>";
else
$pag_container .= "<li p='$i' class='active'>{$i}</li>";
}
if ($next_btn && $cur_page < $no_of_paginations) {
$nex = $cur_page + 1;
$pag_container .= "<li p='$nex' class='active'>Next</li>";
} else if ($next_btn) {
$pag_container .= "<li class='inactive'>Next</li>";
}
if ($last_btn && $cur_page < $no_of_paginations) {
$pag_container .= "<li p='$no_of_paginations' class='active'>Last</li>";
} else if ($last_btn) {
$pag_container .= "<li p='$no_of_paginations' class='inactive'>Last</li>";
}
$pag_container = $pag_container . "
</ul>
</div>";
echo
'<div class = "cvf-pagination-content">' . $msg . '</div>' .
'<div class = "cvf-pagination-nav">' . $pag_container . '</div>';
}
exit();
}
I have a wordpress website which is using the custom template with custom post types like landing and services.
Each post type have a specific slug in the url like this => (http://example.com/landing/landing-page-name)
I want to change this url (http://example.com/landing/landing-page-name) to this url (http://example.com/landing-page-name).
In fact I need to remove the [landing] phrase from the url. The important thing is that the [landing] is a custom post type in my posts table.
I have tested following solutions:
==> I have changed slug to '/' in rewrite property in register_post_type() --> It breaks the all of landings, posts and pages url (404)
==> I added 'with_front' => false to the rewrite property --> nothing changed
==> I tried to do this with RewriteRule in htaccess --> it did not work or give too many redirects error
I could not get a proper result.
Did anyone solve this problem before?
First, you need to filter the permalink for your custom post type so that all published posts don't have the slug in their URLs:
function stackoverflow_remove_cpt_slug( $post_link, $post ) {
if ( 'landing' === $post->post_type && 'publish' === $post->post_status ) {
$post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
}
return $post_link;
}
add_filter( 'post_type_link', 'stackoverflow_remove_cpt_slug', 10, 2 );
At this point, trying to view the link would result in a 404 (Page Not Found) error. That's because WordPress only knows that Posts and Pages can have URLs like domain.com/post-name/ or domain.com/page-name/. We need to teach it that our custom post type's posts can also have URLs like domain.com/cpt-post-name/.
function stackoverflow_add_cpt_post_names_to_main_query( $query ) {
// Return if this is not the main query.
if ( ! $query->is_main_query() ) {
return;
}
// Return if this query doesn't match our very specific rewrite rule.
if ( ! isset( $query->query['page'] ) || 2 !== count( $query->query ) ) {
return;
}
// Return if we're not querying based on the post name.
if ( empty( $query->query['name'] ) ) {
return;
}
// Add CPT to the list of post types WP will include when it queries based on the post name.
$query->set( 'post_type', array( 'post', 'page', 'landing' ) );
}
add_action( 'pre_get_posts', 'stackoverflow_add_cpt_post_names_to_main_query' );
try this code , 100% working single custom post type and multiple post type.
add this class in functions.php file in our theme , or create separate file and import into functions.php
class remove_cpt_base {
var $plugin_admin_page;
static $instance = null;
static public function init() {
if (self::$instance == null) {
self::$instance = new self();
}
return self::$instance;
}
function __construct() {
add_action('plugins_loaded', array($this, 'plugins_loaded'));
$this->rcptb_selected = get_option('rcptb_selected', array());
$this->rcptb_selected_keys = array_keys($this->rcptb_selected);
add_action('admin_menu', array($this, 'plugin_menu_link'));
add_filter('post_type_link', array($this, 'remove_slug'), 10, 3);
add_action('template_redirect', array($this, 'auto_redirect_old'), 1);
add_action('pre_get_posts', array($this, 'handle_cpts'), 1);
}
function plugins_loaded() {
load_plugin_textdomain('remove_cpt_base', FALSE, basename(dirname(__FILE__)) . '/languages/');
}
function filter_plugin_actions($links, $file) {
$settings_link = '' . __('Settings') . '';
array_unshift($links, $settings_link);
return $links;
}
function plugin_menu_link() {
$this->plugin_admin_page = add_submenu_page(
'options-general.php',
__('Remove CPT base', 'remove_cpt_base'),
__('Remove CPT base', 'remove_cpt_base'),
'manage_options',
basename(__FILE__),
array($this, 'admin_options_page')
);
add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'filter_plugin_actions'), 10, 2);
}
function admin_options_page() {
if (get_current_screen()->id != $this->plugin_admin_page) {
return;
}
global $wp_post_types;?>
<div class="wrap">
<h2><?php _e('Remove base slug from url for these custom post types:', 'remove_cpt_base')?></h2><?php
if (isset($_POST['rcptb_selected_sent'])) {
if (!isset($_POST['rcptb_alternation']) || !is_array($_POST['rcptb_alternation'])) {
$alternation = array();
} else {
$alternation = $_POST['rcptb_alternation'];
}
if (!isset($_POST['rcptb_selected']) || !is_array($_POST['rcptb_selected'])) {
$this->rcptb_selected = array();
} else {
$this->rcptb_selected = $_POST['rcptb_selected'];
}
foreach ($this->rcptb_selected as $post_type => $active) {
$this->rcptb_selected[$post_type] = isset($alternation[$post_type]) ? 1 : 0;
}
$this->rcptb_selected_keys = array_keys($this->rcptb_selected);
update_option('rcptb_selected', $this->rcptb_selected, 'no');
echo '<div class="below-h2 updated"><p>' . __('Settings saved.') . '</p></div>';
flush_rewrite_rules();
}?>
<br>
<form method="POST" action="">
<input type="hidden" name="rcptb_selected_sent" value="1">
<table class="widefat" style="width:auto">
<tbody><?php
foreach ($wp_post_types as $type => $custom_post) {
if ($custom_post->_builtin == false) {?>
<tr>
<td>
<label>
<input type="checkbox" name="rcptb_selected[<?php echo $custom_post->name ?>]" value="1" <?php echo isset($this->rcptb_selected[$custom_post->name]) ? 'checked' : '' ?>>
<?php echo $custom_post->label ?> (<?php echo $custom_post->name ?>)
</label>
</td>
<td>
<label>
<input type="checkbox" name="rcptb_alternation[<?php echo $custom_post->name ?>]" value="1" <?php echo isset($this->rcptb_selected[$custom_post->name]) && $this->rcptb_selected[$custom_post->name] == 1 ? 'checked' : '' ?>>
<?php _e('alternation', 'remove_cpt_base')?>
</label>
</td>
</tr><?php
}
}?>
</tbody>
</table>
<p><?php _e('* if your custom post type children return error 404, then try alternation mode', 'remove_cpt_base')?></p>
<hr>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save')?>">
</p>
</form>
</div><?php
}
function remove_slug($permalink, $post, $leavename) {
global $wp_post_types;
foreach ($wp_post_types as $type => $custom_post) {
if ($custom_post->_builtin == false && $type == $post->post_type && isset($this->rcptb_selected[$custom_post->name])) {
$custom_post->rewrite['slug'] = trim($custom_post->rewrite['slug'], '/');
$permalink = str_replace('/' . $custom_post->rewrite['slug'] . '/', '/', $permalink);
}
}
return $permalink;
}
function get_current_url() {
$REQUEST_URI = strtok($_SERVER['REQUEST_URI'], '?');
$real_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
$real_url .= $_SERVER['SERVER_NAME'] . $REQUEST_URI;
return $real_url;
}
function handle_cpts($query) {
// make sure it's main query on frontend
if (!is_admin() && $query->is_main_query() && !$query->get('queried_object_id')) {
// conditions investigated after many tests
if ($query->is_404() || $query->get('pagename') || $query->get('attachment') || $query->get('name') || $query->get('category_name')) {
// test both site_url and home_url
$web_roots = array();
$web_roots[] = site_url();
if (site_url() != home_url()) {
$web_roots[] = home_url();
}
// polylang fix
if (function_exists('pll_home_url')) {
if (site_url() != pll_home_url()) {
$web_roots[] = pll_home_url();
}
}
foreach ($web_roots as $web_root) {
// get clean current URL path
$path = $this->get_current_url();
$path = str_replace($web_root, '', $path);
// fix missing slash
if (substr($path, 0, 1) != '/') {
$path = '/' . $path;
}
// test for posts
$post_data = get_page_by_path($path, OBJECT, 'post');
if (!($post_data instanceof WP_Post)) {
// test for pages
$post_data = get_page_by_path($path);
if (!is_object($post_data)) {
// test for selected CPTs
$post_data = get_page_by_path($path, OBJECT, $this->rcptb_selected_keys);
if (is_object($post_data)) {
// maybe name with ancestors is needed
$post_name = $post_data->post_name;
if ($this->rcptb_selected[$post_data->post_type] == 1) {
$ancestors = get_post_ancestors($post_data->ID);
foreach ($ancestors as $ancestor) {
$post_name = get_post_field('post_name', $ancestor) . '/' . $post_name;
}
}
// get CPT slug
$query_var = get_post_type_object($post_data->post_type)->query_var;
// alter query
$query->is_404 = 0;
$query->tax_query = NULL;
$query->is_attachment = 0;
$query->is_category = 0;
$query->is_archive = 0;
$query->is_tax = 0;
$query->is_page = 0;
$query->is_single = 1;
$query->is_singular = 1;
$query->set('error', NULL);
unset($query->query['error']);
$query->set('page', '');
$query->query['page'] = '';
$query->set('pagename', NULL);
unset($query->query['pagename']);
$query->set('attachment', NULL);
unset($query->query['attachment']);
$query->set('category_name', NULL);
unset($query->query['category_name']);
$query->set('post_type', $post_data->post_type);
$query->query['post_type'] = $post_data->post_type;
$query->set('name', $post_name);
$query->query['name'] = $post_name;
$query->set($query_var, $post_name);
$query->query[$query_var] = $post_name;
break;
} else {
// deeper matching
global $wp_rewrite;
// test all selected CPTs
foreach ($this->rcptb_selected_keys as $post_type) {
// get CPT slug and its length
$query_var = get_post_type_object($post_type)->query_var;
// test all rewrite rules
foreach ($wp_rewrite->rules as $pattern => $rewrite) {
// test only rules for this CPT
if (strpos($pattern, $query_var) !== false) {
if (strpos($pattern, '(' . $query_var . ')') === false) {
preg_match_all('#' . $pattern . '#', '/' . $query_var . $path, $matches, PREG_SET_ORDER);
} else {
preg_match_all('#' . $pattern . '#', $query_var . $path, $matches, PREG_SET_ORDER);
}
if (count($matches) !== 0 && isset($matches[0])) {
// build URL query array
$rewrite = str_replace('index.php?', '', $rewrite);
parse_str($rewrite, $url_query);
foreach ($url_query as $key => $value) {
$value = (int) str_replace(array('$matches[', ']'), '', $value);
if (isset($matches[0][$value])) {
$value = $matches[0][$value];
$url_query[$key] = $value;
}
}
// test new path for selected CPTs
if (isset($url_query[$query_var])) {
$post_data = get_page_by_path('/' . $url_query[$query_var], OBJECT, $this->rcptb_selected_keys);
if (is_object($post_data)) {
// alter query
$query->is_404 = 0;
$query->tax_query = NULL;
$query->is_attachment = 0;
$query->is_category = 0;
$query->is_archive = 0;
$query->is_tax = 0;
$query->is_page = 0;
$query->is_single = 1;
$query->is_singular = 1;
$query->set('error', NULL);
unset($query->query['error']);
$query->set('page', '');
$query->query['page'] = '';
$query->set('pagename', NULL);
unset($query->query['pagename']);
$query->set('attachment', NULL);
unset($query->query['attachment']);
$query->set('category_name', NULL);
unset($query->query['category_name']);
$query->set('post_type', $post_data->post_type);
$query->query['post_type'] = $post_data->post_type;
$query->set('name', $url_query[$query_var]);
$query->query['name'] = $url_query[$query_var];
// solve custom rewrites, pagination, etc.
foreach ($url_query as $key => $value) {
if ($key != 'post_type' && substr($value, 0, 8) != '$matches') {
$query->set($key, $value);
$query->query[$key] = $value;
}
}
break 3;
}
}
}
}
}
}
}
}
}
}
}
}
}
function auto_redirect_old() {
global $post;
if (!is_preview() && is_single() && is_object($post) && isset($this->rcptb_selected[$post->post_type])) {
$new_url = get_permalink();
$real_url = $this->get_current_url();
if (substr_count($new_url, '/') != substr_count($real_url, '/') && strstr($real_url, $new_url) == false) {
remove_filter('post_type_link', array($this, 'remove_slug'), 10);
$old_url = get_permalink();
add_filter('post_type_link', array($this, 'remove_slug'), 10, 3);
$fixed_url = str_replace($old_url, $new_url, $real_url);
wp_redirect($fixed_url, 301);
}
}
}
}
function rcptb_remove_plugin_options() {
delete_option('rcptb_selected');
}
add_action('init', array('remove_cpt_base', 'init'), 99);
register_activation_hook(__FILE__, 'flush_rewrite_rules');
register_deactivation_hook(__FILE__, 'flush_rewrite_rules');
register_uninstall_hook(__FILE__, 'rcptb_remove_plugin_options');
To the rewrite you just have to change your current slug from ‘cpt-slug’ to ‘/’ and the with-front: ‘false’. And done, you just resave permalinks and the url shouldn’t display the cpt slug anymore.
Having same issue and came across this answer and none of the above mentioned solution works so tried different plugins and the best which worked, removed base slug and solved 404 error try Remove CPT base
here is the error i get on my website when trying to process a payment page am not sure what to do i found this code
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/bargainhivee/public_html/wp-includes/wp-db.php:1482) in /home/bargainhivee/public_html/wp-content/plugins/Tevolution/tmplconnector/templatic-connector.php on line 5
this is the line 5
if (!isset($_SESSION)) { session_start(); }
here is the php file templatic-connector.php
<?php
/*
* includes the main files of tevolution default ad-on such as claim ownership,custom taxonomy,csutom fields,etc. and common functions.
*/
if (!isset($_SESSION)) { session_start(); }
require_once(TEMPL_MONETIZE_FOLDER_PATH."/templatic-claim_ownership/install.php" );
require_once(TEMPL_MONETIZE_FOLDER_PATH."/templatic-custom_taxonomy/install.php" );
require_once(TEMPL_MONETIZE_FOLDER_PATH."/templatic-custom_fields/install.php" );
require_once(TEMPL_MONETIZE_FOLDER_PATH."/templatic-monetization/install.php" );
require_once(TEMPL_MONETIZE_FOLDER_PATH."/templatic-ratings/install.php" );
require_once(TEMPL_MONETIZE_FOLDER_PATH."/templatic-registration/install.php" );
require_once (TEMPL_MONETIZE_FOLDER_PATH . "/templatic-widgets/templatic_browse_by_categories_widget.php");
require_once (TEMPL_MONETIZE_FOLDER_PATH . "/templatic-widgets/templatic_advanced_search_widget.php");
require_once (TEMPL_MONETIZE_FOLDER_PATH . "/templatic-widgets/templatic_people_list_widget.php");
require_once (TEMPL_MONETIZE_FOLDER_PATH . "/templatic-widgets/templatic_metakey_search_widget.php");
require_once(TEMPL_MONETIZE_FOLDER_PATH."templatic-generalization/general_functions.php" );
/* Add to favourites for tevolution*/
if(file_exists(TEMPL_MONETIZE_FOLDER_PATH."templatic-generalization/add_to_favourites.php") && (!strstr($_SERVER['REQUEST_URI'],'/wp-admin/') || strstr
($_SERVER['REQUEST_URI'],'/admin-ajax.php') )){
require_once(TEMPL_MONETIZE_FOLDER_PATH."templatic-generalization/add_to_favourites.php" );
}
/*
do action for admin menu
*/
add_action('admin_menu', 'templ_add_admin_menu_'); /* create templatic admin menu */
function templ_add_admin_menu_()
{
do_action('templ_add_admin_menu_');
}
add_action('templ_add_admin_menu_', 'templ_add_mainadmin_menu_', 0);
add_action('templ_add_admin_menu_', 'templ_remove_mainadmin_sub_menu_');
if(!function_exists('templ_remove_mainadmin_sub_menu_')){
function templ_remove_mainadmin_sub_menu_(){
remove_submenu_page('templatic_system_menu', 'templatic_system_menu');
add_submenu_page( 'templatic_system_menu', __('Overview','templatic-admin'), __('Overview','templatic-admin'), 'administrator',
'templatic_system_menu', 'templatic_connector_class' );
}
}
/*
include the main.connector.class.php file
*/
function templatic_connector_class()
{
require_once(TEVOLUTION_PAGE_TEMPLATES_DIR.'classes/main.connector.class.php' );
}
/*
Return the main menu at admin sidebar
*/
function templ_add_mainadmin_menu_()
{
$menu_title = __('Tevolution', 'templatic');
if (function_exists('add_object_page'))
{
if(isset($_REQUEST['page']) && $_REQUEST['page'] == 'templatic_system_menu'){
$icon = TEMPL_PLUGIN_URL.'favicon-active.png';
}else{
$icon = TEMPL_PLUGIN_URL.'favicon-active.png';
}
$hook = add_menu_page("Admin Menu", $menu_title, 'administrator', 'templatic_system_menu', 'dashboard_bundles', '',3); /* title of new
sidebar*/
}else{
add_menu_page("Admin Menu", $menu_title, 'administrator', 'templatic_wp_admin_menu', 'design','');
}
}
/*
return the connection with dashboard wizards(bundle box)
*/
function dashboard_bundles()
{
$Templatic_connector = New Templatic_connector;
require_once(TEVOLUTION_PAGE_TEMPLATES_DIR.'classes/main.connector.class.php' );
if(isset($_REQUEST['tab']) && $_REQUEST['tab'] =='extend') {
$Templatic_connector->templ_extend();
}else if(isset($_REQUEST['tab']) && $_REQUEST['tab'] =='payment-gateways') {
$Templatic_connector->templ_payment_gateway();
}else if((!isset($_REQUEST['tab'])&& #$_REQUEST['tab']=='') || isset($_REQUEST['tab']) && $_REQUEST['tab'] =='overview') {
$Templatic_connector->templ_overview();
$Templatic_connector->templ_dashboard_extends();
}
}
/*
return main CSS of Plugin
*/
add_action('admin_head', 'templ_add_my_stylesheet'); /* include style sheet */
add_action('wp_head', 'templ_add_my_stylesheet',0); /* include style sheet */
function templ_add_my_stylesheet()
{
/* Respects SSL, Style.css is relative to the current file */
wp_enqueue_script('jquery');
$tmpl_is_allow_url_fopen = tmpl_is_allow_url_fopen();
/* Tevolution Plug-in Style Sheet File In Desktop view only */
if (function_exists('tmpl_wp_is_mobile') && !tmpl_wp_is_mobile()) {
/* if "allow_url_fopen" is enabled then apply minifiled css otherwise includse seperately */
if(!$tmpl_is_allow_url_fopen){
wp_enqueue_style('tevolution_style',TEMPL_PLUGIN_URL.'style.css','',false);
}else{
wp_enqueue_style('tevolution_style',TEMPL_PLUGIN_URL.'css.minifier.php','',false);
}
}
if(function_exists('theme_get_settings')){
if(theme_get_settings('supreme_archive_display_excerpt')){
if(function_exists('tevolution_excerpt_length')){
add_filter('excerpt_length', 'tevolution_excerpt_length');
}
if(function_exists('new_excerpt_more')){
add_filter('excerpt_more', 'new_excerpt_more');
}
}
}
}
/* check if "allow_url_fopen" is enabled or not */
function tmpl_is_allow_url_fopen(){
if( ini_get('allow_url_fopen') ) {
return true;
}else{
return false;
}
}
/*
return each add-ons is activated or not
*/
function is_active_addons($key)
{
$act_key = get_option($key);
if ($act_key != '')
{
return true;
}
}
/*
Function will remove the admin dashboard widget
*/
function templ_remove_dashboard_widgets()
{
/* Globalize the metaboxes array, this holds all the widgets for wp-admin*/
global $wp_meta_boxes;
/* Remove the Dashboard quickpress widget*/
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
/* Remove the Dashboard incoming links widget*/
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
/* Remove the Dashboard secondary widget*/
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
}
add_action('wp_dashboard_setup', 'templ_remove_dashboard_widgets');
/* -- coding to add submenu under main menu-- */
add_action('templ_add_admin_menu_', 'templ_add_page_menu');
function templ_add_page_menu()
{
/*tevolution_menu_before_general_settings hook for add additional menu before general settings */
do_action('tevolution_menu_before_general_settings');
$menu_title2 = __('Settings', 'templatic-admin');
add_submenu_page('templatic_system_menu', $menu_title2, $menu_title2,'administrator', 'templatic_settings', 'my_page_templates_function');
/*tevolution_menu_after_general_settings hook for add additional menu after general settings */
do_action('tevolution_menu_after_general_settings');
}
/*
Email, security , and set up steps menu selected
*/
add_action('admin_footer','tevolution_menu_script');
function tevolution_menu_script()
{
?>
<script data-cfasync="false" type="text/javascript" async >
jQuery(document).ready(function(){
if(jQuery('#adminmenu ul.wp-submenu li').hasClass('current'))
{
<?php if(isset($_REQUEST['page']) && $_REQUEST['page']=='templatic_system_menu' && isset($_REQUEST['tab']) && $_REQUEST['tab']=='setup-steps'
):?>
jQuery('#adminmenu ul.wp-submenu li').removeClass('current');
jQuery('#adminmenu ul.wp-submenu li a').removeClass('current');
jQuery('#adminmenu ul.wp-submenu li a[href*="page=templatic_system_menu&tab=setup-steps"]').attr('href', function() {
jQuery('#adminmenu ul.wp-submenu li a[href*="page=templatic_system_menu&tab=setup-steps"]').addClass('current');
jQuery('#adminmenu ul.wp-submenu li a[href*="page=templatic_system_menu&tab=setup-steps"]').parent().addClass('current');
});
<?php endif;?>
}
jQuery('.reset_custom_fields').click( function() {
if(confirm("<?php echo __('All your modifications done with this, will be deleted forever! Still you want to proceed?','templatic-admin');?
>")){
return true;
}else{
return false;
}
});
});
</script>
<?php
}
/* include general_settings.php file */
function my_page_templates_function()
{
include(TEMPL_MONETIZE_FOLDER_PATH.'templatic-generalization/general_settings.php');
}
/*
Redirect on plugin dashboard after activating plugin
*/
add_action('admin_init', 'my_plugin_redirect');
function my_plugin_redirect()
{
global $pagenow;
if (get_option('myplugin_redirect_on_first_activation') == 'true' && $pagenow=='plugins.php' ){
update_option('myplugin_redirect_on_first_activation', 'false');
wp_redirect(MY_PLUGIN_SETTINGS_URL);
}
if (get_option('myplugin_redirect_on_first_activation') == 'true' && $pagenow=='themes.php' ){
update_option('myplugin_redirect_on_first_activation', 'false');
wp_redirect(site_url().'/wp-admin/themes.php');
}
}
/*
* View counter for detail page
*/
function view_counter_single_post($pid){
if($_SERVER['HTTP_REFERER'] == '' || !strstr($_SERVER['HTTP_REFERER'],$_SERVER['REQUEST_URI']))
{
$viewed_count = get_post_meta($pid,'viewed_count',true);
$viewed_count_daily = get_post_meta($pid,'viewed_count_daily',true);
$daily_date = get_post_meta($pid,'daily_date',true);
update_post_meta($pid,'viewed_count',$viewed_count+1);
if(get_post_meta($pid,'daily_date',true) == date('Y-m-d')){
update_post_meta($pid,'viewed_count_daily',$viewed_count_daily+1);
} else {
update_post_meta($pid,'viewed_count_daily','1');
}
update_post_meta($pid,'daily_date',date('Y-m-d'));
}
}
/*
* return the count of post view
*/
if(!function_exists('user_single_post_visit_count')){
function user_single_post_visit_count($pid)
{
if(get_post_meta($pid,'viewed_count',true))
{
return get_post_meta($pid,'viewed_count',true);
}else
{
return '0';
}
}
}
/*
* Function Name:user_single_post_visit_count_daily
* Argument: Post id
*/
if(!function_exists('user_single_post_visit_count_daily')){
function user_single_post_visit_count_daily($pid)
{
if(get_post_meta($pid,'viewed_count_daily',true))
{
return get_post_meta($pid,'viewed_count_daily',true);
}else
{
return '0';
}
}
}
/*
* add view count display after the content
*/
if( !function_exists('view_count')){
function view_count( $content ) {
if ( is_single())
{
global $post;
$sep =" , ";
$custom_content='';
$custom_content.="<p>".__('Visited','templatic')." ".user_single_post_visit_count($post->ID)." ".__('times','templatic');
$custom_content.= $sep.user_single_post_visit_count_daily($post->ID).__(" Visits today",'templatic')."</p>";
$custom_content .= $content;
echo $custom_content;
}
}
}
/*
* show counter and share button after custom fields.
*/
function teamplatic_view_counter()
{
$settings = get_option( "templatic_settings" );
if(isset($settings['templatic_view_counter']) && $settings['templatic_view_counter']=='Yes')
{
global $post;
view_counter_single_post($post->ID);
view_count('');
}
//view_sharing_buttons('');
tevolution_socialmedia_sharelink();
}
/*Remove the the_content filter to add view counter everywhere in single page and add action tmpl_detail_page_custom_fields_collection before the custom
field display*/
add_action('tmpl_detail_page_custom_fields_collection','teamplatic_view_counter',5);
function view_sharing_buttons($content)
{
global $post;
if (is_single() && ($post->post_type!='post' && $post->post_type!='page' && $post->post_type!='product' && $post->post_type!='product_variation'
))
{
$post_img = bdw_get_images_plugin($post->ID,'thumb');
$post_images = $post_img[0];
$title=urlencode($post->post_title);
$url=urlencode(get_permalink($post->ID));
$summary=urlencode(htmlspecialchars($post->post_content));
$image=$post_images;
$settings = get_option( "templatic_settings" );
if($settings['facebook_share_detail_page'] =='yes' || $settings['google_share_detail_page'] == 'yes' || $settings
['twitter_share_detail_page'] == 'yes' || $settings['pintrest_detail_page']=='yes'){
echo '<div class="share_link">';
if($settings['facebook_share_detail_page'] == 'yes')
{
?>
<a onClick="window.open('//www.facebook.com/sharer.php?s=100&p[title]=<?php echo $title;?>&p[summary]=<?php echo
$summary;?>&p[url]=<?php echo $url; ?>&&p[images][0]=<?php echo $image;?>','sharer','toolbar=0,status=0,width=548,height=325');"
href="javascript: void(0)" id="facebook_share_button"><?php _e('Facebook Share.',T_DOMAIN); ?></a>
<?php
}
if($settings['google_share_detail_page'] == 'yes'): ?>
<script data-cfasync="false" type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<div class="g-plus" data-action="share" data-annotation="bubble"></div>
<?php endif;
if($settings['twitter_share_detail_page'] == 'yes'): ?>
<a href="https://twitter.com/share" class="twitter-share-button" data-lang="en" data-text='<?php echo htmlentities
($post->post_content);?>' data-url="<?php echo get_permalink($post->ID); ?>" data-counturl="<?php echo get_permalink($post->ID); ?>"><?php _e
('Tweet',T_DOMAIN); ?></a>
<script data-cfasync="false">!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id))
{js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-
wjs");</script>
<?php endif;
if(#$settings['pintrest_detail_page']=='yes'):?>
<!-- Pinterest -->
<div class="pinterest">
<a href="//pinterest.com/pin/create/button/?url=<?php echo urlencode(get_permalink($post->ID)); ?>&media=<?php echo $image; ?
>&description=<?php the_title(); ?>" ><?php _e('Pin It','templatic');?></a>
<script data-cfasync="false" type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script>
</div>
<?php endif;
echo '</div>';
}
}
return $content;
}
/*
return the currency code
*/
function templatic_get_currency_type()
{
global $wpdb;
$option_value = get_option('currency_code');
if($option_value)
{
return stripslashes($option_value);
}else
{
return 'USD';
}
}
/*
this function returns the currency with position selected in currency settings
*/
function fetch_currency_with_position($amount,$currency = '')
{
$amt_display = '';
if($amount==''){ $amount =0; }
$decimals=get_option('tmpl_price_num_decimals');
$decimals=($decimals!='')?$decimals:2;
if($amount >=0 )
{
if(#$amount !='')
$amount = number_format( (float)($amount),$decimals,'.','');
$currency = get_option('currency_symbol');
$position = get_option('currency_pos');
if($position == '1')
{
$amt_display = $currency.$amount;
}
else if($position == '2')
{
$amt_display = $currency.' '.$amount;
}
else if($position == '3')
{
$amt_display = $amount.$currency;
}
else
{
$amt_display = $amount.' '.$currency;
}
return apply_filters('tmpl_price_format',$amt_display,$amount,$currency);
}
}
/*
this function returns the currency with position selected in currency settings
*/
function fetch_currency_with_symbol($amount,$currency = '')
{
$amt_display = '';
if($amount==''){ $amount =0; }
$decimals=get_option('tmpl_price_num_decimals');
$decimals=($decimals!='')?$decimals:2;
if($amount >=0 )
{
if(#$amount !='')
$amount = $amount;
$currency = get_option('currency_symbol');
$position = get_option('currency_pos');
if($position == '1')
{
$amt_display = $currency.$amount;
}
else if($position == '2')
{
$amt_display = $currency.' '.$amount;
}
else if($position == '3')
{
$amt_display = $amount.$currency;
}
else
{
$amt_display = $amount.' '.$currency;
}
return apply_filters('tmpl_price_format',$amt_display,$amount,$currency);
}
}
/* eof - display currency with position */
/* this function will display the legends descr
in this code;
if (!is_array($keywords)) {
$keywords = explode(',', $keywords);
}
foreach ($keywords as $thetag) {
wp_add_post_tags($post_id, $thetag);
}
How can i limit the number of tags added to the post?
Will this work
if (!is_array($keywords)) {
$count=0;
$keywords = explode(',', $keywords);
}
foreach ($keywords as $thetag) {
$count++;
wp_add_post_tags($post_id, $thetag);
if( $count > 3 ) break;
}
Yes it worked!!!!!
if (!is_array($keywords)) {
$count=0;
$keywords = explode(',', $keywords);
}
foreach ($keywords as $thetag) {
$count++;
wp_add_post_tags($post_id, $thetag);
if( $count > 3 ) break;
}
the website is the following: http://smokingdesigners.com
I have a problem with the masonry view of my pages.
I have recently changed my theme to a new one and my old theme used to add automatically on every article the "more" tag in order to crop my articles to fit to their masonry, So I have never actually added the "more" tag in more than 1200 articles.
My new theme is cropping the articles weird and that causes my page to be messed up because one box has height lets say 600 (including the picture) and the other 450 and it doesn't look good. (link with problem http://smokingdesigners.com/page/10/ )
Is there a way to make a fixed size boxes with heigh 575 lets say?
here is my masonry theme code..
$def_teaser_width = ( $dtw = get_option('wpb_post_teaser_width') ) ? $dtw : 'two-third';
if ( get_option('wpb_blog_layout') == __("Masonry", "wpb") ) {
$gallery_style = 'masonry';
} else {
$gallery_style = 'fluid';
}
if ( $_GET['style'] == 'masonry' ) {
$gallery_style = 'masonry';
} else if ( $_GET['style'] == 'fluid' ) {
$gallery_style = 'fluid';
}
$holder_class = ( $gallery_style == 'masonry' ) ? 'masonry_blocks' : 'float_blocks';
?>
<?php get_header(); ?>
<div class="float_blocks_container">
<div class="blog_teasers <?php echo $holder_class; ?>">
<?php if (have_posts()) :
$teasers_count = 0;
?>
<?php while (have_posts()) : the_post(); ?>
<?php
$teasers_count++;
$teaser_width = ( $tw = get_post_meta($post->ID, "_teaser_width", true) ) ? $tw : $def_teaser_width;
$teaser_width = ( $teaser_width == 'default' ) ? $def_teaser_width : $teaser_width;
//$teaser_width = ($teaser_w = get_post_meta($post->ID, "_teaser_width", true)) ? ' '.$teaser_w : ' one-half';
if ( $teaser_width == 'one-third' || ( $gallery_style == 'masonry' && $teaser_width == 'one-half' )) {
$th_w = 320;
$th_h = 180;
}
else if ( $teaser_width == 'one-half' ) {
$th_w = 495;
$th_h = 278;
}
else if ( $teaser_width == 'two-third' || ( $gallery_style == 'masonry' && $teaser_width == 'full-width' ) ) {
$th_w = 670;
$th_h = 377;
}
else if ( $teaser_width == 'full-width' ) {
$th_w = 1020;
$th_h = 574;
}
$content_type = (get_option('wpb_full_content') == 'true') ? ' full_content_in_blog' : '';
$has_thumbnail = '';
if (has_post_thumbnail() == false) { $has_thumbnail = ' no_thumbnail'; }
?>
<div id="post-<?php the_ID(); ?>" <?php post_class("post_teaser float_block ".$teaser_width.$has_thumbnail.$content_type); ?>>
<?php
$video_w = $th_w;
$video_h = $th_h;
$p_video = get_post_meta($post->ID, "_p_video", true);
$youtube = strpos($p_video, 'youtube.com');
$vimeo = strpos($p_video, 'vimeo');
if ( $youtube || $vimeo ) : ?>
<div class="p_video">
<?php
if ( $youtube ) {
preg_match('/[\\?\\&]v=([^\\?\\&]+)/', $p_video, $matches);
echo '<iframe width="'.$video_w.'" height="'.$video_h.'" src="http://www.youtube.com/embed/'.$matches[1].'" frameborder="0" allowfullscreen></iframe>';
}
else if ( $vimeo ) {
preg_match('#vimeo.com/([A-Za-z0-9\-_]+)?#s', $p_video, $matches);
echo '<iframe src="http://player.vimeo.com/video/'.$matches[1].'?title=0&byline=0&portrait=0" width="'.$video_w.'" height="'.$video_h.'" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>';
}
?>
</d
HERE IS FUNCTIONS.PHP FILE.
<?php
/*
wpb_category_filter
wpb_get_video_or_thumbnail
wpb_blog_pagination - previous/next page navigation
wpb_tags - return array with tags attached to post from specific vocab.
wpb_posted_under - return array with taxonomy object from specific vocab.
siteAttachedImages -
metaAttachedImages
wpb_login_head - changes logo in the WP login screen
wpb_resize - resize image to the specific dimensions
curPageURL - return current page url
*/
/* Category filter
---------------------------------------------------------- */
if (!function_exists('wpb_category_filter')) {
function wpb_category_filter ( $args = array() ) {
$defaults = array( 'taxonomy' => 'portfolio_category', 'posts' => NULL, 'echo' => true, 'filter_text' => __('Filter:', 'wpb_framework') );
$args = wp_parse_args( $args, $defaults );
$args = (object) $args;
if ( $args->posts == NULL) {
global $wp_query;
$args->posts = $wp_query->posts;
}
$categories_slugs_array = array();
$categories_names_array = array();
foreach ($args->posts as $p) {
$post_categories_array = wpb_get_post_categories(array('taxonomy' => $args->taxonomy, 'pid' => $p->ID));
if ( $post_categories_array ) {
$categories_slugs_array[$p->ID] = array();
$categories_names_array[$p->ID] = array();
if ( $post_categories_array['slug'] != NULL ) {
$categories_slugs_array[$p->ID] = array_unique( array_merge($post_categories_array['slug'], $categories_slugs_array[$p->ID]) );
$categories_names_array[$p->ID] = array_unique( array_merge($post_categories_array['name'], $categories_names_array[$p->ID]) );
}
}
}
$all_cats = array(); $all_slugs = array();
foreach ( $categories_names_array as $c ) { $all_cats = array_unique( array_merge( $all_cats, $c ) ); }
foreach ( $categories_slugs_array as $c ) { $all_slugs = array_unique( array_merge( $all_slugs, $c ) ); }
$filter = '';
if ( count($all_cats) > 0 ) :
$filter .= '<ul class="wpb_sort">';
$filter .= '<li class="wpb_all_cats"><span>'.$args->filter_text.'</span> <a class="wpb_sortable_current" href="#">'. __("All", "wpb_framework") .'</a></li>';
for ( $i = 0; $i < count($all_cats); $i++) {
$filter .= '<li><a class="wpb_sortable_cats" href="#" data-value="sortable-'.$all_slugs[$i].'">'.$all_cats[$i].'</a></li>';
}
$filter .= '</ul>';
unset($i);
endif;
return array('links' => $filter, 'categories_slugs_array' => $categories_slugs_array);
/*if ( $args->echo ) {
echo $filter;
} else {
return $filter;
}*/
}
}
/* Get video or thumbnail
---------------------------------------------------------- */
if (!function_exists('wpb_get_video_or_thumbnail')) {
function wpb_get_video_or_thumbnail( $args = array() ) {
$defaults = array( 'pid' => NULL, 'width' => 300, 'height' => 'proportional', 'force_image' => false, 'video_height' => 250, 'img_class' => NULL, 'echo' => true, 'before' => '', 'after' => '' );
$args = wp_parse_args( $args, $defaults );
$args = (object) $args;
if ($args->pid == NULL) {
global $post;
$pid = $post->ID;
} else {
$pid = $args->pid;
}
$has_thumbnail = '';
if ( has_post_thumbnail($pid) == false ) { $has_thumbnail = ' no_thumbnail'; }
$video_w = $args->width;
$video_h = $args->video_height;
$p_video = get_post_meta($pid, "_p_video", true);
$hide_image = get_post_meta($pid, "_hide_image", true);
$youtube = strpos($p_video, 'youtube.com');
$vimeo = strpos($p_video, 'vimeo');
if ( ($youtube || $vimeo) && !$args->force_image ) : ?>
<div class="p_video">
<?php
if ( $youtube ) {
preg_match('/[\\?\\&]v=([^\\?\\&]+)/', $p_video, $matches);
echo $args->before.'<iframe width="'.$video_w.'" height="'.$video_h.'" src="http://www.youtube.com/embed/'.$matches[1].'" frameborder="0" allowfullscreen></iframe>'.$args->after;
}
else if ( $vimeo ) {
preg_match('#vimeo.com/([A-Za-z0-9\-_]+)?#s', $p_video, $matches);
echo $args->before.'<iframe src="http://player.vimeo.com/video/'.$matches[1].'?title=0&byline=0&portrait=0" width="'.$video_w.'" height="'.$video_h.'" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>'.$args->after;
}
?>
</div>
<?php endif; ?>
<?php if ( ($has_thumbnail == '' && $hide_image != 'no' && $youtube == false && $vimeo == false)
|| $hide_image != 'no' && $args->force_image == true
) :
$th_id = get_post_thumbnail_id($pid);
$image_src = wp_get_attachment_image_src( $th_id, 'full' );
if ( $args->height == 'proportional' ) {
$th_h = round($video_w/$image_src[1] * $image_src[2]);
} else {
$th_h = $args->height;
}
$image = wpb_resize( $th_id, '', $video_w, $th_h, true );
$html = $args->before . '<img ';
$html .= ( $args->img_class ) ? ' class="'. $args->img_class .'"' : '';
$html .= ' src="'. $image['url'] .'" alt="" />'. $args->after;
if ($image['url'] && $args->echo) :
echo $html;
else:
return $html;
endif; ?>
<?php endif; ?>
<?php
}
}
/* Outputs next/previous links paginator
---------------------------------------------------------- */
if (!function_exists('wpb_next_prev_pagination')) {
function wpb_next_prev_pagination( $args = array() ) {
$defaults = array( 'next_txt' => '', 'prev_txt' => '', 'extra_class' => '' );
$args = wp_parse_args( $args, $defaults );
$args = (object) $args;
global $wp_query;
if ( $wp_query->max_num_pages > 1 ) :
if ($args->next_txt == '') $args->next_txt = '< ' . __('Previous posts', 'wpb_framework');
if ($args->prev_txt == '') $args->prev_txt = __('Next posts', 'wpb_framework') . ' >';
if ($args->extra_class != '') $args->extra_class = ' ' . $args->extra_class;
?>
<div class="wpb_paginator<?php echo $args->extra_class; ?>">
<?php next_posts_link($args->next_txt); previous_posts_link($args->prev_txt); ?><?php //previous == Se tidligere indlæg ?>
</div>
<?php
endif;
}
}
/* Paged paginator
---------------------------------------------------------- */
add_filter('previous_posts_link_attributes', 'previous_posts_link_css' );
function previous_posts_link_css($content) {
return 'class="controls left_control"';
}
add_filter('next_posts_link_attributes', 'next_posts_link_css' );
function next_posts_link_css($content) {
return 'class="right_control"';
}
if ( !function_exists('wpb_pagination') ) {
//Thanks Kriesi for the nice paginator
function wpb_pagination( $pages = '', $range = 10 ) {
$showitems = ($range * 2)+1;
//global $paged;
$paged = get_query_var('paged');
if ( empty($paged) ) $paged = 1;
if ( $pages == '' ) {
global $wp_query;
$pages = $wp_query->max_num_pages;
if ( !$pages ) {
$pages = 1;
}
}
if ( 1 != $pages ) {
echo "<div class='wp-pagenavi'>";
//if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>«</a>";
//if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>‹</a>";
for ( $i=1; $i <= $pages; $i++ ) {
if ( 1 != $pages && ( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) {
echo ( $paged == $i ) ? "<span class='current'>". $i ."</span>" : "<a href='". get_pagenum_link($i) ."' class='inactive' >". $i ."</a>";
}
}
if ($paged < $pages && $showitems < $pages) previous_posts_link('←');
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) next_posts_link('→');
//if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>›</a>";
//if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>»</a>";
echo "</div>\n";
}
}
}
/* Receives taxonomy name as argument and returns array
with tags objects
---------------------------------------------------------- */
if ( !function_exists('wpb_tags') ) {
function wpb_tags( $args = array() ) {
$defaults = array( 'pid' => NULL, 'tag_vocab' => '', 'echo' => true, 'before' => '', 'separator' => '', 'after' => '' );
$args = wp_parse_args( $args, $defaults );
$args = (object) $args;
if ($args->pid == NULL) {
global $post;
$pid = $post->ID;
} else {
$pid = $args->pid;
}
if ($args->tag_vocab != '') {
$output = get_the_term_list($pid, $args->tag_vocab, $args->before, $args->separator, $args->after);
} else {
$c_arr = array();
$tags_arr = get_the_tags();
if ($tags_arr) {
foreach($tags_arr as $tag) {
$c_arr[] = $args->before.'' . $tag->name . ''.$args->after;
}
$output = implode($args->separator, $c_arr);
}
}
if ($output and $args->echo) {
echo $output;
} else if ($output) {
return $output;
}
}
}
/*
---------------------------------------------------------- */
if (!function_exists('wpb_get_post_category_names')) {
function wpb_get_post_categories( $args = array() ) {
$defaults = array( 'taxonomy' => '', 'pid' => NULL, 'echo' => TRUE );
$args = wp_parse_args( $args, $defaults );
$args = (object) $args;
if ( $args->pid == NULL ) {
global $post;
$args->pid = $post->ID;
}
if ( $args->taxonomy != '' ) {
$terms = wp_get_object_terms($args->pid, $args->taxonomy);
}
if ( $terms ) {
$term_output = array();
$names = array();
$slugs = array();
foreach ( $terms as $term ) {
$names[] = $term->name;
$slugs[] = $term->slug;
}
$term_output['name'] = array_unique($names);
$term_output['slug'] = array_unique($slugs);
return $term_output;
}
}
}
/* Receives taxonomy name as argument and returns array
with taxonomy objects
---------------------------------------------------------- */
if (!function_exists('wpb_posted_under')) {
function wpb_posted_under( $args = array() ) {
$defaults = array( 'taxonomy' => '', 'pid' => NULL, 'echo' => TRUE, 'separator' => ', ', 'link' => TRUE );
$args = wp_parse_args( $args, $defaults );
$args = (object) $args;
if ($args->pid == NULL) {
global $post;
$args->pid = $post->ID;
}
if ($args->taxonomy != '') {
$terms = wp_get_object_terms($args->pid, $args->taxonomy);
}
else {
$terms = array();
foreach((get_the_category()) as $category) {
//get_category_link($category->cat_ID)
//$category->cat_name
$terms[] = $category;
}
}
if ($terms) {
$term_output = '';
foreach ($terms as $term) {
//$term_output[] = '' . $term->name . '';
if ($args->link) {
$term_output[] = '' . $term->name . '';
}
else {
$term_output[] = $term->name;
}
}
$term_output = implode($args->separator, $term_output);
if ($args->echo) {
echo $term_output;
}
else {
return $term_output;
}
}
}
}
/* Helper function which returs list of site attached images,
and if image is attached to the current post it adds class
'added'
---------------------------------------------------------- */
if (!function_exists('siteAttachedImages')) {
function siteAttachedImages($att_ids = array()) {
$output = '';
global $wpdb;
$media_images = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'attachment' order by ID desc");
foreach($media_images as $image_post) {
$thumb_src = wp_get_attachment_image_src($image_post->ID, 'thumbnail');
$thumb_src = $thumb_src[0];
$class = (in_array($image_post->ID, $att_ids)) ? ' class="added"' : '';
if ($thumb_src) {
$output .= '<li'.$class.'>
<img rel="'.$image_post->ID.'" src="'. $thumb_src .'" alt="'. $img_details[0] .'" />
<span class="img-added">'. __('Added', 'wpb_framework') .'</span>
</li>';
}
}
if ($output != '') {
$output = '<ul class="gallery_widget_img_select">' . $output . '</ul>';
}
return $output;
}
}
/* Helper function. Outputs attached images to the post
in custom meta section.
---------------------------------------------------------- */
if (!function_exists('metaAttachedImages')) {
function metaAttachedImages($att_ids = array()) {
$output = '';
foreach ($att_ids as $img_id) {
$thumb_src = wp_get_attachment_image_src($img_id, 'thumbnail');
$thumb_src = $thumb_src[0];
if ($thumb_src) {
$output .= '<li class="added">
<img rel="'.$img_id.'" src="'. $thumb_src .'" alt="" />
<span class="img-added">'. __('Added', 'wpb_framework') .'</span>
</li>';
}
}
return $output;
}
}
function getTopLevelCategories() {
$topCat = array();
$categories = get_categories('hide_empty=0');
foreach ($categories as $category) {
if ($category->parent == 0) {
$topCat[] = $category->name;
}
}
return $topCat;
}
/* Goldmines from internet
---------------------------------------------------------- */
/* Change Wordpress logo on login screen
---------------------------------------------------------- */
if (!function_exists('wpb_login_head')) {
add_action("login_head", "wpb_login_head");
function wpb_login_head() {
echo "
<style>
body.login #login h1 a {
background: url('".get_bloginfo('template_url')."/images/logotype.png') no-repeat scroll center top transparent;
}
</style>
";
}
}
/*
* Resize images dynamically using wp built in functions
* Victor Teixeira
*
* php 5.2+
*
* Exemplo de uso:
*
* <?php
* $thumb = get_post_thumbnail_id();
* $image = vt_resize( $thumb, '', 140, 110, true );
* ?>
* <img src="<?php echo $image[url]; ?>" width="<?php echo $image[width]; ?>" height="<?php echo $image[height]; ?>" />
*
* #param int $attach_id
* #param string $img_url
* #param int $width
* #param int $height
* #param bool $crop
* #return array
*/
if (!function_exists('wpb_resize')) {
function wpb_resize( $attach_id = null, $img_url = null, $width, $height, $crop = false ) {
// this is an attachment, so we have the ID
if ( $attach_id ) {
$image_src = wp_get_attachment_image_src( $attach_id, 'full' );
$file_path = get_attached_file( $attach_id );
// this is not an attachment, let's use the image url
} else if ( $img_url ) {
$file_path = parse_url( $img_url );
$file_path = $_SERVER['DOCUMENT_ROOT'] . $file_path['path'];
//$file_path = ltrim( $file_path['path'], '/' );
//$file_path = rtrim( ABSPATH, '/' ).$file_path['path'];
$orig_size = getimagesize( $file_path );
$image_src[0] = $img_url;
$image_src[1] = $orig_size[0];
$image_src[2] = $orig_size[1];
}
$file_info = pathinfo( $file_path );
$extension = '.'. $file_info['extension'];
// the image path without the extension
$no_ext_path = $file_info['dirname'].'/'.$file_info['filename'];
$cropped_img_path = $no_ext_path.'-'.$width.'x'.$height.$extension;
// checking if the file size is larger than the target size
// if it is smaller or the same size, stop right here and return
if ( $image_src[1] > $width || $image_src[2] > $height ) {
// the file is larger, check if the resized version already exists (for $crop = true but will also work for $crop = false if the sizes match)
if ( file_exists( $cropped_img_path ) ) {
$cropped_img_url = str_replace( basename( $image_src[0] ), basename( $cropped_img_path ), $image_src[0] );
$vt_image = array (
'url' => $cropped_img_url,
'width' => $width,
'height' => $height
);
return $vt_image;
}
// $crop = false
if ( $crop == false ) {
// calculate the size proportionaly
$proportional_size = wp_constrain_dimensions( $image_src[1], $image_src[2], $width, $height );
$resized_img_path = $no_ext_path.'-'.$proportional_size[0].'x'.$proportional_size[1].$extension;
// checking if the file already exists
if ( file_exists( $resized_img_path ) ) {
$resized_img_url = str_replace( basename( $image_src[0] ), basename( $resized_img_path ), $image_src[0] );
$vt_image = array (
'url' => $resized_img_url,
'width' => $proportional_size[0],
'height' => $proportional_size[1]
);
return $vt_image;
}
}
// no cache files - let's finally resize it
$new_img_path = image_resize( $file_path, $width, $height, $crop );
if ( is_string($new_img_path) == false ) { return ''; }
$new_img_size = getimagesize( $new_img_path );
$new_img = str_replace( basename( $image_src[0] ), basename( $new_img_path ), $image_src[0] );
// resized output
$vt_image = array (
'url' => $new_img,
'width' => $new_img_size[0],
'height' => $new_img_size[1]
);
return $vt_image;
}
// default output - without resizing
$vt_image = array (
'url' => $image_src[0],
'width' => $image_src[1],
'height' => $image_src[2]
);
return $vt_image;
}
}
/* Returns current page url
---------------------------------------------------------- */
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") { $pageURL .= "s"; }
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
---AND FINALLY THE MASONRY FLUID THEME FILE---
<?php
$def_teaser_width = ( $dtw = get_option('wpb_post_teaser_width') ) ? $dtw : 'two-third';
if ( get_option('wpb_blog_layout') == __("Masonry", "wpb") ) {
$gallery_style = 'masonry';
} else {
$gallery_style = 'fluid';
}
if ( $_GET['style'] == 'masonry' ) {
$gallery_style = 'masonry';
} else if ( $_GET['style'] == 'fluid' ) {
$gallery_style = 'fluid';
}
$holder_class = ( $gallery_style == 'masonry' ) ? 'masonry_blocks' : 'float_blocks';
?>
<?php get_header(); ?>
<div class="float_blocks_container">
<div class="blog_teasers <?php echo $holder_class; ?>">
<?php if (have_posts()) :
$teasers_count = 0;
?>
<?php while (have_posts()) : the_post(); ?>
<?php
$teasers_count++;
$teaser_width = ( $tw = get_post_meta($post->ID, "_teaser_width", true) ) ? $tw : $def_teaser_width;
$teaser_width = ( $teaser_width == 'default' ) ? $def_teaser_width : $teaser_width;
//$teaser_width = ($teaser_w = get_post_meta($post->ID, "_teaser_width", true)) ? ' '.$teaser_w : ' one-half';
if ( $teaser_width == 'one-third' || ( $gallery_style == 'masonry' && $teaser_width == 'one-half' )) {
$th_w = 320;
$th_h = 180;
}
else if ( $teaser_width == 'one-half' ) {
$th_w = 495;
$th_h = 278;
}
else if ( $teaser_width == 'two-third' || ( $gallery_style == 'masonry' && $teaser_width == 'full-width' ) ) {
$th_w = 670;
$th_h = 377;
}
else if ( $teaser_width == 'full-width' ) {
$th_w = 1020;
$th_h = 574;
}
$content_type = (get_option('wpb_full_content') == 'true') ? ' full_content_in_blog' : '';
$has_thumbnail = '';
if (has_post_thumbnail() == false) { $has_thumbnail = ' no_thumbnail'; }
?>
<div id="post-<?php the_ID(); ?>" <?php post_class("post_teaser float_block ".$teaser_width.$has_thumbnail.$content_type); ?>>
<?php
$video_w = $th_w;
$video_h = $th_h;
$p_video = get_post_meta($post->ID, "_p_video", true);
$youtube = strpos($p_video, 'youtube.com');
$vimeo = strpos($p_video, 'vimeo');
if ( $youtube || $vimeo ) : ?>
<div class="p_video">
<?php
if ( $youtube ) {
preg_match('/[\\?\\&]v=([^\\?\\&]+)/', $p_video, $matches);
echo '<iframe width="'.$video_w.'" height="'.$video_h.'" src="http://www.youtube.com/embed/'.$matches[1].'" frameborder="0" allowfullscreen></iframe>';
}
else if ( $vimeo ) {
preg_match('#vimeo.com/([A-Za-z0-9\-_]+)?#s', $p_video, $matches);
echo '<iframe src="http://player.vimeo.com/video/'.$matches[1].'?title=0&byline=0&portrait=0" width="'.$video_w.'" height="'.$video_h.'" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>';
}
?>
</div>
<?php endif; ?>
<?php if ( $has_thumbnail == '' && $youtube == false && $vimeo == false) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php
$th_id = get_post_thumbnail_id();
$image_src = wp_get_attachment_image_src( $th_id, 'full' );
$th_h = 220;
$image = wpb_resize( $th_id, '', $th_w, $th_h, true );
if ($image['url']) : ?>
<img class="post_teaser_img" src="<?php echo $image['url']; ?>" alt="" />
<?php endif; ?>
</a>
<?php endif; ?>
<div class="teaser_content">
<h2 class="post_title"><?php the_title(); ?></h2>
<div class="post_info">
<span class="light"><?php _e("Posted by", "wpb"); ?></span> <?php the_author(); ?> <span class="light"><?php _e("in", "wpb"); ?></span> <?php wpb_posted_under(); ?> <span class="date"><span class="light"><?php _e("on ", "wpb"); ?></span><?php the_time('F j, Y'); ?></span>
</div>
<?php
if ($content_type == ' full_content_in_blog') {
the_content('');
} else {
the_excerpt('');
}
?>
</div> <!-- end .teaser_content -->
<div class="teaser_meta">
<a class="read_more" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php _e("Read more...", "wpb"); ?></a>
<span class="comment_balloon"><?php comments_popup_link( __( 'Leave a comment', 'wpb' ), __( '1 Comment', 'wpb' ), __( '% Comments', 'wpb' ) ); ?></span>
<div class="social_buttons">
<?php echo do_shortcode('[vc_facebook type="button_count" url="'.get_permalink().'"]'); ?>
<?php echo do_shortcode('[vc_tweetmeme]'); ?>
</div>
<div class="wpb_clear"></div>
</div> <!-- end .teaser_ment -->
</div> <!-- end .post_teaser -->
<?php
endwhile;
endif;
?>
<?php if ( $teasers_count > 1 && $gallery_style != 'masonry') : ?>
<a id="float_prev" class="tooltip" title="<?php _e("Previous post", "wpb"); ?>"></a>
<a id="float_next" class="tooltip" title="<?php _e("Next post", "wpb"); ?>"></a>
<?php endif; ?>
<?php if ( $gallery_style != 'masonry' ) { wpb_pagination(); } ?>
<div class="wpb_clear"></div>
</div> <!-- end main_content -->
<?php
if ( $gallery_style == 'masonry' ) {
echo '<div class="masonry_paginator">';
wpb_pagination();
echo '</div>';
}
?>
<div class="wpb_clear"></div>
</div> <!-- end container_12 -->
<?php get_footer(); ?>
You can solve this by making sure all the excerpts, as the auto-generated short intro-texts are called, are the same length. Also, there is HTML markup in these excerpts, which is not a good idea if you want consistent use of space. So, here we go.
In your theme's functions.php you should add the following:
function my_new_excerpt_length($length) {
return 20;
}
add_filter( 'excerpt_length', 'my_new_excerpt_length', 999 );
Here, my_new_excerpt_length is the custom name of your function. The 20 is the amount of words you would like your excerpt to be. You can tweak these values, of course. Just experiment until it fits your needs.
Note: It might be that the changes are not showing up for you on that specific page. Please post the complete template, so I can take a look at what's happening further down the page.