2

カスタム投稿タイプを使用してカスタム wordpress テーマを作成する作業:

カスタム投稿タイプ (プラグイン カスタム投稿 UI 経由) とカスタム フィールド (高度なカスタム フィールド経由) を追加しました。カスタム投稿は、作成された新しいテンプレート ページ (single-custom.php) に正しく表示されます。したがって、個々のカスタム投稿は希望どおりに表示されます。

ただし問題は、ホームページにタイトルしか表示されないことです。

私がやったこと:

1) 次のコードを追加して、functions.php を介してホームページ/ブログ フィードのフィードに新しい投稿タイプを取り込めるようにしました。

add_filter( 'pre_get_posts', 'my_get_posts' );

function my_get_posts( $query ) {

if ( ( is_home() && $query->is_main_query() ) || is_feed() )
    $query->set( 'post_type', array( 'post', 'custom' ) );

return $query;

これについてジャスティン・タドロックに感謝します

2) カスタム コンテンツ ページ content-custom.php を作成し、そのテンプレートを呼び出すようにインデックス ループを修正しました。

<?php if ( have_posts() ) : ?>

    <?php /* Start the Loop */ ?>
    <?php while ( have_posts() ) : the_post(); ?>

        <?php
           get_template_part( 'content', 'custom', get_post_format() );
        ?>

    <?php endwhile; ?>

私のホームページにはまだカスタム投稿のタイトルしか表示されておらず、完全なコンテンツは表示されていません。この問題は、content-custom.php の the_content の呼び出しに関係していますが、まだ wordpress に慣れているため、問題を見つけることができません。content-custom.php に関連するコードは次のとおりです。

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
            //The title below is displayed correctly
    <h1 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h1>  

</header><!-- .entry-header -->

    // The problem begins below. The entry-content div is created but is empty and is not pulling any content from the custom post through the_content call.

<div class="entry-content">
    <?php the_content(); ?>
</div><!-- .entry-content -->
4

2 に答える 2