www.91084.com

GVKun编程网logo

如何在 wordpress 仪表板的导航菜单中添加项目?(wordpress仪表盘在哪)

12

本文的目的是介绍如何在wordpress仪表板的导航菜单中添加项目?的详细情况,特别关注wordpress仪表盘在哪的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解如

本文的目的是介绍如何在 wordpress 仪表板的导航菜单中添加项目?的详细情况,特别关注wordpress仪表盘在哪的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解如何在 wordpress 仪表板的导航菜单中添加项目?的机会,同时也不会遗漏关于php – 在WordPress注册表单中添加名字和姓氏、php – 如何在WordPress / WooCommerce 3中的注释表单中添加自定义字段、php – 如何在wordpress菜单中为仪表板添加id?、php – 如何在我的WordPress菜单中添加父菜单描述?的知识。

本文目录一览:

如何在 wordpress 仪表板的导航菜单中添加项目?(wordpress仪表盘在哪)

如何在 wordpress 仪表板的导航菜单中添加项目?(wordpress仪表盘在哪)

如何解决如何在 wordpress 仪表板的导航菜单中添加项目??

如何添加按钮或链接到导航菜单项的区域,我在 wordpress 仪表板下面的图像中引用它?

我可以使用什么钩子或函数?

enter image description here

解决方法

使用自定义链接选项,在那里添加您的链接并为该菜单提供一些 id,使用其他 css 将其样式设置为按钮。您还可以使用超级菜单插件进行高级菜单样式和创建。

php – 在WordPress注册表单中添加名字和姓氏

php – 在WordPress注册表单中添加名字和姓氏

我在WP上的注册表只有用户名,电子邮件和密码选项.

//1. firstname

add_action(‘register_form’,’myplugin_register_form’);
function myplugin_register_form(){

$first_name = ( ! empty( $_POST['first_name'] ) ) ? trim( $_POST['first_name'] ) : '';

    ?>

    <?PHP
}

//2. Add validation. In this case,we make sure first_name is required.
add_filter( 'registration_errors','myplugin_registration_errors',10,3 );
function myplugin_registration_errors( $errors,$sanitized_user_login,$user_email ) {

    if ( empty( $_POST['first_name'] ) || ! empty( $_POST['first_name'] ) && trim( $_POST['first_name'] ) == '' ) {
        $errors->add( 'first_name_error',__( '<strong>ERROR</strong>: You must include a first name.','mydomain' ) );
    }

    return $errors;
}

//3. Finally,save our extra registration user Meta.
add_action( 'user_register','myplugin_user_register' );
function myplugin_user_register( $user_id ) {
    if ( ! empty( $_POST['first_name'] ) ) {
        update_user_Meta( $user_id,'first_name',trim( $_POST['first_name'] ) );
    }
}

在我的注册表(模板)中,我放置了以下内容:

<label><?PHP _e('First Name',APP_TD) ?></label>
                <input tabindex="3" type="text" name="first_name"id="display_name" value="<?PHP echo esc_attr( wp_unslash( $first_name ) ); ?>" maxlength="100" />

它的工作原理应该如此.它抓取名字并将其放在用户配置文件中.但是我不知道如何将姓氏添加到它,我是一个初学者,由于某种原因我无法得到姓氏.非常感谢帮助.

解决方法

我从来没有在WP上做过类似的事情.你把这个代码放在哪里?

但是我会尝试执行这样的事情:

//1. Fistname

add_action( 'register_form','myplugin_register_form' ); function myplugin_register_form() {

$first_name = ( ! empty( $_POST['first_name'] ) ) ? trim( $_POST['first_name'] ) : '';
$last_name = ( ! empty( $_POST['last_name'] ) ) ? trim( $_POST['last_name'] ) : '';

?>

<?PHP
}

//2. Add validation. In this case,$user_email ) {

    if ( empty( $_POST['first_name'] ) || ! empty( $_POST['first_name'] ) && trim( $_POST['first_name'] ) == '' ) {
    $errors->add( 'first_name_error','mydomain' ) );
    }

    if ( empty( $_POST['last_name'] ) || ! empty( $_POST['last_name'] ) && trim( $_POST['last_name'] ) == '' ) {
    $errors->add( 'last_name_error',__( '<strong>ERROR</strong>: You must include a last name.',trim( $_POST['first_name']  ));
    }

    if ( ! empty( $_POST['last_name'] ) ) {
        update_user_Meta( $user_id,'last_name',trim( $_POST['last_name'] ) );
    }
}

php – 如何在WordPress / WooCommerce 3中的注释表单中添加自定义字段

php – 如何在WordPress / WooCommerce 3中的注释表单中添加自定义字段

Example

我正在尝试在产品评论中添加“电话”字段(WooComerce 3).
*对于未注册的用户(访客).
电话号码只能由管理员在管理面板中查看.

*电话领域需要“必填”.

我试试这段代码,但这不起作用:

function true_phone_number_field( $fields ) {
$fields['phone'] = '<p><label for="phone">Phone</label> <input id="phone" name="phone" type="text" value="" size="30" /></p>';
}
add_filter( 'comment_form_default_fields', 'true_phone_number_field');

解决方法:

    // Add phone number field

    function add_review_phone_field_on_comment_form() {
        echo '<p><label for="phone">' . __( 'Phone', 'text-domain' ) . '</label><spanhttps://www.jb51.cc/tag/required/" target="_blank">required">*</span><inputhttps://www.jb51.cc/tag/dis/" target="_blank">display-block" type="text" name="phone" id="phone"/></p>';
    }
    add_action( 'comment_form_logged_in_after', 'add_review_phone_field_on_comment_form' );
    add_action( 'comment_form_after_fields', 'add_review_phone_field_on_comment_form' );


    // Save phone number
    add_action( 'comment_post', 'save_comment_review_phone_field' );
    function save_comment_review_phone_field( $comment_id ){
        if( isset( $_POST['phone'] ) )
          update_comment_Meta( $comment_id, 'phone', esc_attr( $_POST['phone'] ) );
    }

    function print_review_phone( $id ) {
        $val = get_comment_Meta( $id, "phone", true );
        $title = $val ? '<strong>' . $val . '</strong>' : '';
        return $title;
    }

    // Print phone number - remove if not needed to show in front end
/*
    add_action('woocommerce_review_before_comment_Meta', 'get_comment_phone' );
    function get_comment_phone($comment){
        echo print_review_phone($comment->comment_ID);
    }
*/

//在管理列表表中列出

add_filter('manage_edit-comments_columns', 'my_add_comments_columns');

function my_add_comments_columns($my_cols) {

    $temp_columns = array(
        'phone' => 'Phone'
    );
    $my_cols = array_slice($my_cols, 0, 3, true) + $temp_columns + array_slice($my_cols, 3, NULL, true);

    return $my_cols;
}

add_action('manage_comments_custom_column', 'my_add_comment_columns_content', 10, 2);

function my_add_comment_columns_content($column, $comment_ID) {
    global $comment;
    switch ($column) :

        case 'phone' : {

                echo get_comment_Meta($comment_ID, 'phone', true);
                break;
            }
    endswitch;
}

使用wordpress 5.1和WooCommerce 3.5.5测试好

enter image description here

enter image description here

php – 如何在wordpress菜单中为仪表板添加id?

php – 如何在wordpress菜单中为仪表板添加id?

如何在wordpress菜单中转换此html菜单以及如何启用< a id =“”>?

标记:

<ul>
    <li><a id="home" href="">???</a></li>
    <li><a id="description" href="">???</a></li>
    <li><a id="about" href="">?</a></li>
    <li><a id="shop" href="">????</a></li>
    <li><a id="blog" href="">???</a></li>
</ul>

我正在尝试在header.PHP中创建一个默认的wordpress菜单代码

<?PHP

if (function_exists('wp_nav_menu')) {
    wp_nav_menu(array(
        'theme_location' =>  'wpj-main-menu', 
        'fallback_cb' => 'wpj_default_menu')
    );
}
else {
    wpj_default_menu();
}

?>

add_action('init', 'wpj_register_menu');

function wpj_register_menu() {
    if (function_exists('register_nav_menu')) {
        register_nav_menu( 'wpj-main-menu', __( 'Main Menu', 'brightpage' ) );
    }
}

function wpj_default_menu() {
    echo '<ul>';
    if ('page' != get_option('show_on_front')) {
        echo '<li><a href="'. home_url() . '/">Home</a></li>';
    }
    wp_list_pages('title_li=');
    echo '</ul>';
}

我也正在尝试制作echo’< li>< a id =“home”href =“'.home_url().'/”> Home< / a>< / li>‘;

但是我如何改变那些< a>仪表板中的ID?

请帮我.谢谢.

解决方法:

您可以将Classes添加到每个项目,而不是ID.

在wordpress后端的菜单中,您可以选择屏幕选项并选中css类的复选框.

然后,您就可以为每个菜单项添加唯一的类名.

您的类将添加到LI元素,然后通过执行选择链接

.home a {}

.description a {}

.about a {}

.shop a {}

.blog a {}

php – 如何在我的WordPress菜单中添加父菜单描述?

php – 如何在我的WordPress菜单中添加父菜单描述?

我已经将描述输入到wordpress中的父菜单项中,但它们没有显示在我的主题上.

我知道可以使用walker类来更改菜单,但我不知道如何编写它.

这是我想要实现的目标:

<nav id="main-menu" role="navigation">
<div>
    <ul id="menu-main-menu">
        <!-- REPEATING MENU ITEM START -->
        <li><a>Face</a>
        <ul>
            <li>
                <div></div>
                <div>[Face menu item description]</div>
            </li>
            <lihttps://www.jb51.cc/tag/heading/" target="_blank">heading">Face</li>
            <ul>
                <li>Sub menu 1</li>
                <li>Sub menu 2</li>
                <li>Sub menu 3</li>
            </ul>
            <lihttps://www.jb51.cc/tag/heading/" target="_blank">heading">Ear</li>
            <ul>
                <li>Sub menu 1</li>
                <li>Sub menu 2</li>
                <li>Sub menu 3</li>
            </ul>
            <lihttps://www.jb51.cc/tag/heading/" target="_blank">heading">Eyes</li>
            <ul>
                <li>Sub menu 1</li>
                <li>Sub menu 2</li>
                <li>Sub menu 3</li>
            </ul>
        </ul>
        </li>
        <!-- REPEATING MENU ITEM END -->
    </ul>
</div>

如您所见,我只想显示父菜单项的描述,但它必须位于父列表项中的第一个ul.sub菜单中.

我怎么能编写一个使用start_lvl,start_el和end_lvl来有效处理这个问题的walker?

好吧,我不确定这是否是万无一失的,但这是我的尝试:

因此,您需要确保在管理菜单控制台中显示说明(在“屏幕选项”下拉列表中)

你的第一个菜单项应该是Face then Face再次作为它的孩子然后sub neu项目作为孩子.

希望这可以帮助!

在你的functions.PHP中

class Description_Walker extends Walker_Nav_Menu
{
    /**
     * Start the element output.
     *
     * @param  string $output Passed by reference. Used to append additional content.
     * @param  object $item   Menu item data object.
     * @param  int $depth     Depth of menu item. May be used for padding.
     * @param  array $args    Additional strings.
     * @return void
     */
     function display_element( $element,&$children_elements,$max_depth,$depth=0,$args,&$output )
{
    $id_field = $this->db_fields['id'];
    if ( is_object( $args[0] ) ) {
        $args[0]->has_children = ! empty( $children_elements[$element->$id_field] );
    }
    return parent::display_element( $element,$children_elements,$depth,$output );
}
function start_lvl( &$output,$args=array() ) {
    // depth dependent classes
    $indent = ( $depth > 0  ? str_repeat( "\t",$depth ) : '' ); // code indent
    $display_depth = ( $depth); // because it counts the first submenu as 0
    $classes = array('sub-menu');
    $class_names = implode( ' ',$classes );

    // build html
    $output .= "\n" . $indent . '<ul>' . "\n";
}
    function start_el(&$output,$item,$depth = 0,$args = array(),$current_object_id = 0)
    {

        $classes     = empty ( $item->classes ) ? array () : (array) $item->classes;

        $class_names = join(
            ' ',apply_filters(
                'nav_menu_css_class',array_filter( $classes ),$item
            )
        );

        if ($args->has_children && $depth == 0){
        ! empty ( $class_names )
            and $class_names = '';
        }else if($depth == 1){
         ! empty ( $class_names )
            and $class_names = 'https://www.jb51.cc/tag/heading/" target="_blank">heading"';
        }else{
         ! empty ( $class_names )
            and $class_names = '';  
        }

        $output .= "<li id='menu-item-$item->ID' $class_names>" ;
        $attributes  = '';

        ! empty( $item->attr_title )
            and $attributes .= ' title="'  . esc_attr( $item->attr_title ) .'"';
        ! empty( $item->target )
            and $attributes .= ' target="' . esc_attr( $item->target     ) .'"';
        ! empty( $item->xfn )
            and $attributes .= ' rel="'    . esc_attr( $item->xfn        ) .'"';
        ! empty( $item->url )
            and $attributes .= ' href="'   . esc_attr( $item->url        ) .'"';

        // insert description for top level elements only
        // you may change this
        $description = ( ! empty ( $item->description ) and 0 == $depth )
            ? '<div>' . esc_attr( $item->description ) . '</div>' : '';

        $title = apply_filters( 'the_title',$item->title,$item->ID );
        if (  $depth == 0) {//top level items
         $item_output = $args->before.$title.'</li><ul><li><div></div>'.$description.'</li>';  
        }
        else if(  $depth == 1){
             $item_output = $args->before.$title.'</li>';
        }
        else{//everything else
        $item_output = $args->before
            . "<a $attributes>"
            . $args->link_before
            . $title
            . '</a> '
            . $args->link_after
            . $args->after;
        }
        // Since $output is called by reference we don't need to return anything.
        $output .= apply_filters(
            'walker_nav_menu_start_el',$item_output,$args
        );

    }
}

在标题中(或您的菜单所在的位置)

<nav id="main-menu" role="navigation"><?PHP wp_nav_menu( array('menu' => 'Main','container' => 'div','container_class' => 'menu-main-menu-container','menu_id' => 'menu-main-menu','walker' => new Description_Walker )); ?></nav>

关于如何在 wordpress 仪表板的导航菜单中添加项目?wordpress仪表盘在哪的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于php – 在WordPress注册表单中添加名字和姓氏、php – 如何在WordPress / WooCommerce 3中的注释表单中添加自定义字段、php – 如何在wordpress菜单中为仪表板添加id?、php – 如何在我的WordPress菜单中添加父菜单描述?的相关信息,请在本站寻找。

本文标签: