• Resolved teamcanada613

    (@teamcanada613)


    hey, so I’m a little confused, I’ve been searching for hours, I’ve made a custom post type for a portfolio section, and I have posts within it called projects, I want to pull the post title/featured image and category its under from the featured category, so the posts will have 2 categories, the featured being the option that displays them on a certain page, and another for a certain part of my design

    its an image (which i want to pull the featured from)
    with a mouse overlay that will show the Project title, and the category

    so like

    Web Company – title
    Development – category (also in the featured but don’t want featured being displayed

    i’ve found this code on the site, and was wondering how i could do it, the slug is project so example

    localhost/project/web-company
    also i want either 3 of these to loop or 6 if possible.

    <?php
    query_posts('cat=7&posts_per_page=3');
    if(have_posts()) :
      while(have_posts()) :
        the_post();
        ?>
        <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
          <h2><?php permalink(); ?></h2>
          <div class="entry">
          <?php
          $img = get_post_meta($post->ID, 'Featured Thumbnail', true);
          ?><img src="<?php echo $img; ?>"/><?php
          the_content('Read More');
          ?>
          </div>
        </div>
        <?php
      endwhile;
    endif;
    wp_reset_query();
    ?>
Viewing 11 replies - 1 through 11 (of 11 total)
  • Hi, I would probably start with something g like this;

    <?php
    $type = 'projects';
    $args=array(
      'post_type' => $type,
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    
    $my_query = null;
    $my_query = new WP_Query($args);
    
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
        <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
          <h2><?php permalink(); ?></h2>
          <div class="entry">
          <?php
          $img = get_post_meta($post->ID, 'Featured Thumbnail', true);
          ?><img src="<?php echo $img; ?>"/><?php
          the_content('Read More');
          ?>
          </div>
        </div>
        <?php
      endwhile;
    wp_reset_query();
    ?>

    Oops forgot you wanted only 3 or 6 to display;

    <?php
    $type = 'projects';
    $args=array(
    'post_type' => $type,
    'post_status' => 'publish',
    'posts_per_page' => 3
    
    $my_query = null;
    $my_query = new WP_Query($args);
    
    if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
    <h2><?php permalink(); ?></h2>
    <div class="entry">
    <?php
    $img = get_post_meta($post->ID, 'Featured Thumbnail', true);
    ?><img src="<?php echo $img; ?>"/><?php
    the_content('Read More');
    ?>
    </div>
    </div>
    <?php
    endwhile;
    wp_reset_query();
    ?>

    Thread Starter teamcanada613

    (@teamcanada613)

    thank you for your help,

    i broke it down to this

    <?php
        $args = array(
            'post_type' => 'project',
            'post_status' => 'publish',
            'posts_per_page' => 3 );
    
        $loop = new WP_Query( $args );
    
        while ( $loop->have_posts() ) : $loop->the_post();
            the_title();
            the_category();
    
        endwhile;
    
    ?>

    i dont want the category to be a link, and also i want to know how to make a link out of each post

    Hi,

    Wouldn’t this work?

    <?php
        $args = array(
            'post_type' => 'project',
            'post_status' => 'publish',
            'posts_per_page' => 3 );
    
        $loop = new WP_Query( $args );
    
        while ( $loop->have_posts() ) : $loop->the_post();
            the_title();
            the_category(', ');
    
        endwhile;
    
    ?>

    Thank you.

    Thread Starter teamcanada613

    (@teamcanada613)

    no, thank you!

    the change in the

    the_category();

    was perfect.

    Just wondering, do you know the function to obtain the link of each post to add into the loop?

    cant figure it out still searching for it, i found the featured image part i was looking for =)

    Hi,

    Normally you’d use permalink … So the_permalink();

    Hope that helps.

    Thank you.

    Thread Starter teamcanada613

    (@teamcanada613)

    that was it, i was trying it with the_ so now it works also

    the_category(‘, ‘);

    still is a link, do u know to how to stop that?

    Thread Starter teamcanada613

    (@teamcanada613)

    the solution for category was this

    $categories = get_the_category();
    
    if ( ! empty( $categories ) ) {
        echo esc_html( $categories[0]->name );
    }

    Hi,

    Was gonna post that just as I refreshed πŸ™‚ glad you got that part working

    Thread Starter teamcanada613

    (@teamcanada613)

    thanks a ton for your help and your time =)

    Hi,

    Was gonna post that just as I refreshed πŸ™‚ glad you got that part working

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Custom Post Type help’ is closed to new replies.