{"id":111,"date":"2008-10-05T08:09:51","date_gmt":"2008-10-05T08:09:51","guid":{"rendered":"http:\/\/30dayloa.com\/?p=111"},"modified":"2008-10-05T08:09:51","modified_gmt":"2008-10-05T08:09:51","slug":"how-to-create-a-default-image-for-the-unstandard-theme","status":"publish","type":"post","link":"https:\/\/30dayloa.com\/blog\/how-to-create-a-default-image-for-the-unstandard-theme\/","title":{"rendered":"How to create a default image for the Unstandard theme"},"content":{"rendered":"<p>Two tweaks for the Unstandard theme:<\/p>\n<p>How to specify a default image for lead_image and secondary_image and<br \/>\nHow to make the home page show posts from only one category.<\/p>\n<p>I know, this is another off-topic post but I&#8217;ve had so many people write in to me wanting to know about the tweaks I&#8217;ve been doing for this theme that I just thought I&#8217;d put it out there.<br \/>\n[grin] Maybe it&#8217;s how I&#8217;m going to do some more &#8216;attraction&#8217; of readers???<\/p>\n<p>Anyway, I&#8217;ve been wanting to set up the theme for a while so that if I didn&#8217;t have the time (or inspiration) to create a custom image for lead_image and secondary_image, the page would revert to using a default one.  Plus, of course, it would mean I could occasionally post remotely from places where I didn&#8217;t have access to ftp and image software.  Turns out it&#8217;s not actually that hard.<\/p>\n<p>The line of code that looks for the image to use on your home page is, funnily enough, home.php.  (There&#8217;s a similar entry under index.php but it only looks for secondary images, so I suspect that&#8217;s called when you&#8217;ve got some kind of page navigation plugin that lets you go back to previous entries.  I put the fix in there too just to be certain.)<\/p>\n<p>You&#8217;re looking for the code:<\/p>\n<blockquote><p>&lt;?php $top_query = new WP_Query(&#8216;showposts=1&#8217;); ?&gt;<br \/>\n&lt;?php while($top_query-&gt;have_posts()) : $top_query-&gt;the_post(); $first_post = $post-&gt;ID; ?&gt;<br \/>\n&lt;div class=&#8221;post&#8221; id=&#8221;post-&lt;?php the_ID(); ?&gt;&#8221;&gt;<br \/>\n&lt;div class=&#8221;main-post-bg&#8221;&gt;<br \/>\n&lt;p class=&#8221;post-comments&#8221;&gt;&lt;?php comments_popup_link(&#8216;No Comments&#8217;, &#8216;1 Comment&#8217;, &#8216;% Comments&#8217;); ?&gt;&lt;\/p&gt;<br \/>\n&lt;?php $image = get_post_meta($post-&gt;ID, &#8216;lead_image&#8217;, true); ?&gt;<br \/>\n&lt;a href=&#8221;&lt;?php the_permalink() ?&gt;&#8221; title=&#8221;&lt;?php the_title(); ?&gt;&#8221;&gt;&lt;img width=&#8221;593&#8243; src=&#8221;&lt;?php echo $image; ?&gt;&#8221; alt=&#8221;&#8221; \/&gt;&lt;\/a&gt;<br \/>\n&lt;div id=&#8221;post-&lt;?php the_ID(); ?&gt;&#8221; class=&#8221;post&#8221;&gt;<br \/>\n&lt;div class=&#8221;main-post-bg&#8221;>&lt;a title=&#8221;&lt;?php the_title(); ?&gt;&#8221; href=&#8221;&lt;?php the_permalink() ?&gt;&#8221;&gt;&lt;img src=&#8221;&lt;?php echo $image; ?&gt;&#8221; alt=&#8221;&#8221; width=&#8221;593&#8243; \/&gt;&lt;\/a&gt;<\/p><\/blockquote>\n<p>The line in there that calls the image is &lt;?php $image = get_post_meta($post-&gt;ID, &#8216;lead_image&#8217;, true); ?&gt;.\u00a0 You can add in a string just after the last semicolon that tells it what to look for if there is no &#8216;lead_image&#8217; specified by changing it to:<\/p>\n<blockquote><p>&lt;?php $image = get_post_meta($post-&gt;ID, &#8216;lead_image&#8217;, true); $image = $image ? $image : &#8216;..\/images\/default_img.jpg&#8217;; ?&gt;<\/p><\/blockquote>\n<p>Of course, you&#8217;d change the path to whatever points to your default picture, and make sure it&#8217;s sized properly (593 x 225px).<\/p>\n<p>Then you need to do something similar to point to your default &#8216;secondary_image&#8217;.\u00a0 It looks just like the above line, but about 15 lines down and says &#8216;secondary_image&#8217; instead of &#8216;lead_image&#8217;.\u00a0 That one will need to be sized 293&#215;150, if you&#8217;re still using the unstandard default sizing.\u00a0 To make it easy, here&#8217;s a cut and paste again:<\/p>\n<blockquote><p>&lt;?php $image = get_post_meta($post-&gt;ID, &#8216;secondary_image&#8217;, true); $image = $image ? $image : &#8216;..\/images\/default_img2.jpg&#8217;; ?&gt;<\/p><\/blockquote>\n<p>And finally, for those that have asked me how I made my home page show only selected posts, I created a category called &#8216;Featured&#8217; and only those will show up on the front page.\u00a0 It was my workaround for posts where I didn&#8217;t have images &#8211; I just wouldn&#8217;t assign them to that category and the pictures wouldn&#8217;t be needed.\u00a0 How?\u00a0 The line:<\/p>\n<blockquote><p>&lt;?php $top_query = new WP_Query(&#8216;showposts=1&#8217;); ?&gt;<br \/>\n&#8230;and further down&#8230;<br \/>\n&lt;?php query_posts(&#8216;showposts=15&#8217;); ?&gt;<\/p><\/blockquote>\n<p>got changed to:<\/p>\n<blockquote><p>&lt;?php $top_query = new WP_Query(&#8216;showposts=1&amp;category_name=Featured&#8217;); ?&gt;<br \/>\n&#8230;and&#8230;<br \/>\n&lt;?php query_posts(&#8216;showposts=15&amp;category_name=Featured&#8217;); ?&gt;<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Two tweaks for the Unstandard theme: How to specify a default image for lead_image and secondary_image and How to make the home page show posts from only one category. I know, this is another off-topic post but I&#8217;ve had so many people write in to me wanting to know about the tweaks I&#8217;ve been doing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,59,60],"tags":[66,91,92,65,67,61],"class_list":["post-111","post","type-post","status-publish","format-standard","hentry","category-30-day-loa","category-featured","category-web-design","tag-customizing","tag-default-images","tag-home-page-category","tag-scripting","tag-the-unstandard","tag-wordpress-theme"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/30dayloa.com\/blog\/wp-json\/wp\/v2\/posts\/111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/30dayloa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/30dayloa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/30dayloa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/30dayloa.com\/blog\/wp-json\/wp\/v2\/comments?post=111"}],"version-history":[{"count":8,"href":"https:\/\/30dayloa.com\/blog\/wp-json\/wp\/v2\/posts\/111\/revisions"}],"predecessor-version":[{"id":119,"href":"https:\/\/30dayloa.com\/blog\/wp-json\/wp\/v2\/posts\/111\/revisions\/119"}],"wp:attachment":[{"href":"https:\/\/30dayloa.com\/blog\/wp-json\/wp\/v2\/media?parent=111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/30dayloa.com\/blog\/wp-json\/wp\/v2\/categories?post=111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/30dayloa.com\/blog\/wp-json\/wp\/v2\/tags?post=111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}