• Resolved Cashlin

    (@cashlin)


    If you’d like to show, say, the 4 latest portfolio entries on any of your WordPress pages, follow these simple instructions.

    1. Open the OTW portfolio template ‘otw-portfolio-paginated.php’. I copied all OTW’s templates to my theme so any plugin updates won’t break my edits.

    2. Copy the whole code from lines 10 to lines 76. Also make sure you copy the “otw_pfl_scripts_styles(); /* include the necessary srctips and styles */” and insert it below get_header(); in the theme file(s) you want to show the portfolio entries.

    3. Paste the whole big code you copied from OTW to the theme page where you want the latest entries to appear. For me, that was in ‘home-page.php’.

    4. Now find this code in your custom theme file where you placed the latest X entries code:

    <?php if (is_page()) { $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts('post_type=otw-portfolio&paged='.$paged); } ?>

    You simply want to add ‘&posts_per_page=4’ to the query_posts string. Change 4 to the # of latest entries you want to add. So your code will now look like this:

    <?php if (is_page()) { $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts('post_type=otw-portfolio&posts_per_page=4&paged='.$paged); } ?>

    5. If you want to remove the pagination and filtering for the latest entries, simply find and delete these two pieces of code from your custom theme file:

    <?php $taxo = get_object_taxonomies( 'otw-portfolio' );
                    foreach ( $taxo as $tax_name ) {
                        $categories = get_categories('taxonomy='.$tax_name);
                        $i = 0; $len = count( $categories );
                        foreach ($categories as $category) {
                            if ($i == 0) { ?><ul class="otw-portfolio-filter"><?php }
                            if ($i > 0) { $sep = '<span class="separator">/</span>'; }
                    	        echo '<li class="'.$category->category_nicename.'"><a href="'.get_term_link($category->slug, 'otw-portfolio-category').'">'.$sep.$category->cat_name.'</a></li>';
                            if ($i == $len - 1) { echo '</ul>'; }
                            $i++;
                        }
                    }
                  ?>

    <?php otw_pagination_pfl(); ?>

    Should work!

    https://www.ads-software.com/plugins/otw-portfolio-light/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter Cashlin

    (@cashlin)

    And here’s a super stripped version of a custom template page with only the latest 4 entries showing. This is a working example. Just copy and paste the code within your own theme file where you want it to show:

    <?php
    /**
     * Template Name: Your Custom Template Page Title
     */
    
    get_header();
    otw_pfl_scripts_styles(); /* include the necessary srctips and styles */
    ?>
    
    <div class="make-center">
    
    <h1>Featured Portfolio Entries</h1>
    
    <?php $style_width = '';
      if( get_option( 'otw_pfl_content_width' ) ) {
          $style_width = 'style="width:'.get_option('otw_pfl_content_width').'px;"';
      }
    ?>
            <div class="otw-row otw-sc-portfolio" <?php echo $style_width; ?>>
                  <div class="otw-twentyfour otw-columns">
    
                      <ul class="otw-portfolio block-grid four-up mobile">
    
                      <?php if (is_page()) { $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts('post_type=otw-portfolio&posts_per_page=4&paged='.$paged); } ?>
                      <?php if (have_posts()): while (have_posts()) : the_post(); ?>
                          <li data-type="<?php foreach(get_the_terms($post->ID, 'otw-portfolio-category') as $term) echo $term->slug.' ' ?>" data-id="id-<?php echo($post->post_name) ?>">
                              <article id="post-<?php the_ID(); ?>" <?php post_class('otw-portfolio-item'); ?>>
                                	<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="otw-portfolio-item-link">
                                		<div class="image">
                                    		<?php if ( has_post_thumbnail()) { ?>
                                    		    <?php the_post_thumbnail('otw-portfolio-medium'); ?>
                                    		<?php } else { ?>
                                                <div style="background:url(<?php echo plugins_url( '/otw-portfolio-light/images/pattern-1.png' ) ?>);width:<?php echo get_option('otw_pfl_thumb_size_w', '303'); ?>px;height:<?php echo get_option('otw_pfl_thumb_size_h', '210'); ?>px" title="<?php _e( 'No Image', 'otw_pfl' ); ?>"></div>
                                            <?php } ?>
                                		</div>
                                		<div class="title">
                                			<h3><?php the_title(); ?></h3>
                                		</div>
                                		<div class="text entry-content">
                                			<?php the_excerpt(); ?>
                                		</div>
                                	<span class="shadow-overlay hide-for-small"></span></a>
                              </article>
                          </li>
    
                      <?php endwhile; ?>
                      </ul>
    
    <?php else: ?>
    
        <article id="post-0" class="post no-results not-found">
    		<header class="entry-header">
    			<h1 class="entry-title"><?php _e( 'Nothing Found', 'otw_pfl' ); ?></h1>
    		</header>
    
    		<div class="entry-content">
    			<p><?php _e( 'Apologies, but no results were found. Perhaps searching will help find a related post.', 'otw_pfl' ); ?></p>
    			<?php get_search_form(); ?>
    		</div><!-- .entry-content -->
    	</article><!-- #post-0 -->
    
    <?php endif; ?>
    
    </div>	
    
    <?php
    get_footer();

    Thanks !
    this is absolutely what i was looking for !

    But when i use your code on my homepage, it shows me the main articles of my website and not the projects inside my “portfolio”. i don’t see where is the mistake in your code because in the request, “otw-portfolio-category” is written so…

    Could you help me ?

    thanks for your work.

    Thread Starter Cashlin

    (@cashlin)

    Can you post the URL to the page please? I’m not understanding you fully…

    Yes absolutely ! thanks
    https://www.guillaumedeschamps.fr/?page_id=21

    i would like to show the 3 last works i have done in my homepage, and i have another “portfolio” page. This last one is ok.

    I just don’t know how to show my works on the homepage.
    I suppose i need a special argument code to select the categorie of articles i would like to show. But which one and where ?

    Thread Starter Cashlin

    (@cashlin)

    Did you figure out how to show the 3 latest entries on your home page? It looks like you did. I see 3 portfolio thumbnails on your website.

    Yes or no ?

    Yes Cashlin,
    i found a way : i used this code ( which is yours) in order to show the 3 latest entries in my homepage

    <section id="sectionA">
                    <div id="portfolio_home">
                        <h2>Mes dernières réalisations</h2>
    					<?php $style_width = '';
    					  if( get_option( 'otw_pfl_content_width' ) ) {
    						  $style_width = 'style="width:'.get_option('otw_pfl_content_width').'px;"';
    					  }
    					?>
    
    							<div class="otw-row otw-sc-portfolio" <?php echo $style_width; ?>>
    								  <div class="otw-twentyfour otw-columns">
    
    									  <ul class="otw-portfolio block-grid three-up mobile">
    									  <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;  ?>
    									  <?php query_posts('post_type=otw-portfolio&posts_per_page=-1&paged='.$paged); ?>
    									  <?php if (have_posts()): while (have_posts()) : the_post(); ?>
    										  <li data-type="<?php foreach(get_the_terms($post->ID, 'otw-portfolio-category') as $term) echo $term->slug.' ' ?>" data-id="id-<?php echo($post->post_name) ?>">
    											  <article id="post-<?php the_ID(); ?>" <?php post_class('otw-portfolio-item'); ?>>
    													<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="otw-portfolio-item-link">
    														<div class="image">
    															<?php if ( has_post_thumbnail()) { ?>
    																<?php the_post_thumbnail('otw-portfolio-medium'); ?>
    															<?php } else { ?>
    																<div style="background:url(<?php echo plugins_url( '/otw-portfolio-light/images/pattern-1.png' ) ?>);width:<?php echo get_option('otw_pfl_thumb_size_w', '303'); ?>px;height:<?php echo get_option('otw_pfl_thumb_size_h', '210'); ?>px" title="<?php _e( 'No Image', 'otw_pfl' ); ?>"></div>
    															<?php } ?>
    														</div>
    														<div class="title">
    															<h3><?php the_title(); ?></h3>
    														</div>
    														<div class="text entry-content">
    															<?php the_excerpt(); ?>
    														</div>
    													<span class="shadow-overlay hide-for-small"></span></a>
    											  </article>
    										  </li>
    
    									  <?php endwhile; ?>
    									  </ul>
    								</div>
    							  </div>
    
    					<?php else: ?>
    
    						<article id="post-0" class="post no-results not-found">
    							<header class="entry-header">
    								<h1 class="entry-title"><?php _e( 'Nothing Found', 'otw_pfl' ); ?></h1>
    							</header>
    
    							<div class="entry-content">
    								<p><?php _e( 'Apologies, but no results were found. Perhaps searching will help find a related post.', 'otw_pfl' ); ?></p>
    								<?php get_search_form(); ?>
    							</div><!-- .entry-content -->
    						</article><!-- #post-0 -->
    
    					<?php endif; ?>
    
                </section><!-- fin de sectionA -->

    And i use another loops to get the main articles in the same page

    <section id="sectionB">
                	<div id="articles_home">
                    <h2>Mes derniers articles</h2>
    				<?php if ( have_posts() ) : ?>
                    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;?>
                    <?php query_posts("&cat=10&posts_per_page=3&paged=$paged"); ?>
    
                        <?php /* The loop */ ?>
                        <?php while ( have_posts() ) : the_post(); ?>
                            <?php get_template_part( 'content2', get_post_format() ); ?>
                        <?php endwhile; ?>
    
                        <?php twentythirteen_paging_nav(); ?>
    
                    <?php else : ?>
                        <?php get_template_part( 'content2', 'none' ); ?>
                    <?php endif; ?>
                    </div>
            	</section><!-- fin de sectionB -->

    The thing is you have to rewrite the url of the categories and articles with the back office od wordpress.

    Thank you for your help.
    Guillaume

    Thread Starter Cashlin

    (@cashlin)

    Cool. Marking the topic as solved.

    Thank you so much, Cashlin. Your code helped me a lot!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Here's how to show x latest portfolio entries on any page’ is closed to new replies.