Decarn Posted November 16, 2014 Share Posted November 16, 2014 Hi, I'm trying to combine the two codes below so that my images can be styled by CSS? echo '<img src="' . get_stylesheet_directory_uri() . '/images/category-two.png' . '" alt="Your Alt Text" />'; array( 'class' => 'alignleft' ) Thanks for your time. Quote Link to comment https://forums.phpfreaks.com/topic/292501-how-to-call-a-css/ Share on other sites More sharing options...
maxxd Posted November 16, 2014 Share Posted November 16, 2014 In WordPress, you include style sheets with the wp_enqueue_style() function that you can call using the wp_enqueue_scripts hook. function queueMyStyles(){ wp_enqueue_style('subbranding',get_stylesheet_directory_uri()."/myStyle.css",'site-style'); } add_action('wp_enqueue_scripts','queueMyStyles'); Quote Link to comment https://forums.phpfreaks.com/topic/292501-how-to-call-a-css/#findComment-1496736 Share on other sites More sharing options...
Decarn Posted November 16, 2014 Author Share Posted November 16, 2014 Hi, Sorry if this is the code, how do I call alignleft in style.css for /images/default-image.jpg? add_filter( 'genesis_pre_get_image', 'category_featured_image_fallback' ); function category_featured_image_fallback() { if ( has_post_thumbnail()) : the_post_thumbnail( 'thumbnail', array( 'class' => 'alignleft' ) ); elseif ( in_category( 'shares-derivatives' ) ) : echo '<img src="' . get_stylesheet_directory_uri() . '/images/default-image.jpg' . '" alt="Shares & Derivatives Left" />'; elseif ( in_category( 'two' ) ) : echo '<img src="' . get_stylesheet_directory_uri() . '/images/category-two.png' . '" alt="Your Alt Text" />'; else: echo '<img src="' . get_stylesheet_directory_uri() . '/images/default-image.png' . '" alt="No Category" />'; endif; } Quote Link to comment https://forums.phpfreaks.com/topic/292501-how-to-call-a-css/#findComment-1496764 Share on other sites More sharing options...
maxxd Posted November 17, 2014 Share Posted November 17, 2014 You just add "class='alignleft'" to the <img /> line. The only reason that the class is 'called' for the thumbnail is that the_post_thumbnail() is a template tag and by default outputs the source code, so the theme developer is passing the class name into the function call as one of the optional parameters. Quote Link to comment https://forums.phpfreaks.com/topic/292501-how-to-call-a-css/#findComment-1496781 Share on other sites More sharing options...
Decarn Posted November 17, 2014 Author Share Posted November 17, 2014 Thanks I tried to insert the "ccode in but my page could not load. Is my code correct? echo '<img "class='alignleft'" src="' . get_stylesheet_directory_uri() . '/images/default-image.jpg' . '" alt="Shares & Derivatives Left" />'; Quote Link to comment https://forums.phpfreaks.com/topic/292501-how-to-call-a-css/#findComment-1496841 Share on other sites More sharing options...
LeJack Posted November 18, 2014 Share Posted November 18, 2014 I see that you're not too familiar with PHP. I suggest you learn it from the official website because that will help you much more. If you learn it from a tutorial, you won't get any where. In addition, you're placing your edits in the wrong places. echo '<img class="alignleft" src="' . get_stylesheet_directory_uri() . '/images/default-image.jpg" alt="Shares & Derivatives Left" />'; Take out all those double single quotes. You're placing them where they aren't suppose to and you're placing them where you don't have any PHP codes. You need to learn the basics of HTML too if you're not sure where to put the double quotes. Quote Link to comment https://forums.phpfreaks.com/topic/292501-how-to-call-a-css/#findComment-1496845 Share on other sites More sharing options...
maxxd Posted November 18, 2014 Share Posted November 18, 2014 I have to agree with LeJack on this one - taking some time to learn a little HTML, CSS, php, and WordPress is going to help a lot in this situation. The thing about WordPress is that it's great for end-users, but once you start digging into and modifying the code, it's kind of a nightmare from that perspective. The reliance on global functions and variables can make things difficult to follow and really isn't good modern coding, so you should have a decent grounding in php to know when and how to break both php's and WordPress's rules. And no offense, but if you don't know how to assign a class to a DOM element, you're going to be in over your head quickly. The nice thing is, it doesn't take a whole lot of time to learn the basics that you need to know. That being said, you do need to know those basics. 1 Quote Link to comment https://forums.phpfreaks.com/topic/292501-how-to-call-a-css/#findComment-1496928 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.