vendredi 27 mars 2015

Conditional statements in wordpress themes


I have the following code at the start of my single.php loop that displays the post featured image as a background.



<?php $featured_background = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'full' ); ?>

<div class="parallax" id="parallax1" style="background: url(<?php echo $featured_background['0'];?>) !important; background-position: 50% 50% !important; background-repeat: no-repeat !important; background-size: cover !important; background-attachment: fixed !important;" data-stellar-background-ratio=".5">
<div class="parallax-content">
Some content
</div>
</div>


I've set .parallax to be 600px high in the stylesheet.


Of course this poses a problem for posts that don't have a featured image.


It seems then that I need a conditional statement that only displays the code above if the post has a thumbnail.


I've looked at the wordpress codex, but am unsure how to apply the teachings there to my case. It also looks like they'd be a lot of use of the echo command due to all the HTML.


I think I understand the first part of the statement which will be something like:



<?php

if ( has_post_thumbnail() ) {
echo'my html code as above'
}
else {
just get on with rendering the rest of the page
}
?>


But then I don't understand how to tell it to just get on with rendering the page in the else statement.





String taken from database table post_meta is showing HTML tags on Frontend


I have saved a string in post_meta table in wordpress database with html entities like-


<p>Hello <b>Shashank</b>, I have an idea.</p>


When I get this string on frontend using function


get_post_meta(get_the_id(),field_name, true).


It echoes string with HTML entities as same as it stores in DB.


But I want to show this sting as "Hello Shashank, I have an idea."


How can I do this.?





Submit a form without keyboard input, addition with the help of button


I am new to WordPress. I want to create sales status website, something like this...


< - button>Item 1< + button> < - button>Item 2< + button> < - button>Item 3< + button> < - button>Item 4< + button> I want a plus and minus button to add the number of a particular item.


For example if I sold (item 1) 4 times, I will click it 4 times and the number will show at the bottom.


Do I need to use a form plugin for this





I can't use nth-child on pair divs


i'm trying put pair divs with float:right but don't work. Only work with li???


I need put < div class="portfolio-entry-media" > only pairs (2, 4, 6...) with float right. Is this possible? thanks!


this is the code



<div class="wpex-row vcex-portfolio-grid clr left-thumbs" data-transition-duration="0.0">

<div class="post-359 portfolio type-portfolio status-publish has-post-thumbnail hentry portfolio-entry span_1_of_1 col col-1 cat-38">



<div class="portfolio-entry-media">


<img src="http://ift.tt/1yiI4zD" width="222" height="167" class="portfolio-entry-img" alt="Bótox">



</div><!-- .portfolio-entry-media -->




<div class="portfolio-entry-details clr">



<h2 class="portfolio-entry-title entry-title">


<a href="http://ift.tt/1MbaiYA" title="Bótox">
Bótox </a>


</h2>




<div class="portfolio-entry-excerpt clr">
<p>Maecenas nec ultrices massa. Quisque orci diam, malesuada id augue nec, faucibus interdum dolor. Curabitur sagittis, felis porttitor placerat rhoncus, mauris diam sollicitudin nisl, sed luctus nulla sem non velit. Fusce a libero ullamcorper, volutpat orci ut, suscipit erat. Morbi tempor tortor vel urna lobortis. Hendrerit faucibus massa consequat. Vivamus feugiat sapien massa, non luctus purus scelerisque et. Donec sodales pellentesque diam, et adipiscing erat imperdiet ac. Integer a lacinia velit. Pellentesque eu adipiscing arcu, a eleifend nulla. Vivamus tempus sem erat, eget lobortis odio interdum at. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Interdum et malesuada fames ac ante ipsum primis in faucibus. Phasellus et feugiat risus. Ut a egestas libero. Morbi dictum quis felis vel congue. Sed eu arcu auctor, volutpat justo et, egestas libero. Phasellus sagittis sem in iaculis faucibus. Aenean vel lacus purus.</p>
</div><!-- .portfolio-entry-excerpt -->




</div><!-- .portfolio-entry-details -->


</div><!-- .portfolio-entry -->



<div class="post-265 portfolio type-portfolio status-publish has-post-thumbnail hentry portfolio-entry span_1_of_1 col col-1 cat-38">



<div class="portfolio-entry-media">


<img src="http://ift.tt/1Mbagjr" width="222" height="167" class="portfolio-entry-img" alt="Ácido Hialurónico">



</div><!-- .portfolio-entry-media -->




<div class="portfolio-entry-details clr">



<h2 class="portfolio-entry-title entry-title">


<a href="http://ift.tt/1yiI4zG" title="Ácido Hialurónico">
Ácido Hialurónico </a>


</h2>




<div class="portfolio-entry-excerpt clr">
<p>Donec sed vulputate nunc, at fringilla purus. Nulla molestie ut turpis sit amet suscipit. Nullam vulputate diam elit, ac varius turpis vestibulum aliquet. Vestibulum mattis purus et blandit hendrerit. Nulla luctus nisi et pellentesque aliquam. Morbi orci massa, vestibulum vel urna quis, porta interdum libero. Vivamus id eros congue, lacinia elit eget, condimentum risus. </p>
</div><!-- .portfolio-entry-excerpt -->




</div><!-- .portfolio-entry-details -->


</div><!-- .portfolio-entry -->



<div class="post-342 portfolio type-portfolio status-publish has-post-thumbnail hentry portfolio-entry span_1_of_1 col col-1 cat-38">



<div class="portfolio-entry-media">


<img src="http://ift.tt/1MbaiYD" width="222" height="167" class="portfolio-entry-img" alt="Mesoterapia">



</div><!-- .portfolio-entry-media -->




<div class="portfolio-entry-details clr">



<h2 class="portfolio-entry-title entry-title">


<a href="http://ift.tt/1yiI3f9" title="Mesoterapia">
Mesoterapia </a>


</h2>




<div class="portfolio-entry-excerpt clr">
<p>Integer semper malesuada elit. Donec consequat nulla nunc. Praesent nisi ipsum, imperdiet et venenatis et, sagittis nec mi. Phasellus luctus diam elit. Integer porta adipiscing felis ultrices viverra. Morbi tempor tortor vel urna lobortis. Hendrerit faucibus massa consequat. Vivamus feugiat sapien massa, non luctus purus scelerisque et. Donec sodales pellentesque diam, et adipiscing erat imperdiet ac. Integer a lacinia velit. Pellentesque eu adipiscing arcu, a eleifend nulla. Vivamus tempus sem erat, eget lobortis odio interdum at. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Interdum et malesuada fames ac ante ipsum primis in faucibus. Phasellus et feugiat risus. Ut a egestas libero. Morbi dictum quis felis vel congue. Sed eu arcu auctor, volutpat justo et, egestas libero. Phasellus sagittis sem in iaculis faucibus. Aenean vel lacus purus.</p>
</div><!-- .portfolio-entry-excerpt -->




</div><!-- .portfolio-entry-details -->


</div><!-- .portfolio-entry -->



<div class="post-324 portfolio type-portfolio status-publish has-post-thumbnail hentry portfolio-entry span_1_of_1 col col-1 cat-38">



<div class="portfolio-entry-media">


<img src="http://ift.tt/1MbaiYG" width="222" height="167" class="portfolio-entry-img" alt="Hilos Tensores">



</div><!-- .portfolio-entry-media -->




<div class="portfolio-entry-details clr">



<h2 class="portfolio-entry-title entry-title">


<a href="http://ift.tt/1Mbagjx" title="Hilos Tensores">
Hilos Tensores </a>


</h2>




<div class="portfolio-entry-excerpt clr">
<p>Curabitur metus lectus, condimentum eu lacinia sed, aliquam et nibh. Nullam et mi eu ipsum accumsan vestibulum. Donec dignissim, nibh vel consequat molestie, lacus felis suscipit velit, sit amet mollis mauris sem at leo ullamcorper, volutpat orci ut, suscipit erat. Morbi tempor tortor vel urna lobortis. Hendrerit faucibus massa consequat. Vivamus feugiat sapien massa, non luctus purus scelerisque et. Donec sodales pellentesque diam, et adipiscing erat imperdiet ac. Integer a lacinia velit. Pellentesque eu adipiscing arcu, a eleifend nulla. Vivamus tempus sem erat, eget lobortis odio interdum at. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Interdum et malesuada fames ac ante ipsum primis in faucibus. Phasellus et feugiat risus. Ut a egestas libero. Morbi dictum quis felis vel congue. Sed eu arcu auctor, volutpat justo et, egestas libero. Phasellus sagittis sem in iaculis faucibus. Aenean vel lacus purus.</p>
</div><!-- .portfolio-entry-excerpt -->




</div><!-- .portfolio-entry-details -->


</div><!-- .portfolio-entry -->



<div class="post-350 portfolio type-portfolio status-publish has-post-thumbnail hentry portfolio-entry span_1_of_1 col col-1 cat-38">



<div class="portfolio-entry-media">


<img src="http://ift.tt/1yiI4PX" width="222" height="167" class="portfolio-entry-img" alt="Carboxiterapia">



</div><!-- .portfolio-entry-media -->




<div class="portfolio-entry-details clr">



<h2 class="portfolio-entry-title entry-title">


<a href="http://ift.tt/1yiI4PY" title="Carboxiterapia">
Carboxiterapia </a>


</h2>




<div class="portfolio-entry-excerpt clr">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent pretium turpis rhoncus, ultrices quam vel, aliquam lorem. Suspendisse mattis nisl nibh, sit amet pharetra velit auctor vitae. In lacus nibh, bibendum vitae varius vitae, mollis at ipsum. Nullam fermentum purus arcu, sed fringilla libero imperdiet ac. Sed tincidunt fringilla nunc, sed sollicitudin ante interdum id.</p>
</div><!-- .portfolio-entry-excerpt -->




</div><!-- .portfolio-entry-details -->


</div><!-- .portfolio-entry -->



<div class="post-336 portfolio type-portfolio status-publish has-post-thumbnail hentry portfolio-entry span_1_of_1 col col-1 cat-38">



<div class="portfolio-entry-media">


<img src="http://ift.tt/1yiI4PZ" width="222" height="167" class="portfolio-entry-img" alt="Rinomodelación">



</div><!-- .portfolio-entry-media -->




<div class="portfolio-entry-details clr">



<h2 class="portfolio-entry-title entry-title">


<a href="http://ift.tt/1yiI3vt" title="Rinomodelación">
Rinomodelación </a>


</h2>




<div class="portfolio-entry-excerpt clr">
<p>Maecenas nec ultrices massa. Quisque orci diam, malesuada id augue nec, faucibus interdum dolor. Curabitur sagittis, felis porttitor placerat rhoncus, mauris diam sollicitudin nisl, sed luctus nulla sem non velit. Fusce a libero ullamcorper, volutpat orci ut, suscipit erat. Morbi tempor tortor vel urna lobortis. Hendrerit faucibus massa consequat. Vivamus feugiat sapien massa, non luctus purus scelerisque et. Donec sodales pellentesque diam, et adipiscing erat imperdiet ac. Integer a lacinia velit. Pellentesque eu adipiscing arcu, a eleifend nulla. Vivamus tempus sem erat, eget lobortis odio interdum at. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Interdum et malesuada fames ac ante ipsum primis in faucibus. Phasellus et feugiat risus. Ut a egestas libero. Morbi dictum quis felis vel congue. Sed eu arcu auctor, volutpat justo et, egestas libero. Phasellus sagittis sem in iaculis faucibus. Aenean vel lacus purus.</p>
</div><!-- .portfolio-entry-excerpt -->




</div><!-- .portfolio-entry-details -->


</div><!-- .portfolio-entry -->



<div class="post-380 portfolio type-portfolio status-publish has-post-thumbnail hentry portfolio-entry span_1_of_1 col col-1 cat-38">



<div class="portfolio-entry-media">


<img src="http://ift.tt/1MbaiYJ" width="222" height="167" class="portfolio-entry-img" alt="Escleroterapia">



</div><!-- .portfolio-entry-media -->




<div class="portfolio-entry-details clr">



<h2 class="portfolio-entry-title entry-title">


<a href="http://ift.tt/1yiI4Q2" title="Escleroterapia">
Escleroterapia </a>


</h2>




<div class="portfolio-entry-excerpt clr">
<p>Maecenas nec ultrices massa. Quisque orci diam, malesuada id augue nec, faucibus interdum dolor. Curabitur sagittis, felis porttitor placerat rhoncus, mauris diam sollicitudin nisl, sed luctus nulla sem non velit. Fusce a libero ullamcorper, volutpat orci ut, suscipit erat. Morbi tempor tortor vel urna lobortis. Hendrerit faucibus massa consequat. Vivamus feugiat sapien massa, non luctus purus scelerisque et. Donec sodales pellentesque diam, et adipiscing erat imperdiet ac. Integer a lacinia velit. Pellentesque eu adipiscing arcu, a eleifend nulla. Vivamus tempus sem erat, eget lobortis odio interdum at. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Interdum et malesuada fames ac ante ipsum primis in faucibus. Phasellus et feugiat risus. Ut a egestas libero. Morbi dictum quis felis vel congue. Sed eu arcu auctor, volutpat justo et, egestas libero. Phasellus sagittis sem in iaculis faucibus. Aenean vel lacus purus.</p>
</div><!-- .portfolio-entry-excerpt -->




</div><!-- .portfolio-entry-details -->


</div><!-- .portfolio-entry -->



<div class="post-371 portfolio type-portfolio status-publish has-post-thumbnail hentry portfolio-entry span_1_of_1 col col-1 cat-38">



<div class="portfolio-entry-media">


<img src="http://ift.tt/1MbaiYK" width="222" height="167" class="portfolio-entry-img" alt="Piel Perfecta">



</div><!-- .portfolio-entry-media -->




<div class="portfolio-entry-details clr">



<h2 class="portfolio-entry-title entry-title">


<a href="http://ift.tt/1MbagzS" title="Piel Perfecta">
Piel Perfecta </a>


</h2>




<div class="portfolio-entry-excerpt clr">
<p>Nullam volutpat libero vel dolor bibendum, vel vestibulum orci congue. Suspendisse potenti. Ut eu condimentum velit, in varius diam. Phasellus vitae arcu placerat, tristique mi ut, tincidunt leo. Aenean nec felis augue. Vivamus blandit turpis at dictum accumsan. Fusce adipiscing rutrum nibh, ac fermentum urna dictum eu. Nunc ullamcorper aliquet sagittis. Maecenas euismod lacus a pulvinar luctus. Interdum et malesuada fames ac ante ipsum primis in faucibus. Phasellus et feugiat risus. Ut a egestas libero. Morbi dictum quis felis vel congue. Sed eu arcu auctor, volutpat justo et, egestas libero. Phasellus sagittis sem in iaculis faucibus. Aenean vel lacus purus.</p>
</div><!-- .portfolio-entry-excerpt -->




</div><!-- .portfolio-entry-details -->


</div><!-- .portfolio-entry -->



</div>




wp_get_attachment_image_src and server path


wp_get_attachment_image_src will give me URL and dimensions for an image.


But is there any way to get the server path for a scaled image (like /html/wordpress/wp-content/uploads/2015/03/cat-2-300x225.jpeg)? I know about get_attached_file but this returns only the original image.


I'd like to avoid hacky solutions (string-replacing domains and such) or using WP_Image_Editor directly. Also it should be multisite-proof. Is there something official I've just missed?





Wordpress Home page issue


At this point, I can only do changes to my home page at tomwitek.com by doing changes directly to html and uploading it to my server directly. My static page is set in the Reading to Home which was a page I created for displaying the tomwitek.com. The page i used was http://ift.tt/1HVQK3X


Now, I was able to change this page directly using pages panel and it would update the page at Home location. What happens right now is that even though I deleted the http://ift.tt/1HVQK3X at some point the home page was still loading as if the page was there, so now i can only make changes through html.index and only to homepage.


How do I fix this so that it goes back to me being able to do changes through wordpress pages panel instead of doing changes to index.html?


Also, whenever i do changes to index.html (for example I combined 38 css files into 2 (cant get it to one because it breaks my site in IE) these changes are not reflected on my other pages on the site (they still use the original calls for css and js so i get bad Google speed all around)


Which file caused this changes to happen, I am not sure if this was something I did or it happened when there was upgrade to wordpress or upgrade to php?


Help needed.





Is possible to add post-formats to custom-post-type?


I was wondering if there is some way to put together the custom-post-types and post-formats so I can code a new post type and offer some variations as post-formats.


I'm involved in a company directory conceptualization and we have to mix different kind of company. While almost all of this types share the same data fields, there are two specific kind of companies - hotels & bistros - which has especific requirements (custom taxonomies and some data fields).


In your opinion, which is the best approach?



  • Use three custom-post-type: 'company', 'bistro' & 'hotel'.

  • Use one custom-post-type w/ post-formats.

  • Use only one custom-post-type and use conditional logic to add or not specific data-models.


Thanks in advance!!!


Xavier