I'm looking for a way to exclude categories with ID 3 and 4 from get_category_parents of my breadcrumb theme. This is the code, The line in question is the 11:
function the_breadcrumb() {
global $post;
if (!is_home()) {
echo ''.home.'';
if (is_category()) {
echo " / ";
echo single_cat_title();
} elseif(is_single() && !is_attachment()) {
$cat = get_the_category(); $cat = $cat[0];
echo " / ";
echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
echo " / ";
echo thman_get_limited_string($post->post_title,30);
}
elseif (is_search()) {
echo " / " . cerca;
}
elseif (is_page() && $post->post_parent) {
echo ' / <a href="'.get_permalink($post->post_parent).'">';
echo get_the_title($post->post_parent);
echo "</a> / ";
echo thman_get_limited_string($post->post_title,30);
}
elseif (is_page() OR is_attachment()) {
echo " / ";
echo thman_get_limited_string($post->post_title,30);
}
elseif (is_author()) {
echo wp_title(' / Profilo');
echo "";
}
elseif (is_404()) {
echo " / ";
echo errore_404;
}
elseif (is_archive()) {
echo wp_title(' / ');
}
}
}
$cat = get_the_category();
$cat = $cat[0]->term_id;
// next will return an array of all category ancestors, with toplevel cat being [0]
$ancestors = array_reverse(get_ancestors($cat, 'category'));
if($ancestors) {
// set up output
$output = '';
foreach($ancestors as $cat) {
// skips cats 3 and 4
if($cat == '3' || $cat == '4') continue;
$catlink = get_category_link($cat);
$catname = get_cat_name($cat);
$output .= '' . $catname . '' . "\n";
}
}
echo $output;
That's off the top of my head, but I believe it's correct.
thanks shelly the answer, but I'm not an expert in php, so my full code should look like this?
function the_breadcrumb() {
global $post;
if (!is_home()) {
echo ''.home.'';
if (is_category()) {
echo " / ";
echo single_cat_title();
} elseif(is_single() && !is_attachment()) {
$cat = get_the_category(); $cat = $cat[0]->term_id;
// next will return an array of all category ancestors, with toplevel cat being [0]
$ancestors = array_reverse(get_ancestors($cat, 'category');
if($ancestors) {
// set up output
$output = '';
foreach($ancestor as $cat) {
// skips cats 3 and 4
if($cat == '3' || $cat == '4') continue;
$catlink = get_category_link($cat);
$catname = get_cat_name($cat);
$output .= '' . $catname . '' . "\n";
}
}
echo $output;
echo " / ";
echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
echo " / ";
echo the_title_shorten(45,'...');
}
elseif (is_search()) {
echo " / " . cerca;
}
elseif (is_page() && $post->post_parent) {
echo ' / <a href="'.get_permalink($post->post_parent).'">';
echo get_the_title($post->post_parent);
echo "</a> / ";
echo the_title_shorten(45,'...');
}
elseif (is_page() OR is_attachment()) {
echo " / ";
echo the_title_shorten(45,'...');
}
elseif (is_author()) {
echo wp_title(' / Profilo');
echo "";
}
elseif (is_404()) {
echo " / ";
echo errore_404;
}
elseif (is_archive()) {
echo wp_title(' / ');
}
}
}
Thanks for all of you,
I finally get the code working:
$ancestors = array_reverse(get_ancestors(get_cat_ID(single_cat_title("", false)), 'category'));
$cat_parent_and_cat = '';
if($ancestors) {
foreach($ancestors as $cat) {
//if($cat == '3' || $cat == '4') continue; // skips cats 3 and 4
$catlink = get_category_link($cat);
$catname = get_cat_name($cat);
$cat_parent_and_cat .= '' . $catname . '' . ' › ' ;
}
}
echo $cat_parent_and_cat;
Hope it will help someone
Related
This code perfectly doing listing users, and remove users with short code. But i have an author directory plugin, and i can list my user with additional meta data. So i want to remove user on my author directory plugin. At the bellow, there is my author directory plugins codes, how can i combine this funciton.
add_action( 'wp_head', 'my_action_javascript' );
function my_action_javascript() {
?>
<script type="text/javascript" >
jQuery(document).ready(function() {
jQuery(".delete_user").click(function() {
var current_element_var = jQuery(this);
var data = {
'action': 'delete_user_action',
'user_id': current_element_var.attr('delete-user-id'),
'security': '<?php echo wp_create_nonce( "security-special-string" ) ?>'
};
jQuery.post('<?php echo admin_url( 'admin-ajax.php' ) ?>', data, function(response) {
if (response == 'deleted_successfully') {
current_element_var.hide();
current_element_var.after('<span> User Deleted Successfully </span>');
current_element_var.remove();
}
});
return false;
});
});
</script>
<?php
}
add_action( 'wp_ajax_delete_user_action', 'delete_user_action_callback' );
add_action( 'wp_ajax_nopriv_delete_user_action', 'delete_user_action_callback' );
function delete_user_action_callback() {
check_ajax_referer( 'security-special-string', 'security' );
wp_delete_user( $_POST['user_id'] );
echo 'deleted_successfully';
die();
}
add_shortcode('listuser', 'listsubscriber');
function listsubscriber() {
$blogusers = get_users( array( 'fields' => array('display_name','ID' )) );
echo '<ul>';
foreach ( $blogusers as $user ) {
echo '<li>' . esc_html( $user->display_name ) . '|' . esc_html( $user->ID ) . '<a class="delete_user" delete-user-id="' . $user->ID . '" href="#">Delete User</a></li>';
}
echo '</ul>';
}
Author list plugin codes at here.
require_once("rules/useroles.php");
require_once("admin/admin.php");
function member_directory_loader_scripts()
{
wp_register_style( 'directorycss', plugin_dir_url( __FILE__ ).'asset/js/jdirectory/directory.css');
wp_enqueue_style( 'directorycss' );
wp_register_script( 'directoryjs', plugin_dir_url( __FILE__ ).'asset/js/jdirectory/jquery.directory.js', array('jquery'));
wp_enqueue_script( 'directoryjs' );
}
add_action( 'wp_enqueue_scripts', 'member_directory_loader_scripts' );
function member_directory_shortcode($atts)
{
global $table_prefix,$wpdb,$post;
$return_content = '';
$return_content .= '<div class="member_directory_table">';
$results = get_users();
if ((!(empty($results))) && (is_array($results)) && (count($results) >0))
{
$m_single = array();
foreach ($results as $single)
{
$user_allowed_listed = true;
$memberDirectoryUserRoleSelect = get_option('memberDirectoryUserRoleSelect');
if (empty($memberDirectoryUserRoleSelect))
{
}
else
{
$user_allowed_listed = check_user_role_allowed($single);
if ($user_allowed_listed == false)
{
continue;
}
}
$return_content .= '<div class="tooltips_list">';
$return_content .= '<span class="tooltips_table_items">';
$return_content .= '<div class="tooltips_table">';
$return_content .= '<div class="tooltips_table_title">';
$enabGlossaryIndexPage = get_option("enabGlossaryIndexPage");
$return_content .= $single->display_name;
$return_content .='</div>';
$return_content .= '<div class="billing">';
$return_content .= $single->billing_address_1;
$return_content .='</div>';
***** i want to at there remove user link with ajax ******
$return_content .= '<div class="billing2">';
$return_content .= $single->billing_company;
$return_content .='</div>';
$return_content .= '<div class="billing3">';
$return_content .= $single->ID;
$return_content .='</div>';
$return_content .= '<div class="tooltips_table_content">';
// old $m_content = $single->user_email;
// 1.3.1
$m_content = '';
$m_content_user_email = $single->user_email;
$m_content_user_bio_in_wp = get_the_author_meta('description',$single->ID);
$m_content .= "<div class = 'member_content_user_email'>";
$m_content .= $m_content_user_email;
$m_content .= "</div>";
$m_content .= "<div class = 'member_content_user_description'>";
$m_content .= $m_content_user_bio_in_wp;
$m_content .= "</div>";
$return_content .= $m_content;
$return_content .='</div>';
$return_content .='</div>';
$return_content .='</span>';
$return_content .='</div>';
}
}
$return_content .= '</div>';
return $return_content;
}
add_shortcode( 'member_directory', 'member_directory_shortcode',10 );
function member_directory_load_footer_js()
{
global $post;
?>
<script type="text/javascript">
var inboxs = new Array();
inboxs['hidezeronumberitem'] = "yes";
inboxs['selectors'] = '.tooltips_list > span';
<?php
$glossaryNavItemFontSize = '12px';
$glossarySelectedNavItemFontSize = get_option("glossarySelectedNavItemFontSize");
$glossarySelectedNavItemFontSize = '14px';
$glossaryNavItemFontSize = '12px';
?>
inboxs['navitemdefaultsize'] = '<?php echo $glossaryNavItemFontSize; ?>';
inboxs['navitemselectedsize'] = '<?php echo $glossarySelectedNavItemFontSize; ?>';
<?php
$glossaryNumbersOrNot = 'no';
if ($choseLanguageForGlossary == 'custom')
{
$glossaryLanguageCustomNavLetters = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z';
?>
inboxs['alphabetletters'] = "<?php echo $glossaryLanguageCustomNavLetters; ?>";
<?php
}
?>
inboxs['number'] = "no";
jQuery(document).ready(function () {
jQuery('.member_directory_table').directory(inboxs);
jQuery('.navitem').css('font-size','<?php echo $glossaryNavItemFontSize; ?>');
})
</script>
<?php
}
add_action('wp_footer','member_directory_load_footer_js');
function check_user_role_allowed($checkuser)
{
$memberDirectoryUserRoleSelect = get_option('memberDirectoryUserRoleSelect');
$saved_allowed_user_roles_in_member_directory = get_option('saved_allowed_user_roles_in_member_directory');
if (empty($memberDirectoryUserRoleSelect))
{
return true;
}
else
{
if ('enableMemberDirectoryUserRolesOption' == $memberDirectoryUserRoleSelect)
{
$can_listed = false;
$checking_user_roles = $checkuser->roles;
if (empty($checking_user_roles))
{
return false ;
}
else
{
foreach ($checking_user_roles as $checking_user_role)
{
if (in_array(strtolower($checking_user_role), $saved_allowed_user_roles_in_member_directory) )
{
$can_listed = true;
return true;
}
}
}
}
if ('disableMemberDirectoryUserRolesOption' == $memberDirectoryUserRoleSelect)
{
$can_listed = true;
$checking_user_roles = $checkuser->roles;
if (empty($checking_user_roles))
{
return false ;
}
else
{
foreach ($checking_user_roles as $checking_user_role)
{
if (in_array(strtolower($checking_user_role), $saved_allowed_user_roles_in_member_directory) )
{
$can_listed = false;
return false;
}
}
}
}
return $can_listed;
}
}
like so
Am guessing that $single->ID contains the User ID. If so, in that place where you marked in code, you could add the delete button.
It would be something like this:
$return_content .= '<div class="billing">';
$return_content .= $single->billing_address_1;
$return_content .='</div>';
/***** i want to at there remove user link with ajax ******/
/*--------- delete button ------------*/
$return_content .= '<button class="delete_user" delete-user-id="'. $single->ID .'">Delete</button>';
/*--------- /delete button ------------*/
$return_content .= '<div class="billing2">';
$return_content .= $single->billing_company;
$return_content .='</div>';
You are already listening to the click event of the class delete_user. And inside it, you are expecting the delete-user-id to have the user_id of the User whom you want to delete! Hence we are using both in our button.
One thing I noticed in code is the add_action( 'wp_ajax_nopriv_delete_user_action', 'delete_user_action_callback' ); This will allow non-logged in users to perform this delete operation because of the wp_ajax_nopriv_*
This hook is functionally the same as wp_ajax_{$action}, except the
“nopriv” variant is used for handling AJAX requests from
unauthenticated users, i.e. when is_user_logged_in() returns false.
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();
}
remove_action is not working I have tried to remove acf_woocommerce_add_fields_to_order using following code
remove remove_action( 'acf_woocommerce_add_fields_to_order', array( ACF_Woo_API::get_instance(), 'acf_woocommerce_add_fields_to_order' ) );
But this is not working kindly help.
The function that I would like to remove from the plugin is as following
public function acf_woocommerce_add_fields_to_order() {
$api = ACF_Woo_API::get_instance();
$group_keys = wp_list_pluck($api->get_field_groups(), $api->acf_id_case_sensitive());
foreach ($group_keys as $group_key => $key) {
$fields = $api->get_field_group_fields($key);
foreach ($fields as $field => $value) {
$field_label = $value['label'];
$raw_meta = base64_decode(get_post_meta(get_the_ID(), $value['key'], true));
$meta = unserialize($raw_meta);
if (is_array($meta)) {
//handle repeater, flexible content
if (is_array(reset($meta))) {
echo '<table style="border-collapse: collapse; width: 100%">';
foreach ($meta as $row) {
echo '<tr>';
foreach ($row as $column) {
echo "<td style='border: 1px solid black;'>$column</td>";
}
echo '</tr>';
}
echo '</table>';
} //handle choice and select
else {
echo '<p><strong>' . $field_label . ': </strong>' . implode('; ', $meta) . '</p>';
}
} else {
$meta = stripcslashes($meta);
echo '<p><strong>' . $field_label . ': </strong>' . $meta . '</p>';
}
}
}
}
Was trying
remove_action( 'acf_woocommerce_add_fields_to_order', array( ACF_Woo_API::get_instance(), 'acf_woocommerce_add_fields_to_order' ) );
but unable to do it.
Hoping to learn more. Thanks!
Sorry if this question seems redundant but in looking around, I am finding that there are a lot of questions around conditional CSS per browsers, as opposed to, OS.
Is there any way to simply load a different style sheet per OS? (I'm trying to circumvent pixel-walking backgrounds on Mac.) I would preferably need an option that integrates well into a Wordpress child-theme.
Thank you!
the best way is to break it down by user agent and then serve up a different stylesheet. If your using wordperss this will be PHP. #
$_SERVER['HTTP_USER_AGENT']
http://php.about.com/od/learnphp/p/http_user_agent.htm
I had this same question a few years ago. I had to search a while to find the article again, so here's the code from the article:
function get_broswer_stylesheet ($test_by = 'browser')
{
$broswer = array(
'MSIE', // parent
'OPERA',
'MOZILLA',
'NETSCAPE',
'FIREFOX',
'SAFARI',
'CHROME'
);
$os = array(
'MAC',
'WINDOWS',
'LINUX'
);
$info[browser] = 'OTHER';
$info[os] = 'OTHER';
$user_agent = $_SERVER['HTTP_USER_AGENT'];
foreach ($broswer as $parent)
{
$s = strpos(strtoupper($user_agent), $parent);
$f = $s + strlen($parent);
$version = substr($user_agent, $f, 5);
$version = preg_replace('/[^0-9,.]/', '', $version);
if (strpos(strtoupper($user_agent), $parent))
{
$info[browser] = $parent;
$info[version] = $version;
}
}
foreach ($os as $parent)
{
if (strpos(strtoupper($user_agent), $parent))
{
$info[os] = $parent;
}
}
if ($test_by == 'browser' || $test_by == 'os')
{
$string = '<link rel="stylesheet" type="text/css" href="' . get_bloginfo('template_directory') . '/css/';
if ($test_by == 'browser')
{
if ($info[browser] == 'MSIE') {
switch ($info[version])
{
case 9 : $string .= 'ie9.css'; break;
case 8 : $string .= 'ie8.css'; break;
case 7 : $string .= 'ie7.css'; break;
default: $string .= 'ie6.css'; break;
}
} elseif ( $info[browser] == 'FIREFOX') {
$string .= 'firefox.css';
} elseif ($info[browser] == 'SAFARI') {
$string .= 'safari.css';
} elseif ($info[browser] == 'CHROME') {
$string .= 'chrome.css';
} else {
$string .= 'style.css';
}
} elseif ($test_by == 'os') {
if ($info[os] == 'MAC') {
$string .= 'mac.css';
} elseif ($info[os] == 'WINDOWS') {
$string .= 'windows.css';
} elseif ($info[os] == 'LINUX') {
$string .= 'linux.css';
} else {
$string .= 'style.css';
}
}
$string .= '">';
return $string;
}
}
I hope that helps. You can set the $test_by parameter to either browser or os and it'll try to deliver the right stylesheet.
I am using the following code in my WP theme functions.php page and it works perfectly in all browsers but does not always show up in Safari, where it is intermittent.
When it does not show up on the page, it is in the code, if I look at the source code.
function custom_wp_pagenavi($before = '', $after = '', $prelabel = '', $nxtlabel = '', $pages_to_show = 5, $always_show = false) {
global $request, $posts_per_page, $wpdb, $paged;
if(empty($prelabel)) {
$prelabel = '<strong>«</strong>';
}
if(empty($nxtlabel)) {
$nxtlabel = '<strong>»</strong>';
}
$half_pages_to_show = round($pages_to_show/2);
if (!is_single()) {
if(!is_category()) {
preg_match('#FROM\s(.*)\sORDER BY#siU', $request, $matches);
} else {
preg_match('#FROM\s(.*)\sGROUP BY#siU', $request, $matches);
}
$fromwhere = $matches[1];
$numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere");
$max_page = ceil($numposts /$posts_per_page);
if(empty($paged)) {
$paged = 1;
}
if($max_page > 1 || $always_show) {
echo "$before <div class=\"wp-pagenavi\"><span class=\"pages\">Page $paged of $max_page:</span>";
if ($paged >= ($pages_to_show-1)) {
echo '« First';
}
previous_posts_link($prelabel);
for($i = $paged - $half_pages_to_show; $i <= $paged + $half_pages_to_show; $i++) {
if ($i >= 1 && $i <= $max_page) {
if($i == $paged) {
echo "<strong class='current'>$i</strong>";
} else {
echo ' '.$i.' ';
}
}
}
next_posts_link($nxtlabel, $max_page);
if (($paged+$half_pages_to_show) < ($max_page)) {
echo 'Last »';
}
echo "</div> $after";
}
}
}
<?php if (function_exists('custom_wp_pagenavi')) : ?>
<?php custom_wp_pagenavi(); ?>
Any suggestions would be greatly appreciated.