doushi3715 2018-07-20 12:59
浏览 55
已采纳

Wordpress上的自定义帖子没有显示

I have added CPT UI and Custom Fields plugins to my Wordpress set up. I am trying to add custom posts onto a portfolio page and have two issues that I think must be linked.

Firstly, I cannot get thumbnail images to display on the portfolio page. I have added

"add_theme_support( 'post-thumbnails' );"

to my functions.php file as instructed. The "add_theme_support( 'menus' );" function works fine.

Featured images is enabled and displaying when I add the Portfolio Piece.

In the absence of the image I added a text link which did display but the link address is

"http://localhost/localwp.dev/2018/07/13/hello-world/"

and not "http://localhost/localwp.dev/portfolio_wadn/post/"

So I know I am missing something because the Portfolio page is not finding the right slug/address to link to the post. I think it must be the way I've set up either the Custom Fields or CPT UI settings but I can't find anything that solves the issue.

Can anyone help? Code below.

functions.php code:

<?php 

add_theme_support( 'menus' );
add_theme_support( 'post-thumbnails' );

function register_theme_menus () {

register_nav_menus( 
    array(
        'primary-menu'  => __( 'Primary Menu')
    )
 );
}

add_action( 'init', 'register_theme_menus');




function wadn_theme_styles() {

wp_enqueue_style( 'foundation_css', get_template_directory_uri() . 
'/css/foundation.css' );  
wp_enqueue_style( 'googlefont_css', 'http://fonts.googleapis.com/css? 
family=Asap:400,700,400italic,700italic' );
wp_enqueue_style( 'main_css', get_template_directory_uri() . '/style.css' );
}

add_action( 'wp_enqueue_scripts', 'wadn_theme_styles' );

function wadn_theme_js() {

wp_enqueue_script( 'modernizr_js', get_template_directory_uri() . '/js/modernizr.js', '',  '', false );
wp_enqueue_script( 'foundation_js', get_template_directory_uri() . '/js/foundation.min.js', array('jquery'), '', true );
wp_enqueue_script( 'app_js', get_template_directory_uri() . '/js/app.js', array('jquery', 'foundation_js'), '', true );  

}
add_action( 'wp_enqueue_scripts', 'wadn_theme_js' );





?>

page-portfolio.php code:

<?php 
/* 
Template Name: Portfolio Page 
*/
?>

<?php get_header(); ?>


<section class="row">
  <div class="small-12 columns text-center">
    <div class="leader">

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

      <h1><?php the_title(); ?></h1>

      <?php the_content(); ?>

    <?php endwhile; endif; ?>

    </div>
  </div>
</section>

<?php 

$args = array(
    'post-type' => 'portfolio_wadn'
);
$query = new WP_Query ( $args );

?>

<section class="row no-max pad">

<?php if( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>

  <div class="small-6 medium-4 large-3 columns grid-item">
    <a href="<?php the_permalink(); ?>">Test</a>
  </div>    

 <?php endwhile; endif; wp_reset_postdata(); ?>

</section>

<?php get_footer(); ?>

Register Post Type Code

function cptui_register_my_cpts_portfolio_wadn() {

/**
 * Post Type: portfolio_wadn.
 */

$labels = array(
    "name" => __( "portfolio_wadn", "" ),
    "singular_name" => __( "Portfolio Piece", "" ),
);

$args = array(
    "label" => __( "portfolio_wadn", "" ),
    "labels" => $labels,
    "description" => "",
    "public" => true,
    "publicly_queryable" => true,
    "show_ui" => true,
    "show_in_rest" => false,
    "rest_base" => "",
    "has_archive" => false,
    "show_in_menu" => true,
    "show_in_nav_menus" => true,
    "exclude_from_search" => false,
    "capability_type" => "post",
    "map_meta_cap" => true,
    "hierarchical" => false,
    "rewrite" => array( "slug" => "portfolio_wadn", "with_front" => true ),
    "query_var" => true,
    "supports" => array( "title", "editor", "thumbnail", "custom-fields", "page-attributes", "post-formats" ),
);

register_post_type( "portfolio_wadn", $args );
}

add_action( 'init', 'cptui_register_my_cpts_portfolio_wadn' );
  • 写回答

1条回答 默认 最新

  • dongtiao5094 2018-07-20 13:38
    关注

    There is an error in your 'page-portfolio.php' code - 'post-type' should be 'post_type'.

    $args = array(
        'post_type' => 'portfolio_wadn'
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行