分类: 建站知识

  • 根据不同的分类调用指定的不同single模板

    在wordpress的functions.php中,添加以下代码,即可实现根据不同的分类别名,调用指定的single模板。

    add_action('template_include', 'load_single_template');
    
     function load_single_template($template) {
     $new_template = '';
     if( is_single() ) {
     global $post;
     // 新闻
     if( has_term('news', 'category', $post) ) {
     $new_template = locate_template(array('single-news.php' ));
            }
     // 案例
     if( has_term(array('case', 'case1', 'case2', 'case3', 'case4'), 'category', $post) ) {
     $new_template = locate_template(array('single-case.php' ));
            }
    
         }
     return ('' != $new_template) ? $new_template : $template;
     }
  • wordpress子页面获取父页面的标题和链接

    wordpress模板制作时,如果wordpress子页面模板获取父页面的标题和链接,用以下代码就可以现实。

    <?php global $post;
      if ( $post->post_parent ) { ?>
        <a href="<?php echo get_permalink( $post->post_parent ); ?>" >
        <?php echo get_the_title( $post->post_parent ); ?>
        </a>
    <?php } ?>
  • 用AI视频工具HeyGen可以给产品做视频介绍

    做外贸跨境电商的人有福了

    最近发现一款非常容易上手的AI视频工具HeyGen,通过HeyGen,可以在上传产品图片后,给产品用AI生成一段产品介绍的视频。

    而且还可以在素材库中选择介绍者的形象,有不同性别和职业的人物模板可供选择。

    这个工具可以让上架产品,给产品写介绍变得更简单容易。

    有需要的可以去试用,免费版和付费版都有。

    HeyGen官方网站 https://www.heygen.com

  • wordpress数据库批量替换网址最简单的方法

    在搭建wordpress网站时,常常会用到批量替换网址,网上能搜到挺多的方法,基本都是通过数据库管理后台来批量替换的。

    我最常用的方法是,把数据库文件导出.sql文件,然后用读记事本来批量替换,替换完了,再重新把.sql文件上传到数据库。

  • 让多个域名都可以访问一个wordpress网站

    WordPress在安装后会默认绑定当前的域名,如果把多个域名都绑定到wordpress网站后,在通过这些域名访问时,还是会跳转到安装时候的域名。

    有没有什么办法可以,让各自域名,访问这个wordpress网站,都显示的是当前访问的域名呢?

    简站wordpress主题,今天给大家分享一个WordPress可以绑定多个域名并通过这些域名都能访问网站的方法。

    1. 打开网站根目录下的wp-config.php,找到define(‘WP_DEBUG’, false);在后面添加下面内容:

    define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
    define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);

    这样的话,所有绑定到了这个网站的域名都可以访问。

    如果只想让限定的域名访问,只需要添加以下的代码:

    $domain = array("www.a.com", "www.b.com", "www.c.com"); 
    if(in_array($_SERVER['HTTP_HOST'], $domain)){
        define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
        define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
    }

    说明:

    1、如果是https,请修改代码里面的http://为https://;

    2、如果网站安装在二级目录,则将

    "http://". $_SERVER["HTTP_HOST"]

    修改为

    "http://" . $_SERVER["HTTP_HOST"]."/对应目录名"

    3、完成这些操作后,网站已经可以实现多域名访问了。

    4、但是有个问题,是在启用伪静态后,图片链接是固定的,还没有变化。再需要把以下代码添加进去,才能实现图片链接也改为静态链接。

    define( 'WP_CONTENT_URL', '/wp-content');
  • WP站访问时崩溃 刷新才能正常显示 怎么解决的方法

    wordpress访问时出现崩溃,刷新页面后,才能正常显示。

    如果遇到这种情况,首先要判断是服务器问题?还是程序问题?

    怎么判断呢?

    根据个人经验,分两种情况:

    1、如果进行某个操作时,出现问题,重复多次进行这个操作时,出现的问题,一直一样。这种情况,多是wordpress程序或主题的问题。

    2、如果出现问题,不是因为进行了,某个特定的操作,而是随机的出现问题。这种情况,多是服务器的问题。

    先通过以上排除法,找到问题,再根据具体的问题,解决问题。

    如果是国内的服务器,一般都是因为服务器设置的问题,对服务器进行合理的设置,就可以解决问题。

    如果使用的是海外的服务器,一般是线路问题,挺多海外服务器的网站,访问都比较慢,出现超时或中断的情况,不能访问。这个无解,只能换主机服务商。

  • 向wordpress设置常规页面添加固定字段

    通过向functions.php文件添加以下代码,就可以现实向wordpress设置常规页面添加固定字段

    /**
     * WordPress 添加额外选项字段到常规设置页面
     */
    $new_general_setting = new new_general_setting();
    class new_general_setting {
        function new_general_setting( ) {
            add_filter( 'admin_init' , array( &$this , 'register_fields' ) );
        }
        function register_fields() {
            register_setting( 'general', 'cuskeywords', 'esc_attr' );
            add_settings_field('cuskeywords', '<label for="cuskeywords">'.__('关键词' ).'</label>' , array(&$this, 'fields_html') , 'general' );
        }
        function fields_html() {
            $value = get_option( 'cuskeywords', '' );
            echo '<textarea cols="60" rows="9" id="cuskeywords" name="cuskeywords"  />' . $value . '</textarea>';
        }
    }
    
    $new2_general_setting = new new2_general_setting();
    class new2_general_setting {
        function new2_general_setting( ) {
            add_filter( 'admin_init' , array( &$this , 'register_fields' ) );
        }
        function register_fields() {
            register_setting( 'general', 'cusaboutus', 'esc_attr' );
            add_settings_field('cusaboutus', '<label for="cusaboutus">'.__('描述' ).'</label>' , array(&$this, 'fields_html') , 'general' );
        }
        function fields_html() {
            $value = get_option( 'cusaboutus', '' );
            echo '<textarea cols="60" rows="9" id="cusaboutus" name="cusaboutus"  />' . $value . '</textarea>';
        }
    }
  • 为不同文章形式选择不同的WordPress文章模板

    在写文章的时候选择不同的文章形式,然后打开文章的时候会调用不同文章形式的模板。比如,文章形式为video ,就调用single-video.php模板,其它文章形式类似,可以添加多个文章样式。

    //为不同文章形式的内容添加不同的single页面
    add_action('template_include', 'load_single_template');
    function load_single_template($template) {
      $new_template ='';
      // single post template
      if( is_single() ) {
        global $post;
        if ( has_post_format( 'video' )) {// 文章形式为video
          $new_template = locate_template(array('single-video.php' ));// 就调用single-video.php模板
        }
        if ( has_post_format( 'image' )) {// 文章形式为image
          $new_template = locate_template(array('single-image.php' ));// 就调用ssingle-image.php模板
        }
    // 这里可以添加其他文章形式的模板
      }
      return (''!= $new_template) ? $new_template : $template;
    }

    将以上代码添加到functions.php文件中即可。

  • 如何添加wordpress文章形式

    wordpress的功能很强,通过文章形式,可以让wordpress文章,有多种形式来展示。并不是所有的主题都有wordpress的文章形式,如果想有文章形式,将以下代码添加到functions.php文件中即可。

    //开启文章形式
     add_theme_support( 'post-formats', array( 'aside', 'image', 'link', 'status', 'video'));
  • wordpress根据文章分类自动调用指定页面模板

    通过wordpress分类目录的别名来调用指定的single模板

     add_action('template_include', 'load_single_template');
     function load_single_template($template) {
     $new_template = '';
     if( is_single() ) {
     global $post;
     // 新闻
     if( has_term('news', 'category', $post) ) {
     $new_template = locate_template(array('single-newsinfo.php' ));
            }
     // 团队
     if( has_term('team', 'category', $post) ) {
     $new_template = locate_template(array('single-team.php' ));
            }
     // 案例
     if( has_term('case', 'category', $post) ) {
     $new_template = locate_template(array('single-case.php' ));
            }
     // 产品
     if( has_term('product', 'category', $post) ) {
     $new_template = locate_template(array('single-product.php' ));
            }
         }
     return ('' != $new_template) ? $new_template : $template;
     }

    把上面的代码,添加到functions.php文件中即可。