Permalinks for quote authors

时间:2011-05-27 作者:fivehead

What I have:引用的网站,格式为:“引用文本”-引用作者参见quotup.com 对于我的考试网站(我为考试中的亵渎行为提前道歉)。What I\'m after:单击“-Quote Author”将启动一个包含该Quote Author所有引用的页面,URL为:示例。史蒂夫·史蒂文森,其中史蒂夫·史蒂文森是引文作者。What I\'ve done:创建了一个名为wp\\u qauthor的自定义表,该表通过post\\u meta(qauthor\\u id)绑定到wp\\u posts
向函数中添加了以下代码。php:

add_filter(\'query_vars\', \'add_my_var\');
    function add_my_var($public_query_vars) {
        $public_query_vars[] = \'qaid\';
        return $public_query_vars;
    }
为引用作者的姓名创建链接,如下所示:

<a href="http://example.com?qaid=2">Steve Stevenson</a>
单击此链接当前将加载回主页。php,但我需要它来访问索引。php,我在其中添加了以下代码:

elseif (get_query_var(\'qaid\')) {
    $qaid = get_query_var(\'qaid\');
    query_posts($query_string . "&meta_key=qauthor_id&meta_value=" . $qaid);}

The questions:

<我如何告诉WP调用索引。单击示例时使用php。com?qaid=2 href

2 个回复
SO网友:fuxia

创建自定义分类法quoteauthor, 激活漂亮的永久链接,就会自动获得漂亮的URI。这些URI不会将作者的名字放在根后面,而是类似于/qa/steve-stevenson/ 应该足够好了。

下面是一个插件示例代码,您可以download it on GitHub

<?php # -*- coding: utf-8 -*-
/*
Plugin Name: Custom Taxonomy Quote Author
Plugin URI:  https://gist.github.com/996608
Description: Creates a custom taxonomy <code>Quote Author</code> with an URI <code>/qa/author-name/</code>
Version:     1.0
Required:    3.1
Author:      Thomas Scholz
Author URI:  http://toscho.de
License:     GPL
*/
! defined( \'ABSPATH\' ) and exit;

add_action( \'after_setup_theme\', \'register_quote_author\' );

register_activation_hook(   __FILE__, \'qua_flush\' );
register_deactivation_hook( __FILE__, \'qua_flush\' );

/**
 * Registers the taxonomy \'Quote Author\'.
 *
 * To list the authors with links in your theme use
 * @link http://codex.wordpress.org/Function_Reference/get_the_term_list
 * <code>print get_the_term_list( get_the_ID(), \'quoteauthor\' );</code>
 *
 * @link http://codex.wordpress.org/Function_Reference/register_taxonomy
 * @return void
 */
function register_quote_author()
{
    register_taxonomy(
        // Internal name
        \'quoteauthor\'
        // Post types the taxonomy applies to.
        // The attachment field is not very nice, just a simple input field.
        // You may tweak that.
    ,   array ( \'post\', \'attachment\' )
        // Visible labels
    ,   array (
        \'labels\'            => array (
            \'name\'                       => \'Quote Authors\'
        ,   \'menu_name\'                  => \'Quote Authors\'
        ,   \'singular_name\'              => \'Quote Author\'
        ,   \'search_items\'               => \'Search Quote Authors\'
        ,   \'popular_items\'              => \'Popular Quote Authors\'
        ,   \'all_items\'                  => \'All Quote Authors\'
        ,   \'edit_item\'                  => \'Edit Quote Author\'
        ,   \'update_item\'                => \'Update Quote Author\'
        ,   \'add_new_item\'               => \'Add Quote Author\'
        ,   \'new_item_name\'              => \'New name for Quote Author\'
        ,   \'separate_items_with_commas\' => \'Separate Quote Authors by comma\'
        ,   \'add_or_remove_items\'        => \'Add or remove Quote Authors\'
        ,   \'choose_from_most_used\'      => \'Choose from most quoted authors\'
        )
        // Most important parameter. :)
    ,   \'public\'            => TRUE
        // Available in custom menus.
    ,   \'show_in_nav_menus\' => TRUE
        // Standard box.
    ,   \'show_ui\'           => TRUE
        // Clickable list of popular authors.
    ,   \'show_tagcloud\'     => TRUE
        // URI
    ,   \'rewrite\'           => array (
            \'slug\' => \'qa\'
        )
        // If you want to use WP_Query.
    ,   \'query_var\'         => \'qa\'
    )
    );
}
/**
 * Tells WordPress to rebuild the rewrite rules to include our custom URIS.
 *
 * @return void
 */
function qua_flush()
{
    // The current instance of the class WP_Rewrite.
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
}

SO网友:xLRDxREVENGEx

Q: 我如何告诉WP调用索引。单击示例时使用php。僵尸?qaid=2 href<好吧,如果你谈论模板文件的时候,你的主题中没有供作者使用的模板。php你应该很好。或者只要没有模板干扰加载索引。php默认情况下应该加载它

Q: 单击上面的链接后,如何获得示例所需的漂亮链接。通信/史蒂文森?非常感谢<答:只要服务器允许mod\\u重写并且插入了,就可以在permalinks下的后端设置选项卡下找到。htaccess文件应自动工作

结束

相关推荐

curl problem or permalinks

我刚刚配置了我的VPS,我使用的是Centos,一切都很好,但如果我将永久链接设置为自定义结构,然后接受主页,没有帖子出现,它会显示404页,我想这是因为我没有启用curl,但我不知道我的php在哪里。我的centos中的ini文件?好的,我的卷曲被启用了,我检查过了phpinfo(); 这里是URLhttp://74.117.158.182/info.php但如果我在我的wordpress中设置了永久链接,那么接受主页,所有都会给我404页,你可以在这个URL上查看http://mbas.co.in如果