[wordpress插件] Better Related Posts更好的相关职位

wordpress 插件 文章 2020-03-04 03:20 487 0 全屏看文

AI助手支持GPT4.0

评分
76
描述

Custom post types are one the best features in WordPress.

自定义帖子类型是WordPress中最好的功能之一。

Since WordPress 3.0 they are much easier to use.

从WordPress 3.0开始,它们更加易于使用。

Almost every theme I build for a client features at least one custom post type and usually a custom taxonomy as well.

我为客户构建的几乎每个主题都至少具有一种自定义帖子类型,通常还具有一种自定义分类法。

But there is a problem.

但是有一个问题。

There is no plugin that lists related posts that are from a custom post type.

没有插件列出来自自定义帖子类型的相关帖子。

After looking through the sourcecode of a few plugins I decided to implement my own related content plugin.

浏览了几个插件的源代码后,我决定实现自己的相关内容插件。

Plugin Features

插件功能

安装步骤

If you have a big site keep in mind that installing this plugin will create a fulltext index for your posts, so the size of the wp_posts table can almost double.

如果您的网站很大,请记住,安装此插件将为您的帖子创建全文索引,因此wp_posts表的大小几乎可以增加一倍。

    1. Upload the plugin to your plugins directory
    2. 将插件上传到您的插件目录

    3. Enable the plugin
    4. 启用插件

    5. Enable automatic display of related posts
    6. 启用自动显示相关帖子

    How to place a related content list manually

    如何手动放置相关内容列表

    If you don’t enable automatic display of related posts on the plugin options page (the very first setting) you’ll have to use the template tag

    如果您未在插件选项页面上启用自动显示相关帖子(第一个设置),则必须使用模板标签 <?php the_related();。

    ?> to insert a related content list into your theme.

    ?> 将相关的内容列表插入主题。

    If you use this outside of the WordPress loop you have to pass the post ID as parameter.

    如果您在WordPress循环之外使用此代码,则必须将帖子ID作为参数传递。

    How to build a custom loop of related posts

    如何建立相关帖子的自定义循环

    Here is a short example how to build your own loop of related posts.

    这是一个简短的示例,说明如何构建自己的相关帖子循环。

    This way you can add excerpts, post thumbnails etc.

    这样,您可以添加摘录,发布缩略图等。

      <?php    

    $scores = the_related_get_scores();

    $ scores = the_related_get_scores();

    // pass the post ID if outside of the loop    

    //如果在循环之外,则传递帖子ID    

    $posts = array_slice( array_keys( $scores ), 0, 5 );

    $ posts = array_slice(array_keys($ scores),0,5);

    // keep only the the five best results    

    //仅保留五个最佳结果    

    $args = array(        

    $ args =数组(        

    'post__in' => $posts,        

    'post__in'=> $ posts,        

    'posts_per_page' => 5,        

    'posts_per_page'=> 5        

    'caller_get_posts' => 1 // ignore sticky status    

    'caller_get_posts'=> 1 //忽略粘性状态    

    );    

    );    

    $my_query = new WP_Query( $args );    

    $ my_query =新的WP_Query($ args);    

    if ( $my_query->have_posts() ) {        

    如果($ my_query-> have_posts()){        

    while ( $my_query->have_posts() ) {            

    while($ my_query-> have_posts()){            

    $my_query->the_post();            

    $ my_query-> the_post();            

    echo '';            

    回声'';            

    the_title();            

    标题();            

    echo '';            

    回显'';            

    the_excerpt();            

    the_excerpt();            

    if ( has_post_thumbnail() ) {                

    如果(has_post_thumbnail()){                

    the_post_thumbnail( 'thumb' );            

    the_post_thumbnail('thumb');            

    }            

    }            

    echo '
    ';        

    回声'
    ';        

    }    

    }    

    }    

    }    

    else {        

    其他{        

    echo "No posts found...";    

    回显“未找到帖子...”;    

    }

    }

    ?>

    ?>

    Please notice that the posts won’t be ordered by score if you build a loop like this.

    请注意,如果您建立这样的循环,则帖子不会按分数排序。

    To accomplish this you’ll have to sort the posts in $my_query manually.

    为此,您必须手动对$ my_query中的帖子进行排序。

    I have a relevant example on how to sort posts manually on my site.

    我在我的网站上有一个有关如何手动分类帖子的示例。

    I’ll build something like this into the plugin in the future.

    以后我会在插件中构建类似的内容。

    How to evaluate different scoring methods

    如何评估不同的评分方法

    Logged in admins can get the results of all scoring methods by using the template tag

    登录的管理员可以使用模板标签 <?php the_related_analyze();获取所有评分方法的结果。

    ?> in the loop of their theme.

    ?> 在他们主题的循环中。

    Example:

    示例:

      <?php    

    if ( current_user_can( 'manage_options' ) && function_exists( 'the_related_analyze' ) ) {        

    如果(current_user_can('manage_options')&& function_exists('the_related_analyze')){        

    the_related_analyze();    

    the_related_analyze();    

    }

    }

    ?>

    ?>

    The scoring methods

    评分方法

    Content to content, title to content and title do title are simple MySQL fulltext searches.

    内容对内容,内容对标题和标题做标题是简单的MySQL全文搜索。

    Keywords to content and keywords to title do a fulltext search for a string that contains all terms a post has.

    内容关键字和标题关键字对包含帖子具有的所有术语的字符串进行全文搜索。

    If a post is in the category Fruits and tagged sweet a fulltext search for “Fruits sweet” will be performed.

    如果帖子在“水果”和“甜”标签类别中,则将对“水果甜”进行全文搜索。

    Terms against taxonomies searches for posts that have the same terms as the current one.

    针对分类法的术语搜索与当前术语具有相同术语的帖子。

    By default only posts that use the same taxonomy are found.

    默认情况下,仅找到使用相同分类法的帖子。

    It is however as well possible to find posts that use a different taxonomy, by searching this other taxonomy for terms of the same name.

    但是,也可以通过在其他分类法中搜索相同名称的词来查找使用不同分类法的帖子。

    See the examples below.

    请参见下面的示例。

    How to use different configurations at the same time

    如何同时使用不同的配置

    It is possible to use different configurations of the plugin at the same time.

    可以同时使用插件的不同配置。

    Let’s say you use the normal related content feature for your posts.

    假设您对帖子使用常规的相关内容功能。

    But you also have a custom post type ‘venue’.

    但是您也有一个自定义帖子类型“地点”。

    To get a custom list of related venues use this:

    要获取相关场所的自定义列表,请使用以下方法:

      <?php

    the_related(    

    the_related(    

    get_the_ID(),    

    get_the_ID(),    

    array(        

    数组(        

    'usept' => array(            

    'usept'=>数组(            

    'venue' => true        

    'venue'=>是        

    ),        

    ),        

    'storage_id' => 'ventures-better-'    

    'storage_id'=>'更好的冒险相关'    

    )

    );

    );

    ?>

    ?>

    It is imporant to define a storage ID, or the plugin will overwrite the scores for the standard posts with the scores for your custom configuration.

    定义存储ID非常重要,否则插件将用您的自定义配置的分数覆盖标准帖子的分数。

    The default storage ID is ‘better-related-‘, so you should avoid that unless you changed the default.

    默认存储ID为“更好相关”,因此,除非您更改了默认设置,否则应避免使用该存储ID。

    To get a similar listing that includes related posts (from the built-in ‘post’ post type) use:

    要获得包含相关帖子(来自内置的“帖子”帖子类型)的类似列表,请使用:

      <?php

    the_related(    

    the_related(    

    get_the_ID(),    

    get_the_ID(),    

    array(        

    数组(        

    'usept' => array(            

    'usept'=>数组(            

    'post' => true,            

    'post'=>是,            

    'venue' => true        

    'venue'=>是        

    ),        

    ),        

    'maxresults' => 7,        

    'maxresults'=> 7,        

    'storage_id' => 'more-better-'    

    'storage_id'=>'更多更好的相关'    

    )

    );

    );

    ?>

    ?>

    Now an example that shows off all configuration options available:

    现在,展示一个显示所有可用配置选项的示例:

      <?php

    the_related(    

    the_related(    

    get_the_ID(),    

    get_the_ID(),    

    array(        

    数组(        

    'usept' => array(            

    'usept'=>数组(            

    'post' => true,            

    'post'=>是,            

    'venue' => true        

    'venue'=>是        

    ),        

    ),        

    'usetax' => array(            

    'usetax'=>数组(            

    'drinks' => true,            

    'drinks'=>是,            

    'food' => true,            

    '食物'=>是,            

    'post_tag' => true,            

    'post_tag'=>是,            

    'category' => true        

    '类别'=> true        

    ),        

    ),        

    'do_c2c' => 1.5,        

    'do_c2c'=> 1.5,        

    'do_t2c' => 2,        

    'do_t2c'=> 2,        

    'do_k2c' => 2,        

    'do_k2c'=> 2,        

    'do_t2t' => 1,        

    'do_t2t'=> 1,        

    'do_k2t' => 2,        

    'do_k2t'=> 2,        

    'do_x2x' => 4.3,        

    'do_x2x'=> 4.3,        

    'minscore' => 25,        

    'minscore'=> 25,        

    'maxresults' => 5,        

    'maxresults'=> 5        

    'log' => true,        

    'log'=>是,        

    'loglevel' => 'taxquery',        

    'loglevel'=>'taxquery',        

    'storage_id' => 'better-related-full-',        

    'storage_id'=>'更好的相关完整示例-',        

    'storage' => 'transient',        

    '存储'=>'瞬态',        

    'cachetime' => 1,        

    'cachetime'=> 1,        

    'querylimit' => 10000,        

    'querylimit'=> 10000,        

    'incremental' => true,        

    'incremental'=>是,        

    't_querylimit' => 30000,        

    't_querylimit'=> 30000,        

    'relatedtitle' => 'Related venues and posts',        

    'relatedtitle'=>'相关场所和职位',        

    'relatednone' => 'No related venues or posts'    

    'relatednone'=>'没有相关场所或职位'    

    )

    );

    );

    ?>

    ?>

    Notes:

    注意:

      • Using the usetax parameter means that cross-taxonomy searches will be performed.

      • 使用usetax参数意味着将执行跨分类搜索。

        It is not recommended to use this parameter at the moment, as it’s usage will probably change in the future.

        目前不建议使用此参数,因为将来可能会更改其用法。

        However, if different taxonomies share terms you can play with this parameter.

      • 但是,如果不同的分类法共享术语,则可以使用此参数。

      • You should not log on live sites.
      • 您不应登录实时网站。

      • The high querylimit in this example could slow down your site.
      • 此示例中的高查询限制可能会降低您的网站速度。

      • The transient storage should only be used temporarily and for testing purposes.
      • 暂时性存储只能用于测试目的。

      • Enabling incremental scoring means that the relatedness scores for posts will be calculated in multiple steps.

      • 启用增量计分意味着将分多个步骤计算职位的相关性分数。

        In the example above up to 30000 related posts will be found and the necessary queries will be spread across three page views, assuming there is no cache.

      • 在上面的示例中,假设没有缓存,最多可以找到30000个相关帖子,并且必要的查询将分布在三个页面视图中。

      Find posts related to a string

      查找与字符串相关的帖子

      The template tag returns related posts for a string.

      模板标记 <?php get_the_related_for_string()?> 返回有关字符串的相关文章。

      The tag prints a list of posts related to a string.

      标记 <?php the_related_for_string()?> 打印与字符串相关的帖子列表。

      Usage:

      用法:

        <?php the_related_for_string('foo'); 

      ?>

      ?>

      I use this on 404 pages currently, see the paste for my dynamic WordPress 404 search form

      我目前在404页上使用它,请参见我的动态WordPress 404搜索表单的粘贴

      >.

      >。

      In the future I will probably add a replacement for the built-in WordPress search to this plugin.

      将来我可能会在此插件中添加内置WordPress搜索的替代品。

      mysqld configuration

      mysqld配置

      Generally speaking, the plugin should work out of the box.

      通常来说,该插件应该开箱即用。

      However, there are two settings you might want to change, see the

      但是,您可能需要更改两个设置,请参见

      >mysql full-text fine-tuning docs.

      > mysql全文微调文档。

      ft_min_word_len controls the minumum length of words.

      ft_min_word_len 控制单词的最小长度。

      This defaults to 4, which might be too small if you use acronyms like CSS, PHP etc. You can change or set that option to 3 in your mysqld config.

      默认值为4,如果使用CSS,PHP等首字母缩写,则该值可能太小。您可以在mysqld配置中将该选项更改或设置为3。

      You will have to re-build your fulltext indexes after doing this, use “REPAIR TABLE table_name QUICK;”

      完成此操作后,您将必须重新构建全文索引,请使用“ REPAIR TABLE table_name QUICK;”。

      where table_name is wp_posts on a default WordPress install.

      在默认的WordPress安装中,table_name是wp_posts。

      The second option could be interesting if your site is not in english and you want to improve search results.

      如果您的网站不是英语,并且您想改善搜索结果,那么第二种选择可能会很有趣。

      Use the ft_stopword_file option to create your own stopwords file.

      使用 ft_stopword_file 选项创建自己的停用词文件。

      MySQL uses english stopwords by default.

      MySQL默认使用英语停用词。

下载地址
https://downloads.wordpress.org/plugin/better-related.0.4.3.4.zip
-EOF-

AI助手支持GPT4.0