WordPress的,永久链接和子弹

时间:2018-08-03 13:13:02

标签: php wordpress permalinks slug

我离开wordpress(和php)已有一段时间了,而我几年前做的一些代码却在挣扎。

我想使用摘录后的摘录(如果存在)来标记说明。

我正在处理的代码是这样:

//get post excerpt relating to tag slug
        $tagslug = $tag->slug;
            $args = array('name' => $tagslug);
                $excerpt = get_posts($args);
                    $output = $excerpt[0]->post_excerpt;
                        $outputreplace = str_replace('"', "''", $output);
                            $postexcerpt = str_replace("=", "\n", $outputreplace);

我的函数的其余代码:

function tags(){    
if (is_page('tag')){$tags = get_tags();}
else{$tags = get_the_tags();}
if (! $tags){echo "";}
else{
    $html = '<ul class="tags">' . "\r\n\t" . '<li>Tags: </li>' . "\r\n\t" . '';
    foreach ( $tags as $tag ){
        $tag_link = get_tag_link( $tag->term_id );

        global $post;

        $tag_group_ids = get_option( 'tag_group_ids', array() );
            $i = array_search($tag->term_group, $tag_group_ids);
        $tag_group_labels = get_option( 'tag_group_labels', array() );
            $lower = array_map('strtolower', $tag_group_labels);

        //get tag description
        //FIX THIS
        $description = str_replace('"', "''", $tag->description);
            $tagdescription = str_replace("=", "\n", $description);

        //get post excerpt relating to tag slug
        $tagslug = $tag->slug;
            $args = array('name' => $tagslug);
                $excerpt = get_posts($args);
                    $output = $excerpt[0]->post_excerpt;
                        $outputreplace = str_replace('"', "''", $output);
                            $postexcerpt = str_replace("=", "\n", $outputreplace);

        //change speechmarks for $tag->name
        $tagname = str_replace('"', "''", $tag->name);

        //get post category relating to tag slug
        /*
        $tagslug = $tag->slug;
            $args = array('category' => $tagslug);
                $excerpt = get_posts($args);
                    $output = $excerpt[0]->post_excerpt;
                        $outputreplace = str_replace('"', "''", $output);
                            $postexcerpt = str_replace("=", "\n", $outputreplace);*/

        /*$tag_group = get_option( 'tag_group_ids', array() );
            $n = array_search($tag->term_group, $tag_group);
        $tag_labels = get_option( 'tag_group_labels', array() );
            $new = array_map('strtolower', $tag_labels);                                
        //var_dump($n);
        echo '<pre>';
        var_dump ($new);
        echo '</pre>';
        //var_dump($new[$n]);
        */

        $html .= '<li class="' . $lower[$i] . ' ' . $tag->slug . ' tag">' . "\n\t";
        $html .= '<a href="' . $tag_link . '"';
        $html .= ' title="' . $tagname . "\n\n";
        if (!empty($postexcerpt)){
            $html .= $postexcerpt . "\n\n";
            }
        elseif (!empty($tagdescription)){
            $html .= $tagdescription . "\n\n";
            }
        else{
            $html .= "No tag description or post excerpt yet." . "\n\n";
            }
        $html .= 'Tagged in ' . $tag->count . ' posts' . "\n\n";
        $html .= 'Catergory: ' . $tag_group_labels[$i] . "\n" . '">';

        $html .= $tag->name;
        $html .= ' <sup>[' . $tag->count . ']';
        if (!empty($outputreplace)||($description)){
            $html .= '[D]';
            }
        $html .= '</sup></a></li> '. "\n\n\t";
        }
    $html .= '</ul>';
    echo $html;
    echo "\r\n";
    }
}

有人可以指出我正确的方向吗?

感谢。

0 个答案:

没有答案