WordPress.org

Ready to get started?Download WordPress

Forums

Display only images I want on a theme (4 posts)

  1. neonate928
    Member
    Posted 1 year ago #

    Hello,

    I offer several different services for my company. I have 3 separate "portfolios" for each of these services: Design, Print, and Web. The template I purchased for my website offers 4 different types of layouts (themes), 1 col, 2 col, 3 col, and 4 columns. i'm only worried about the first 3. However, the issue I am having is the themes are pulling all the images, I only want the images pulled that are associated with that particular portfolio, i.e. design only displays images for design, Print only displays images for print, etc.

    Is there a way to categorize the images and then customize the code for the themes to only pull from that category? I've include the code below for 1 col.

    I know a little php (enough to get me in trouble) I am however not to familiar with WordPress. Any help will be appreciated.

    <?php
    /**
     * Template Name: Portfolio 1 column
     */
    
    get_header(); ?>
    
    <div class="container_12">
    	<div id="content" class="grid_12">
    		<?php include_once (TEMPLATEPATH . '/title.php');?>
        <?php global $more;	$more = 0;?>
        <?php $values = get_post_custom_values("category-include"); $cat=$values[0];  ?>
        <?php $catinclude = 'portfoliocat='. $cat ;?>
    
        <?php $wp_query = new WP_Query(); ?>
        <?php $wp_query->query("post_type=portfolio&". $catinclude ."&paged=".$paged.'&showposts=5'); ?>
        <?php if ( ! have_posts() ) : ?>
        <div id="post-0" class="post error404 not-found">
          <h1 class="entry-title"><?php _e( 'Not Found', 'theme1315' ); ?></h1>
          <div class="entry-content">
            <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'theme1315' ); ?></p>
            <?php get_search_form(); ?>
          </div><!-- .entry-content -->
        </div><!-- #post-0 -->
      <?php endif; ?>
      <div id="gallery" class="one_column">
        <ul class="portfolio">
          <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
          <?php
            $custom = get_post_custom($post->ID);
            $lightbox = $custom["lightbox-url"][0];
          ?>
    
            <li>
              <div class="hr"></div>
              <div class="clearfix">
                <?php if($lightbox!=""){ ?>
                <span class="image-border"><a class="image-wrap" href="<?php echo $lightbox;?>" rel="prettyPhoto[gallery]" title="<?php the_title();?>"><?php the_post_thumbnail( 'portfolio-post-thumbnail-xl' ); ?><span class="zoom-icon"></span></a></span>
              <?php }else{ ?>
                <span class="image-border"><a class="image-wrap" href="<?php the_permalink() ?>" title="<?php _e('Permanent Link to', 'theme1315');?> <?php the_title_attribute(); ?>" ><?php the_post_thumbnail( 'portfolio-post-thumbnail-xl' ); ?><span class="zoom-icon"></span></a></span>
                <?php } ?>
                <div class="folio-desc">
                  <header>
                    <h2><a href="<?php the_permalink(); ?>"><?php $title = the_title('','',FALSE); echo substr($title, 0, 40); ?></a></h2>
                    <time datetime="<?php the_time('Y-m-d\TH:i'); ?>"><?php the_time('F j, Y'); ?></time>
                  </header>
                  <p class="excerpt"><?php $excerpt = get_the_excerpt(); echo my_string_limit_words($excerpt,50);?></p>
                  <a href="<?php the_permalink(); ?>" class="button">Read more</a>
                </div>
              </div>
            </li>
    
          <?php endwhile; ?>
        </ul>
        <div class="clear"></div>
      </div>
    
      <?php if(function_exists('wp_pagenavi')) : ?>
        <?php wp_pagenavi(); ?>
      <?php else : ?>
        <?php if ( $wp_query->max_num_pages > 1 ) : ?>
          <nav class="oldernewer">
            <div class="older">
              <?php next_posts_link('&laquo; Older Entries') ?>
            </div><!--.older-->
            <div class="newer">
              <?php previous_posts_link('Newer Entries &raquo;') ?>
            </div><!--.newer-->
          </nav><!--.oldernewer-->
        <?php endif; ?>
      <?php endif; ?>
      <!-- Page navigation -->
      </div><!-- #content -->
    </div>
    <?php get_footer(); ?>
  2. M4thieu
    Member
    Posted 1 year ago #

    <?php $catinclude = 'portfoliocat=CATEGORY_NAME'. $cat ;?>

  3. FAMC
    Member
    Posted 1 year ago #

    I have tested it with hardcoded category and subcategory values, as follows.

    But I'm not sure how to tie the pages and portfolio categories and templates all in a need bow, for a dynamic category. When I figure it out, I may re-post here.

    TEST w/ Hard-coded - category and subcategory values:
    Change:
    <?p $catinclude = 'portfoliocat='.$cat;?>
    To:
    <?p $catinclude = 'portfolio_category=PORTFOLIO_CATEGORY_SLUG'.$cat;?>

    ...where "PORTFOLIO_CATEGORY_SLUG" is substituted with your category or subcategory already defined in Portfolio categories. Of course your test will be of categories that already have posts assigned to them.

    Tested on a top level portfolio category, "Paintings", where the slug is "paintings":
    e.g., <?p $catinclude = 'portfolio_category=paintings';?>

    Tested on a portfolio subcategory, "Portraits", where the slug is "portraits":
    e.g., <?p $catinclude = 'portfolio_category=portraits';?>

    Test passed! Results were only the categories showing that I wanted.

    However, I'm so new to WP that I don't know my way around the relationships in the template system. It seems there would be a clear keyword for the category name.
    M4thieu's 'CATEGORY_NAME' did not work for me though, and neither did the original code (as posted by the op, neonate928). $cat had no value. The $values array had no count. If these were not empty, hard-coding would no doubt not be necessary.

    My goal is actually the same as the op's; and definitely with dynamic categories. I mean, that's what templates are for. So I'll keep plugging away until I see how to call these dynamically and give them the information they need to plug in that category for me.

    Hope this post helps someone along the way, though.

  4. FAMC
    Member
    Posted 1 year ago #

    Got it - the dynamic side of it that is.
    (The above post was a static test, and let me to uncover just what get_post_custom_values("category-include") meant; as my theme example pages, and documentation made no other mention of 'category- include', other than in these templates.

    Summary: By adding the custom field, "category-include" into your category-specific
    page, and setting its value to the category slug; a selected template that
    uses the php code:
    $values = get_post_custom_values("category-include"); $cat=$values[0];
    $catinclude = 'portfolio_category='. $cat ;
    to build a query, will be able to dynamically pull just the categories
    specified for each specific page using the template.

    Detail:

    • First go to Pages.
    • Find the Page that will be your very specific category page.
      • In the Page Attributes, you will see the template that you've chosen
        for this page. For example, "Folio 3" (you can rename it after you have tested your category).
    • Click "Screen Options" at the top right of the Admin area for this page.
      Check "Custom Fields" in the screen options. This is the key to the whole shebang!

    The "category-include", in the template stumped me, until I realized that it is a custom field name. None of my pages had this particular custom field name. The solution continues, below.

    • You should now have a custom field section in the base of your "Edit" screen for this page.
    • Your template providers may have a drop down list of preset custom fields. For example: "lightbox_url" and "thumb". Do not select a preset unless you see "category-include" in the list. If so select it.
    • Otherwise, click the small link below the drop down menu that says,
      "Enter new".
    • A blank "Name" field will now appear, along with it's "value" field. In the "Name" field, type category-include.
    • In the "Value" field, type the category slug, e.g., "portraits"
      Over in the "Publish" column, click "Update" to save the page.

    Now the your category page has it's shiny new custom field, "category-include", set with your target category (the slug name, that is), go to the template.

    In the Template, itself, "Edit" the following:

    • Keep the line:
      <?php $values = get_post_custom_values("category-include"); $cat=$values[0]; ?>

      This will now look for the custom field, "category-include", on any page
      which uses the template. Now the cat values make sense!

    • I changed portfoliocat to portfolio_category, as I'm on WP 3.5. Don't know if they are interchangeable or not, as this is a first install, for me. But portfolio_category definitely works for me in the templates meant for the Portfolio pages. The code will look like this, exactly:
      <?php $catinclude = 'portfolio_category='. $cat ;?>

    That's it! Hope this helps someone.

    Fran

Topic Closed

This topic has been closed to new replies.

About this Topic