how to create tab menu in admin page wordpress - php

this is my update code
if (is_admin())
{
add_action('admin_menu', 'user_menu');
}
function user_menu()
{
add_menu_page('Pesananku', 'Pesananku', 'subscriber', 'userslug',
'user_funct',get_template_directory_uri().'/img/favicon.ico',22);
}
function user_funct()
{
?>
<h2 class="nav-tab-wrapper">
Tab #1
Tab #2
Tab #3
</h2>
<div id="tab1"><!--content tab1--></div>
<div id="tab2"><!--content tab2--></div>
<div id="tab3"><!--content tab3--></div>
<?php
}
i want 'user_funct()' create tab with styling wordpress like this
http://postimg.org/image/h3nttjhof/
how to create different content with link tab menu
Thanks

Here is how you can go about it;
First, you need to create a function that create the structure depending on the current tab selected:
function page_tabs( $current = 'first' ) {
$tabs = array(
'first' => __( 'First tab', 'plugin-textdomain' ),
'second' => __( 'Second tab', 'plugin-textdomain' )
);
$html = '<h2 class="nav-tab-wrapper">';
foreach( $tabs as $tab => $name ){
$class = ( $tab == $current ) ? 'nav-tab-active' : '';
$html .= '<a class="nav-tab ' . $class . '" href="?page=ipl_dbx_import_export&tab=' . $tab . '">' . $name . '</a>';
}
$html .= '</h2>';
echo $html;
}
Then in the callback function called to display the page which will contain the tabs, you need to use this function like that:
<?php
// Code displayed before the tabs (outside)
// Tabs
$tab = ( ! empty( $_GET['tab'] ) ) ? esc_attr( $_GET['tab'] ) : 'first';
page_tabs( $tab );
if ( $tab == 'first' ) {
// add the code you want to be displayed in the first tab
}
else {
// add the code you want to be displayed in the second tab
}
// Code after the tabs (outside)
?>
Also then you call the page, you can add a GET value called tab corresponding to the tab you want to display, e.g.:
admin.php?page=my_plugin_page_slug&tab=second

Related

Add an action button with a unique CSS class to WooCommerce my account orders

Here is my function for adding an option to my orders page:
add_filter( 'woocommerce_my_account_my_orders_actions', 'add_my_account_my_orders_custom_action', 10, 2 );
function add_my_account_my_orders_custom_action( $actions, $order ) {
$action_slug = 'specific_name';
$actions[$action_slug] = array(
'url' => home_url('/the_action_url/'),
'name' => 'The Button Text',
);
return $actions;
}
My question is this : How Can I add my custom CSS to ONLY my newly created option
(There are 3 other buttons except my button that I do not want to change their style and all 4 of them have same class).
Using $action_slug = 'specific_name'; will automatically add this as a class to the button.
Then you can use the following selector
.woocommerce-account table.account-orders-table .specific_name {
color: red;
}
To apply CSS specifically or to overwrite existing CSS
To do the reverse and remove certain classes for this particular button, you need to overwrite the template file /myaccount/orders.php in addition to your existing code
This template can be overridden by copying it to yourtheme/woocommerce/myaccount/orders.php.
Replace line 69 - 71 #version 3.7.0
foreach ( $actions as $key => $action ) { // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
echo '' . esc_html( $action['name'] ) . '';
}
With
foreach ( $actions as $key => $action ) { // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
// Compare
if ( $key == 'specific_name' ) {
echo '' . esc_html( $action['name'] ) . '';
} else {
echo '' . esc_html( $action['name'] ) . '';
}
}
When displaying the buttons on the frontend, the action key is assigned as a classname, so you can assign different CSS based on action key like this:
.shop_table .button.specific_name {
color: #fff;
}

How do I make the following heading output the title in an h4 tag instead of h2 using a child theme?

So I want the sidebar heading to be in an h4 tag this is how the site structure is currently looking
Here is the code where the title is being pulled from :
genesis_markup(
[
'open' => '<aside %s>' . genesis_sidebar_title( 'sidebar' ),
'context' => 'sidebar-primary',
]
You can use genesis_sidebar_title_output filter to modify the output of genesis_sidebar_title function.
Use the snippet below to switch the tag for all sidebar titles to h4:
<?php
add_filter('genesis_sidebar_title_output', 'so_modify_sidebar_title', 10, 2);
function so_modify_sidebar_title($heading, $id) {
global $wp_registered_sidebars;
$name = $id;
if ( array_key_exists( $id, $wp_registered_sidebars ) ) {
$name = $wp_registered_sidebars[ $id ]['name'];
$heading = '<h4 class="genesis-sidebar-title screen-reader-text">' . $name . '</h4>';
}
return $heading;
}

Implementing a Wordpress custom function

Site I’m working on is a radio show. I have a bunch of custom fields, courtesy of Advanced Custom Fields, for links to musicians’ websites, social profiles, etc.. For the last few years, we’ve used a Genesis child theme to display them, and the code I adapted worked great. The radio show’s host/producer now wants to move to a non-Genesis theme, and I’m having some trouble making it work.
Here’s an example from the site we’re migrating FROM, which includes the functioning code. (The Artist Links box, floated to the right of the main copy.)
Here’s the same post at the new site, where the code doesn’t yet display. (It will display in the same place.) FWIW, the theme is GrandBlog.
Here’s the code:
<?php
add_action ('if_artist_links');
function if_artist_links() {
// These are the custom field keys defined in the dashboard:
$metas_links = array(
'website',
'album',
'tour',
'twitter',
'facebook',
'bandcamp',
'soundcloud',
'youtube',
'instagram',
'linkedin',
'myspace',
'image',
);
// If _any_ ACF field is filled in, it's a go.
$has_meta = false; // init
foreach ($metas_links as $test ) {
if ( get_field($test) ) {
$has_meta = true;
continue; // Just need one meta field filled to create the div.
}
}
if ( $has_meta ) {
echo '<div class="custom-data artist-links">';
echo '<h2 class="artistname">' ?> <?php the_field('name') ?></h2>
<center><strong> <?php the_field('tribe') ?></strong></center> <?php
foreach ( $metas_links as $meta_links ) {
$$meta_links = get_field($meta_links);
if ( $$meta_links ) {
$f_object = get_field_object($meta_links);
$label = $f_object['label'];
echo '<div class="' . $meta_links . '">' .
'<span class="label">' . $label . '</span>' .
'</div>';
}
}
echo '</div><!-- /.custom-data -->';
}
}
?>`
Where there’s an ACF value, a link is created. Where there’s no ACF value, there’s no link. Just one link is required to make the box appear.
As far as I can tell, I’m not telling the code to run, or run in the right way. If you can help me do that, I’ll sing your praises through the weekend.
If possible, I’d really like to wrap this up in a WP plugin, for simplicity and ease of maintenance, and to put minimal code in single.php.
Thanks so much for your help!
You need to use WordPress the_content hook. Replace this in your theme's 'functions.php'.
function single_add_to_content( $content ) {
if( is_single() ) {
// These are the custom field keys defined in the dashboard:
$metas_links = array(
'website',
'album',
'tour',
'twitter',
'facebook',
'bandcamp',
'soundcloud',
'youtube',
'instagram',
'linkedin',
'myspace',
'image',
);
// If _any_ ACF field is filled in, it's a go.
$has_meta = false; // init
foreach ($metas_links as $test ) {
if ( get_field($test) ) {
$has_meta = true;
continue; // Just need one meta field filled to create the div.
}
}
if ( $has_meta ) {
$content.= '<div class="custom-data artist-links">';
$content.= '<h2 class="artistname">'.get_field('name').'</h2>
<center><strong>'.get_field('tribe').'</strong></center>';
foreach ( $metas_links as $meta_links ) {
$$meta_links = get_field($meta_links);
if ( $$meta_links ) {
$f_object = get_field_object($meta_links);
$label = $f_object['label'];
$content.= '<div class="' . $meta_links . '">' .
'<span class="label">' . $label . '</span>' .
'</div>';
}
}
$content.= '</div><!-- /.custom-data -->';
}
}
return $content;
}
add_filter( 'the_content', 'single_add_to_content' );
Or you can copy 'single.php' to your child theme and add this code directly without function.

Automate Unique ID On Class & Help Make Each Button Separately Modifiable

I'm using wordpress, I've a content box plugin WP Boxer, I would like to take control of each individual button in each box created.
So I wanted to create a separate class for every button, right now they are all under the same class.
Here's how it is now:
$box['content']['text'] = $excerpt. '<div class="clearboth"></div>
'. sprintf('%s »', __('Read More', WPBOXER_ADMIN_TEXTDOMAIN)). ''. trim( $block_link );
And this is what i tried but it didn't work
$box['content']['text'] = $excerpt. '<div class="clearboth"></div>'
$i = 0;
if ( count($links) > 0 ) {
foreach( $links as $id ) {
. sprintf('%s »', __('Read More', WPBOXER_ADMIN_TEXTDOMAIN)). ''. trim( $block_link );
$i++;
}
Try including
id="<?php echo $i; ?>"
inside the tag instead of putting it in the class

Image in recent post of Wordpress Q and A theme

i am using Instant-QA theme, need to update the recent Post widget with image of the user who has asked the questions. I am using the below code in functions.php of subdomain of wordpress website. Currently its showing the simple post--- Any guess in below code-- ?
function print_requested_template_part() {
// Respond only to requests from the same address...
if ( $_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['including_template_part']) && isset($_GET['load_part']) && $_GET['load_part'] != '' ) {
$part = $_GET['load_part'];
$func = 'render_' . str_replace('-', '_', $part); // if you have declared a function called "render_footer_include", then "?load_part=footer_include"
if ( function_exists($func) ) {
// Allow for passing parameters to the function
if ( isset($_GET['params']) ) {
$params = $_GET['params'];
$params = ( strpos($params, ',') !== false )? explode(',', $params) : array($params);
call_user_func_array($func, $params);
} else {
call_user_func($func);
}
}
exit; // if we don't exit here, a whole page will be printed => bad! it's better to have empty footer than a footer with the whole main site...
}
}
add_action('init', 'print_requested_template_part', 1);
function render_my_recent_posts( $numberposts = 5 ) { ?>
<ul>
<?php
$args = array( 'numberposts' => '5' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ) {
echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . $recent["post_title"].'</a> </li> ';
}
?>
</ul><?php
}
DO not waste you time to indulge urself in the above code. Usel below plugin and gets the immediate output.
http://wordpress.org/extend/plugins/recent-comments-with-avatars/ Use this plugin
Thankyou

Categories