admin管理员组文章数量:1130349
The Thing is that i was trying to Display only the thumb and the title of the post inside the thumb with a "got to this Portfolio" button. Something like this:
<section>
<div class="portfolio">
<div class="row">
<?php
$args = array( 'post_type' => 'portfolio', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo '<div class="col-md-4">';
echo '<h4>';
the_title();
echo '</h4>';
// The Thumb
echo '</div>';
endwhile;
?>
</div>
</div>
</section>
and yeah the h4 is not showing and idk why...
the other Thing that the thumb support for the custom type is not showing inside the WordPress admin Panel here is the functions.php Code:
/* Custom Post Type Start */
function create_posttype() {
register_post_type( 'portfolio',
// CPT Options
array(
'labels' => array(
'name' => __( 'portfolio' ),
'singular_name' => __( 'portfolio' )
),
'public' => true,
'has_archive' => false,
'rewrite' => array('slug' => 'portfolio'),
)
);
}
// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );
/* Custom Post Type End */
/*Custom Post type start*/
function cw_post_type_portfolio() {
$supports = array(
'title', // post title
'editor', // post content
'author', // post author
'thumbnail', // featured images
'excerpt', // post excerpt
'custom-fields', // custom fields
'comments', // post comments
'revisions', // post revisions
'post-formats', // post formats
);
$labels = array(
'name' => _x('portfolio', 'plural'),
'singular_name' => _x('portfolio', 'singular'),
'menu_name' => _x('portfolio', 'admin menu'),
'name_admin_bar' => _x('portfolio', 'admin bar'),
'add_new' => _x('Add New', 'add new'),
'add_new_item' => __('Add New portfolio'),
'new_item' => __('New portfolio'),
'edit_item' => __('Edit portfolio'),
'view_item' => __('View portfolio'),
'all_items' => __('All portfolio'),
'search_items' => __('Search portfolio'),
'not_found' => __('No portfolio found.'),
);
$args = array(
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
'labels' => $labels,
'public' => true,
'query_var' => true,
'rewrite' => array('slug' => 'portfolio'),
'has_archive' => true,
'hierarchical' => false,
);
register_post_type('portfolio', $args);
}
add_action('init', 'cw_post_type_portfolio');
/*Custom Post type end*/
The Thing is that i was trying to Display only the thumb and the title of the post inside the thumb with a "got to this Portfolio" button. Something like this:
<section>
<div class="portfolio">
<div class="row">
<?php
$args = array( 'post_type' => 'portfolio', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo '<div class="col-md-4">';
echo '<h4>';
the_title();
echo '</h4>';
// The Thumb
echo '</div>';
endwhile;
?>
</div>
</div>
</section>
and yeah the h4 is not showing and idk why...
the other Thing that the thumb support for the custom type is not showing inside the WordPress admin Panel here is the functions.php Code:
/* Custom Post Type Start */
function create_posttype() {
register_post_type( 'portfolio',
// CPT Options
array(
'labels' => array(
'name' => __( 'portfolio' ),
'singular_name' => __( 'portfolio' )
),
'public' => true,
'has_archive' => false,
'rewrite' => array('slug' => 'portfolio'),
)
);
}
// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );
/* Custom Post Type End */
/*Custom Post type start*/
function cw_post_type_portfolio() {
$supports = array(
'title', // post title
'editor', // post content
'author', // post author
'thumbnail', // featured images
'excerpt', // post excerpt
'custom-fields', // custom fields
'comments', // post comments
'revisions', // post revisions
'post-formats', // post formats
);
$labels = array(
'name' => _x('portfolio', 'plural'),
'singular_name' => _x('portfolio', 'singular'),
'menu_name' => _x('portfolio', 'admin menu'),
'name_admin_bar' => _x('portfolio', 'admin bar'),
'add_new' => _x('Add New', 'add new'),
'add_new_item' => __('Add New portfolio'),
'new_item' => __('New portfolio'),
'edit_item' => __('Edit portfolio'),
'view_item' => __('View portfolio'),
'all_items' => __('All portfolio'),
'search_items' => __('Search portfolio'),
'not_found' => __('No portfolio found.'),
);
$args = array(
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
'labels' => $labels,
'public' => true,
'query_var' => true,
'rewrite' => array('slug' => 'portfolio'),
'has_archive' => true,
'hierarchical' => false,
);
register_post_type('portfolio', $args);
}
add_action('init', 'cw_post_type_portfolio');
/*Custom Post type end*/
Share
Improve this question
asked Nov 1, 2018 at 16:10
MisterLAMisterLA
52 bronze badges
2
- why are you creating the posttype 2x? lot's of issues here...gimme a minute – rudtek Commented Nov 1, 2018 at 16:24
- oh didnt saw that... – MisterLA Commented Nov 1, 2018 at 16:30
1 Answer
Reset to default 0erase all the code above from your functions.php and use this:
function cw_post_type_portfolio() {
$supports = array(
'title', // post title
'editor', // post content
'author', // post author
'thumbnail', // featured images
'excerpt', // post excerpt
'custom-fields', // custom fields
'comments', // post comments
'revisions', // post revisions
'post-formats', // post formats
);
$labels = array(
'name' => _x('portfolios', 'plural'),
'singular_name' => _x('portfolio', 'singular'),
'menu_name' => _x('portfolio', 'admin menu'),
'name_admin_bar' => _x('portfolio', 'admin bar'),
'add_new' => _x('Add New', 'add new'),
'add_new_item' => __('Add New portfolio'),
'new_item' => __('New portfolio'),
'edit_item' => __('Edit portfolio'),
'view_item' => __('View portfolio'),
'all_items' => __('All portfolios'),
'search_items' => __('Search portfolios'),
'not_found' => __('No portfolios found.'),
);
$args = array(
'supports' => $supports,
'labels' => $labels,
'public' => true,
'query_var' => true,
'rewrite' => array('slug' => 'portfolio'),
'has_archive' => true,
'hierarchical' => false,
);
register_post_type('mla_portfolio', $args);
}
add_action('init', 'cw_post_type_portfolio');
/*Custom Post type end*/
I've edited a few lines including removing duplication issues and using the actual $supports array which wasn't included in the function call. I've also changed your posttype from plain portfolio to mla_portfolio so you'll need to change the code for your wp_query to the correct reference.
The reason your h4 isn't working is because you used the_title() instead of get_the_title().
UPDATE
added query code:
<section>
<div class="portfolio">
<div class="row">
<?php
$args = array( 'post_type' => 'mla_portfolio', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo '<div class="col-md-4">';
echo '<h4>'.get_the_title().'</h4>';
echo '<a href="' . get_permalink() . '">' . get_the_post_thumbnail() . '</a>';
echo '</div>';
endwhile;
?>
</div>
</div>
</section>
The Thing is that i was trying to Display only the thumb and the title of the post inside the thumb with a "got to this Portfolio" button. Something like this:
<section>
<div class="portfolio">
<div class="row">
<?php
$args = array( 'post_type' => 'portfolio', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo '<div class="col-md-4">';
echo '<h4>';
the_title();
echo '</h4>';
// The Thumb
echo '</div>';
endwhile;
?>
</div>
</div>
</section>
and yeah the h4 is not showing and idk why...
the other Thing that the thumb support for the custom type is not showing inside the WordPress admin Panel here is the functions.php Code:
/* Custom Post Type Start */
function create_posttype() {
register_post_type( 'portfolio',
// CPT Options
array(
'labels' => array(
'name' => __( 'portfolio' ),
'singular_name' => __( 'portfolio' )
),
'public' => true,
'has_archive' => false,
'rewrite' => array('slug' => 'portfolio'),
)
);
}
// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );
/* Custom Post Type End */
/*Custom Post type start*/
function cw_post_type_portfolio() {
$supports = array(
'title', // post title
'editor', // post content
'author', // post author
'thumbnail', // featured images
'excerpt', // post excerpt
'custom-fields', // custom fields
'comments', // post comments
'revisions', // post revisions
'post-formats', // post formats
);
$labels = array(
'name' => _x('portfolio', 'plural'),
'singular_name' => _x('portfolio', 'singular'),
'menu_name' => _x('portfolio', 'admin menu'),
'name_admin_bar' => _x('portfolio', 'admin bar'),
'add_new' => _x('Add New', 'add new'),
'add_new_item' => __('Add New portfolio'),
'new_item' => __('New portfolio'),
'edit_item' => __('Edit portfolio'),
'view_item' => __('View portfolio'),
'all_items' => __('All portfolio'),
'search_items' => __('Search portfolio'),
'not_found' => __('No portfolio found.'),
);
$args = array(
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
'labels' => $labels,
'public' => true,
'query_var' => true,
'rewrite' => array('slug' => 'portfolio'),
'has_archive' => true,
'hierarchical' => false,
);
register_post_type('portfolio', $args);
}
add_action('init', 'cw_post_type_portfolio');
/*Custom Post type end*/
The Thing is that i was trying to Display only the thumb and the title of the post inside the thumb with a "got to this Portfolio" button. Something like this:
<section>
<div class="portfolio">
<div class="row">
<?php
$args = array( 'post_type' => 'portfolio', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo '<div class="col-md-4">';
echo '<h4>';
the_title();
echo '</h4>';
// The Thumb
echo '</div>';
endwhile;
?>
</div>
</div>
</section>
and yeah the h4 is not showing and idk why...
the other Thing that the thumb support for the custom type is not showing inside the WordPress admin Panel here is the functions.php Code:
/* Custom Post Type Start */
function create_posttype() {
register_post_type( 'portfolio',
// CPT Options
array(
'labels' => array(
'name' => __( 'portfolio' ),
'singular_name' => __( 'portfolio' )
),
'public' => true,
'has_archive' => false,
'rewrite' => array('slug' => 'portfolio'),
)
);
}
// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );
/* Custom Post Type End */
/*Custom Post type start*/
function cw_post_type_portfolio() {
$supports = array(
'title', // post title
'editor', // post content
'author', // post author
'thumbnail', // featured images
'excerpt', // post excerpt
'custom-fields', // custom fields
'comments', // post comments
'revisions', // post revisions
'post-formats', // post formats
);
$labels = array(
'name' => _x('portfolio', 'plural'),
'singular_name' => _x('portfolio', 'singular'),
'menu_name' => _x('portfolio', 'admin menu'),
'name_admin_bar' => _x('portfolio', 'admin bar'),
'add_new' => _x('Add New', 'add new'),
'add_new_item' => __('Add New portfolio'),
'new_item' => __('New portfolio'),
'edit_item' => __('Edit portfolio'),
'view_item' => __('View portfolio'),
'all_items' => __('All portfolio'),
'search_items' => __('Search portfolio'),
'not_found' => __('No portfolio found.'),
);
$args = array(
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
'labels' => $labels,
'public' => true,
'query_var' => true,
'rewrite' => array('slug' => 'portfolio'),
'has_archive' => true,
'hierarchical' => false,
);
register_post_type('portfolio', $args);
}
add_action('init', 'cw_post_type_portfolio');
/*Custom Post type end*/
Share
Improve this question
asked Nov 1, 2018 at 16:10
MisterLAMisterLA
52 bronze badges
2
- why are you creating the posttype 2x? lot's of issues here...gimme a minute – rudtek Commented Nov 1, 2018 at 16:24
- oh didnt saw that... – MisterLA Commented Nov 1, 2018 at 16:30
1 Answer
Reset to default 0erase all the code above from your functions.php and use this:
function cw_post_type_portfolio() {
$supports = array(
'title', // post title
'editor', // post content
'author', // post author
'thumbnail', // featured images
'excerpt', // post excerpt
'custom-fields', // custom fields
'comments', // post comments
'revisions', // post revisions
'post-formats', // post formats
);
$labels = array(
'name' => _x('portfolios', 'plural'),
'singular_name' => _x('portfolio', 'singular'),
'menu_name' => _x('portfolio', 'admin menu'),
'name_admin_bar' => _x('portfolio', 'admin bar'),
'add_new' => _x('Add New', 'add new'),
'add_new_item' => __('Add New portfolio'),
'new_item' => __('New portfolio'),
'edit_item' => __('Edit portfolio'),
'view_item' => __('View portfolio'),
'all_items' => __('All portfolios'),
'search_items' => __('Search portfolios'),
'not_found' => __('No portfolios found.'),
);
$args = array(
'supports' => $supports,
'labels' => $labels,
'public' => true,
'query_var' => true,
'rewrite' => array('slug' => 'portfolio'),
'has_archive' => true,
'hierarchical' => false,
);
register_post_type('mla_portfolio', $args);
}
add_action('init', 'cw_post_type_portfolio');
/*Custom Post type end*/
I've edited a few lines including removing duplication issues and using the actual $supports array which wasn't included in the function call. I've also changed your posttype from plain portfolio to mla_portfolio so you'll need to change the code for your wp_query to the correct reference.
The reason your h4 isn't working is because you used the_title() instead of get_the_title().
UPDATE
added query code:
<section>
<div class="portfolio">
<div class="row">
<?php
$args = array( 'post_type' => 'mla_portfolio', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo '<div class="col-md-4">';
echo '<h4>'.get_the_title().'</h4>';
echo '<a href="' . get_permalink() . '">' . get_the_post_thumbnail() . '</a>';
echo '</div>';
endwhile;
?>
</div>
</div>
</section>
本文标签: Display Custom Post Type in divs just thumb and title
版权声明:本文标题:Display Custom Post Type in divs just thumb and title 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749213653a2333796.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论