0
votes

is there any way to active portfolio section by adding some code to functions of theme ? i saw some themes that have this feature , that themes add a new section named portfolio to back-end of Word-press

1
what? didn't get my answer? Feel free to ask if you have any questionsFaiz Ahmed

1 Answers

1
votes

You can use custom post type to accomplish what you want.

WordPress can hold and display many different types of content. A single item of such a content is generally called a post, although post is also a specific post type. Internally, all the post types are stored in the same place, in the wp_posts database table, but are differentiated by a column called post_type.

PHP EXAMPLE:

add_action( 'init', 'create_post_type' );
function create_post_type() {
  register_post_type( 'portfolio',
    array(
      'labels' => array(
        'name' => __( 'Portfolios' ),
        'singular_name' => __( 'Portfolio' )
      ),
    'public' => true,
    'has_archive' => true,
    )
  );
}

Then to add it in your theme you can use WP_Query.

EDIT:

WP_Query Example

$args = array(
    'post_type' => 'portfolio'
); // these arguments are telling WP_Query to only look for the post types called portfolio.
$query = new WP_Query( $args );
<!-- the loop -->
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <h2><?php the_title(); ?></h2>
    the_post_thumbnail();
<?php endwhile; ?>
<!-- end of the loop -->

Ask me for any confusions.

NOTE: I am showing you a method without using any plugins. A custom approach.