我正在尝试创建我的第一个wordpress主题。但我遇到了一些问题。当我单击链接(the\\u permalink())时,它会返回主页。我得到了正确的URL,但URL显示的是主页,所以我觉得我遗漏了一些东西。
到目前为止,我得到了一个头球。php,页脚。php,侧栏。php,函数。php,样式。css和索引。php。索引文件包含我的循环。
我还创建了一个自定义帖子类型。这是我在索引中循环的自定义帖子类型。php。
我错过了什么?为什么permalink会把我带到主页(循环页/索引.php)?我试过创建单曲。php和单个customposttypeslug。php到目前为止都是空的。但这并没有解决我的问题。
那么我错过了什么呢?我一直在google上搜索,查找抄本,但我不知道我在做什么。。
我的永久链接看起来像这个网站名。com/索引。php/属性/测试6/
循环:
<?php
/* START THE LOOP */
$loop = new WP_Query( array( \'post_type\' => \'properties\', \'posts_per_page\' => 8 ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post();
/* GET METADATA */
$city = get_post_meta( get_the_ID(), \'city_id\', true );
$rentorsale = get_post_meta( get_the_ID(), \'rentorsale_id\', true );
$price = get_post_meta( get_the_ID(), \'price_id\', true );
$livingarea = get_post_meta( get_the_ID(), \'livingarea_id\', true );
$bedrooms = get_post_meta( get_the_ID(), \'bedrooms_id\', true );
$bathrooms = get_post_meta( get_the_ID(), \'bathrooms_id\', true ); ?>
<a href="<?php the_permalink(); ?>">
<div class="col-md-3"> <!-- START BS COL-MD-3 -->
<div class="poststyle"> <!-- START POSTSTYLE -->
<div class="postheader"> <!-- START POSTHEADER -->
<h2><?php echo $city; ?></h2>
</div> <!-- END POSTHEADER -->
<div class="imgcontainer"> <!-- START IMGCONTAINER -->
<?php the_post_thumbnail(); ?>
<img src="<?php bloginfo(\'stylesheet_directory\'); ?>/img/1.jpg" alt="property" title="Real Estate"/>
<div class="rentorsale"> <!-- START RENTORSALE -->
<p><?php echo $rentorsale; ?></p>
</div> <!-- END RENTORSALE -->
<div class="price"> <!-- START PRICE -->
<p><?php echo $price; ?> <i class="fa fa-usd"></i></p>
</div> <!-- END PRICE -->
</div> <!-- END IMGCONTAINER -->
<table class="table"> <!-- START BS TABLE -->
<tr>
<td>Size</td>
<td><?php echo $livingarea; ?></td>
</tr>
<tr>
<td>Bedrooms</td>
<td><?php echo $bedrooms; ?></td>
</tr>
<tr>
<td>Bathrooms</td>
<td><?php echo $bathrooms; ?></td>
</tr>
</table> <!-- END BS TABLE -->
</div> <!-- END POSTSTYLE -->
</div> <!-- END BS COL-MD-3 -->
</a>
<?php endwhile; wp_reset_query();
?>
注册自定义帖子类型:
<?php
add_action( \'init\', \'properties_post_type\' );
function properties_post_type() {
$args = array(
\'description\' => __( \'Post type to manage properties\', \' \' ), // string
\'public\' => true, // bool (default is FALSE)
\'publicly_queryable\' => true, // bool (defaults to \'public\').
\'exclude_from_search\' => false, // bool (defaults to \'public\')
\'show_in_nav_menus\' => false, // bool (defaults to \'public\')
\'show_ui\' => true, // bool (defaults to \'public\')
\'show_in_menu\' => true, // bool (defaults to \'show_ui\')
\'show_in_admin_bar\' => true, // bool (defaults to \'show_in_menu\')
\'menu_position\' => 6, // int (defaults to 25 - below comments)
\'menu_icon\' => null, // string (defaults to use the post icon)
\'can_export\' => true, // bool (defaults to TRUE)
\'delete_with_user\' => true, // bool (defaults to TRUE if the post type supports \'author\')
\'hierarchical\' => false, // bool (defaults to FALSE)
\'has_archive\' => \'false\', // bool|string (defaults to FALSE)
\'query_var\' => \'properties\', // bool|string (defaults to TRUE - post type name)
\'capability_type\' => \'post\', // string|array (defaults to \'post\')
\'map_meta_cap\' => true, // bool (defaults to FALSE)
\'rewrite\' => array(
\'slug\' => \'property\', // string (defaults to the post type name)
\'with_front\' => false, // bool (defaults to TRUE)
\'pages\' => true, // bool (defaults to TRUE)
\'feeds\' => true, // bool (defaults to the \'has_archive\' argument)
\'ep_mask\' => EP_PERMALINK, // const (defaults to EP_PERMALINK)
),
\'supports\' => array(
\'title\',
\'editor\',
\'excerpt\',
\'author\',
\'thumbnail\',
\'trackbacks\',
\'custom-fields\',
\'revisions\',
\'page-attributes\',
\'post-formats\',
),
\'labels\' => array(
\'name\' => __( \'Properties\', \' \' ),
\'singular_name\' => __( \'Property\', \' \' ),
\'menu_name\' => __( \'Properties\', \' \' ),
\'name_admin_bar\' => __( \'Properties\', \' \' ),
\'add_new\' => __( \'Add New\', \' \' ),
\'add_new_item\' => __( \'Add New Property\', \' \' ),
\'edit_item\' => __( \'Edit Property\', \' \' ),
\'new_item\' => __( \'New Property\', \' \' ),
\'view_item\' => __( \'View Property\', \' \' ),
\'search_items\' => __( \'Search Properties\', \' \' ),
\'not_found\' => __( \'No properties found\', \' \' ),
\'not_found_in_trash\' => __( \'No properties found in trash\', \' \' ),
\'all_items\' => __( \'All properties\', \' \' ),
\'archive_title\' => __( \'Properties\', \' \' ),
)
);
/* Register the post type. */
register_post_type(
\'properties\',
$args // Arguments for post type.
);
}
?>