我正在使用一個插件,其中默認的 wordpress 帖子顯示在“帖子”選項卡上,此代碼正在獲取帖子,我希望獲取自定義帖子型別“屬性”而不是默認的 wordpress 帖子。
回圈post.php:
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
$the_query = isset( $args['template_args']['the_query'] ) ? $args['template_args']['the_query'] : '';
$title = isset( $args['template_args']['title'] ) ? $args['template_args']['title'] : '';
?>
<h3><?php echo $title; ?></h3>
<div class="uwp-profile-item-block">
<?php
// The Loop
if ($the_query && $the_query->have_posts()) {
echo '<ul >';
while ($the_query->have_posts()) {
$the_query->the_post();
uwp_get_template('posts-post.php', $args);
}
echo '</ul>';
/* Restore original Post Data */
wp_reset_postdata();
} else {
// no posts found
echo "<p>".sprintf( __( "No %s found.", 'userswp' ), $title )."</p>";
}
do_action('uwp_profile_pagination', $the_query->max_num_pages);
?>
</div>
帖子post.php:
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
global $post;
$user = uwp_get_displayed_user();
?>
<li class="uwp-profile-item-li uwp-profile-item-clearfix">
<div class="uwp_generic_thumb_wrap">
<a class="uwp-profile-item-img" href="<?php echo esc_url_raw( get_the_permalink() ); ?>">
<?php
if ( has_post_thumbnail() ) {
$thumb_url = get_the_post_thumbnail_url( get_the_ID(), array( 80, 80 ) );
} else {
$thumb_url = uwp_get_default_thumb_uri();
}
?>
<img class="uwp-profile-item-alignleft uwp-profile-item-thumb"
src="<?php echo esc_url_raw( $thumb_url ); ?>">
</a>
</div>
<h3 class="uwp-profile-item-title">
<a href="<?php echo esc_url_raw( get_the_permalink() ); ?>"><?php echo get_the_title(); ?></a>
</h3>
<time class="uwp-profile-item-time published" datetime="<?php echo get_the_time( 'c' ); ?>">
<?php echo get_the_date(); ?>
</time>
<div class="uwp-profile-item-summary">
<?php
do_action( 'uwp_before_profile_summary', get_the_ID(), $post->post_author, $post->post_type );
$excerpt = strip_shortcodes( wp_trim_words( get_the_excerpt(), 15, '...' ) );
echo esc_attr( $excerpt );
do_action( 'uwp_after_profile_summary', get_the_ID(), $post->post_author, $post->post_type );
?>
</div>
</li>
任何人都可以幫助獲取自定義帖子型別“屬性”帖子而不是默認的 wordpress 帖子嗎?提前致謝。
uj5u.com熱心網友回復:
獲取自定義帖子您可以使用如下所示,根據您的要求更新引數:
$args = array(
'post_type' => 'services',
'post_status' => 'publish',
'posts_per_page' => 8,
'orderby’ => 'title',
'order’ => 'ASC',
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
print the_title();
the_excerpt();
endwhile;
wp_reset_postdata();
uj5u.com熱心網友回復:
您可以定義new WP_Query并'post_type' => 'properties'作為引數傳遞。試試下面的代碼。
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
$args = array(
'post_type' => 'properties'
);
$properties = new WP_Query( $args );
$title = isset( $args['template_args']['title'] ) ? $args['template_args']['title'] : '';
?>
<h3><?php echo $title; ?></h3>
<div class="uwp-profile-item-block">
<?php
// The Loop
if ($properties->have_posts()) {
echo '<ul >';
while ($properties->have_posts()) {
$properties->the_post();
uwp_get_template('posts-post.php', $args);
}
echo '</ul>';
/* Restore original Post Data */
wp_reset_postdata();
} else {
// no posts found
echo "<p>".sprintf( __( "No %s found.", 'userswp' ), $title )."</p>";
}
do_action('uwp_profile_pagination', $properties->max_num_pages);
?>
</div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/345943.html
標籤:php WordPress的 自定义帖子类型
