0

そこで、サイト内の投稿の WP_query ループを含むカスタム テンプレートを使用する「comics」というページを作成しました (ページごとに 1 つのコミック ストリップ、ナビゲーション用の前/次ボタン付き)。「コミック」カテゴリ内のすべての投稿を一覧表示するアーカイブ ページもあります。

デフォルトでは、アーカイブ ページのリンクは特定の投稿自体にリンクしていますが、WP_query ループ内の投稿にリンクするように変更するにはどうすればよいですか?

301 リダイレクト プラグインを使用して、すべての投稿に正しいリンクを挿入できることはわかっていますが、クライアントのためにこれを行っているので、彼女にとって物事をより簡単にすることができればより良いでしょう.

知る必要がある場合は、comics.php ページの WP_query ループを次に示します。

<?php 
$comics_loop = new WP_Query(
    array(
        'posts_per_page' => 1,
        'paged' => get_query_var('paged'),
        'category_name' => comics
    )
);

if($comics_loop->have_posts()) :

echo '<ul class="comic-slider-container">';

while($comics_loop->have_posts()) : $comics_loop->the_post();
?>
    <li><h1 id="comic-slider-title" class="page-title">Weekly Comics &nbsp;|&nbsp; <span class="title-alt"><?php the_title(); ?></span>&nbsp;&nbsp; <a href="<?php bloginfo('url') ?>/category/comics/" id="archive-button" class="big-button">Archives</a></h1></li>
    <li><?php the_post_thumbnail( 'full' ); ?></li>

    <li><?php the_content(); ?></li>

    <li><p class="byline vcard">
        <?php
            printf(__('Posted <time class="updated" datetime="%1$s" pubdate>%2$s</time>', 'bonestheme'), get_the_time('Y-m-j'), get_the_time(__('F jS, Y', 'bonestheme')) );
            ?>
        </p>
    </li>
<?php
endwhile;

echo "</ul>";
?>

デフォルトではアーカイブページのタイトルリンク:

<h3 class="h2"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
4

1 に答える 1

0

投稿をパーマリンク構造にするには、カスタム分類法を使用する必要があります。

そうは言っても、設定していない場合は、コミック用に設定するコードがあります。これを functions.php にドロップします

add_action( 'init', 'build_taxonomies', 0 );

    function build_taxonomies() {
        register_taxonomy( 'comics', 'post', array( 'hierarchical' => true, 'label' => 'Comics', 'query_var' => true, 'rewrite' => array( 'slug' => 'comics', 'with_front' => false, 'hierarchical' => true ) ) );
    }

次に、リンクのリストをエコーアウトします

$terms = get_terms('comics');
echo '<ul>';
foreach ($terms as $term) {
    //Always check if it's an error before continuing. get_term_link() can be finicky sometimes
    $term_link = get_term_link( $term, 'comics' );
    if( is_wp_error( $term_link ) )
        continue;
    //We successfully got a link. Print it out.
    echo '<li><a href="' . $term_link . '">' . $term->name . '</a></li>';
}
echo '</ul>';

必要に応じて編集します

于 2013-08-07T15:57:35.110 に答える