• Well i have been trying to get a portfolio template working for my wordpress theme i have been making from scratch and yet another thing will not work for me, i have tried a few different tutorials to get it working but none of them work as they should, all that i can get to display is a title of one of the posts which should be shown, it will not show the content or any of the second post and for some reason the footer disapears also. I am getting very frustrated with things not working when they should from what other people have said on the websites…

    Here is the code i have entered in functions.php and portfolio.php:

    functions.php:

    <?php
    	add_action('init', 'create_portfolio');
    	function create_portfolio() {
        	$portfolio_args = array(
            	'label' => __('Portfolio'),
            	'singular_label' => __('Portfolio'),
            	'public' => true,
            	'show_ui' => true,
            	'capability_type' => 'post',
            	'hierarchical' => false,
            	'rewrite' => true,
            	'supports' => array('title', 'editor', 'thumbnail')
            );
        	register_post_type('portfolio',$portfolio_args);
    	}
    ?>
    
    <?php
    	add_action("admin_init", "add_portfolio");
    	add_action('save_post', 'update_website_url');
    	function add_portfolio(){
    		add_meta_box("portfolio_details", "Portfolio Options", "portfolio_options", "portfolio", "normal", "low");
    	}
    	function portfolio_options(){
    		global $post;
    		$custom = get_post_custom($post->ID);
    		$website_url = $custom["website_url"][0];
    ?>
    	<div id="portfolio-options">
    		<label>Website URL:</label><input name="website_url" value="<?php echo $website_url; ?>" />
    	</div><!--end portfolio-options-->
    <?php
    	}
    	function update_website_url(){
    		global $post;
    		update_post_meta($post->ID, "website_url", $_POST["website_url"]);
    	}
    ?>
    
    <?php
    add_filter("manage_edit-portfolio_columns", "portfolio_edit_columns");
    add_action("manage_posts_custom_column",  "portfolio_columns_display");
    
    function portfolio_edit_columns($portfolio_columns){
    	$portfolio_columns = array(
    		"cb" => "<input type=\"checkbox\" />",
    		"title" => "Project Title",
    		"description" => "Description",
    	);
    	return $portfolio_columns;
    }
    
    function portfolio_columns_display($portfolio_columns){
    	switch ($portfolio_columns)
    	{
    		case "description":
    			the_excerpt();
    			break;
    	}
    }
    ?>

    And the portfolio.php:

    <?php
    /*
    Template Name: Portfolio
    */
    ?>
    <?php get_header(); ?>
    	<div id="content">
    	<?php
    		$loop = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => 10));
    	?>
    	<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    	<?php
    		$custom = get_post_custom($post->ID);
    		$screenshot_url = $custom["screenshot_url"][0];
    		$website_url = $custom["website_url"][0];
    	?>
            <div id="portfolio-item">
    		<h1><?php the_title(); ?></h1>
    		<a>"><?php the_post_thumbnail(); ?> </a>
    		<?php the_content(); ?>
    	</div>
            <?php endwhile; ?>
            </div><!-- #content -->
    <?php get_footer(); ?>
Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter lukewilde

    (@lukewilde)

    Can anyone help?

    If this is on a live site a link to see the actual HTML output would be helpful.

    Also in your portfolio.php you have <a>"><?php the_post_thumbnail(); ?> </a>
    I’m not sure what that might do to the resulting HTML output but it is definitely wrong.
    You want something like :
    <a href="<?php echo your_link_goes_here; ?>"><?php the_post_thumbnail(); ?></a>

    If you have misordered HTML tags and extra ‘<‘ or ‘>’ it can cause the rest of the HTML to not display or display incorrectly.

    Hope this helps.

    Also you might want to put the post thumbnail inside a check to see if one exists like this:

    <?php if(has_post_thumbnail()) : ?>
    <a href="<?php echo your_link_goes_here; ?>"><?php the_post_thumbnail(); ?></a>
    <?php endif; ?>

    Unless you know for sure that all your posts will have thumbnails.

    Thread Starter lukewilde

    (@lukewilde)

    Well i have copied the code from the tutorial which other people have said works for them so i dont get how it could be wrong, i will try what you have suggested and see if it works.

    Also it is not live as i am only working on it locally.

    Thread Starter lukewilde

    (@lukewilde)

    Just tried it and still doesn’t work, and the code i pasted of the portfolio.php somehow missed out the actual code you corrected, it is actually:

    <a href="<?=$website_url?>"><?php the_post_thumbnail(); ?> </a>

    I don’t know what i am doing wrong 🙁 i follow the guides exactly but they almost never work on my theme and it is very annoying.

    The php code looks fine to me.

    When you view the page source code from the browser does each opening tag have a closing tag and vice versa?

    Thread Starter lukewilde

    (@lukewilde)

    Well the code doesn’t even finish in the page source so something must be very wrong 🙁 Here is what the source is showing:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>New WordPress &raquo; Portfolio</title>
    	<link rel="alternate" type="application/rss+xml" title="RSS 2.0 - all posts" href="" />
    	<link rel="alternate" type="application/rss+xml" title="RSS 2.0 - all comments" href="http://localhost:8888/wordpress/?feed=comments-rss2" />
    	<link rel="pingback" href="http://localhost:8888/wordpress/xmlrpc.php" />
    
    <link rel="stylesheet" href="http://localhost:8888/wordpress/wp-content/themes/Blistex/style.css" type="text/css" media="screen" />
    
    <script type="text/javascript" src="http://localhost:8888/wordpress/wp-content/themes/Blistex/menu.js"></script>
    <script type="text/javascript" src="http://localhost:8888/wordpress/wp-content/themes/Blistex/swfobject/swfobject.js"></script>
    
    <!-- Include jQuery -->
    <link rel="alternate" type="application/rss+xml" title="New WordPress &raquo; Portfolio Comments Feed" href="http://localhost:8888/wordpress/?feed=rss2&page_id=273" />
    <script type='text/javascript' src='http://localhost:8888/wordpress/wp-includes/js/jquery/jquery.js?ver=1.4.2'></script>
    <link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://localhost:8888/wordpress/xmlrpc.php?rsd" />
    <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://localhost:8888/wordpress/wp-includes/wlwmanifest.xml" />
    <link rel='index' title='New WordPress' href='http://localhost:8888/wordpress' />
    <link rel='prev' title='Contact' href='http://localhost:8888/wordpress/?page_id=23' />
    <meta name="generator" content="WordPress 3.0.1" />
    
    <link rel='canonical' href='http://localhost:8888/wordpress/?page_id=273' />
    	<style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
    <!-- Include the Nivo Slider CSS file -->
    <link rel="stylesheet" href="http://localhost:8888/wordpress/wp-content/themes/Blistex/nivo-slider.css" type="text/css" media="screen" />
    <!-- Include the Nivo Slider JS file -->
    <script src="http://localhost:8888/wordpress/wp-content/themes/Blistex/jquery.nivo.slider.js" type="text/javascript"></script>
    <!-- Set up the Nivo Slider -->
    <script type="text/javascript">
    jQuery(window).load(function() {
    	jQuery('#slider').nivoSlider();
    });
    </script>
    
    </head>
    
    <body>
    
    <div id="wrapper">
    
    	<div id="header">
    
    	<p class="description">Just another WordPress site</p>
    
    	<h1 id="logo"><a href="http://localhost:8888/wordpress/">New WordPress</a></h1>
    
    	</div>
    
        <ul id="menus">
    	<li class="page_item page-item-119"><a href="http://localhost:8888/wordpress/?page_id=119" title="About">About</a></li>
    <li class="page_item page-item-273 current_page_item"><a href="http://localhost:8888/wordpress/?page_id=273" title="Portfolio">Portfolio</a></li>
    <li class="page_item page-item-23"><a href="http://localhost:8888/wordpress/?page_id=23" title="Contact">Contact</a></li>
    	</ul>
    
        <div class="clear"></div>
    
    	<div id="content">
    			        <div id="portfolio-item">
    
    		<h1>Testing post</h1>
    		<a href="">

    Does it display any php warnings/errors?
    Do you have them turned on in your php ini file?

    That looks to me like your <?=$website_url?> is outputting nothing, this could be because the variable is empty. Or because you have output errors turned off in your php ini file and also have short tags turned off.

    Also it is breaking here <?php the_post_thumbnail(); ?> have you enabled post thumbnails?

    If not you need add_theme_support( 'post-thumbnails' ); in your functions.php file.

    Thread Starter lukewilde

    (@lukewilde)

    Haha i feel bad that it was so simple, i had the post thumbnails add support in my function before and i must have deleted it at some point in frustration. I think it is working now, hopefully i can finally finish the portfolio pages.

    Thanks a lot for the help.

    No problem.

    Glad it’s working now.

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

The topic ‘Portfolio tutorial not working.’ is closed to new replies.