I'm trying to generate dynamicly css file.
global $my_options;
WP_Filesystem();
global $wp_filesystem;
$css = '';
$file = './css/compile.css';
$css .= '
a{
color: '. $my_options['link-color']['regular'] .';
}
a:hover{
color: '. $my_options['link-color']['hover'] .';
}
';
if(!$wp_filesystem->put_contents($file, $css, FS_CHMOD_FILE)) {
echo 'Generating CSS error!';
}
var_dump($wp_filesystem->get_contents($file));
var_dump returns string(69) " a{ color: #81d742; } a:hover{ color: #1e73be; } ", but when I observing file compile.css - it hasn't any changes. I can't figure out what is the reason for this problem.
try with replacing two lines:
global $my_options;
global $wp_filesystem;
WP_Filesystem();
$css = '';
$file = './css/compile.css';
$css .= '
a{
color: '. $my_options['link-color']['regular'] .';
}
a:hover{
color: '. $my_options['link-color']['hover'] .';
}
';
if(!$wp_filesystem->put_contents($file, $css, FS_CHMOD_FILE)) {
echo 'Generating CSS error!';
}
var_dump($wp_filesystem->get_contents($file));
i have the same problem, solved by doing this
thanks
replace
$file = './css/compile.css';
with
$file = plugin_dir_path( __FILE__ ).'css/compile.css';
it will work fine..
Related
I have theme customize function in my customizer.php file:
function mytheme_customize_register( $wp_customize ) {
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
}
But I can't change header_textcolor using theme customizer. How can I use header text color value in my theme?
My header css:
.navbar-default .navbar-nav>.active>a {
color: #777;
background-color: transparent;
}
You can use the header_textcolor value by using get_theme_mod( 'header_textcolor' ) and use that value where applicable. For your specific solution, drop the following code somewhere in functions.php:
function my_styles_method() {
$color = get_theme_mod( 'header_textcolor' ); ?>
<style>
.navbar-default .navbar-nav>.active>a {
color: <?php echo esc_attr( $color ); ?>;
background-color: transparent;
}
</style>
<?php
}
add_action( 'wp_head', 'my_styles_method' );
I'm creating a simple "Read More/Read Less" button for a WordPress site that when pressed reveals hidden content using slideToggle. It's in the form of a WordPress plugin. The buttons fadeIn and fadeOut. And I'm using php/html to display the page.
Everything is working great except one little hiccup. For some reason, when the Read More button is clicked and the animation starts, the content div (or p tag - I can't tell for sure) starts a few pixels down and then shifts up after it finishes the animation. And vice versa, when the Read Less button is clicked, the animation does the same thing.
I've looked through the php and css and I can't find anything. I've even inspected the elements and removed all the css that way but it's not helping.
I've included all the code and a short video to show you what I mean.
Here is the link to the video: https://youtu.be/3LnmaPglyPI
Javascript
jQuery('.wpsm-content').addClass('wpsm-content-hide');
jQuery('.wpsm-show, .wpsm-hide').removeClass('wpsm-content-hide');
jQuery('.wpsm-show').on('click', function (e) {
"use strict";
var currentContent = jQuery(this);
function complete() {
jQuery(currentContent).next('.wpsm-content').slideToggle(800);
}
jQuery(this).fadeOut(200, complete);
e.preventDefault();
});
jQuery('.wpsm-hide').on('click', function (e) {
"use strict";
var wpsm = jQuery(this).parent('.wpsm-content');
function complete() {
wpsm.prev('.wpsm-show').fadeIn(200); // Read More
}
wpsm.slideToggle(1250, complete);
e.preventDefault();
});
CSS
.wpsm-show a, .wpsm-show:active, .wpsm-show:visited {
cursor: pointer;
text-decoration: none;
}
.wpsm-show:hover {
cursor: pointer;
text-decoration: underline;
}
.wpsm-hide a, .wpsm-hide:active, .wpsm-hide:visited {
cursor: pointer;
text-decoration: none;
}
.wpsm-hide:hover {
cursor: pointer;
text-decoration: underline;
}
.wpsm-content-hide {
display: none;
}
PHP/HTML
add_shortcode( 'show_more', 'wpsm');
function wpsm( $attr, $smcontent ) {
if (!isset($attr['color'])) $attr['color'] = '#cc0000';
if (!isset($attr['list'])) $attr['list'] = '';
if (!isset($attr['more'])) $attr['more'] = 'show more';
if (!isset($attr['less'])) $attr['less'] = 'show less';
$wpsm_string = '<div class="show_more">';
$wpsm_string .= '<p class="wpsm-show" style="color: ' . $attr['color'] . ' ">';
$wpsm_string .= $attr['list']. ' ' . $attr['more'];
$wpsm_string .= '</p><div class="wpsm-content">';
$wpsm_string .= $smcontent;
$wpsm_string .= ' <p class="wpsm-hide" style="color: ' . $attr['color'] . ' ">';
$wpsm_string .= $attr['list']. ' ' . $attr['less'];
$wpsm_string .= '</p>';
$wpsm_string .= '</div></div>';
return $wpsm_string;
}
add_action( 'wp_enqueue_scripts', 'sm_scripts');
function sm_scripts (){
$plugin_url = plugins_url( '/', __FILE__ );
wp_enqueue_style (
'sm-style',
$plugin_url . 'wpsm-style.css'
);
wp_enqueue_script (
'sm-script',
$plugin_url . 'wpsm-script-mine.js',
array( 'jquery' ),
'1.0.1',
true
);
}
add_action('wp_footer', 'sm_scripts');
?>
How do i share my website content to wordpress blog and google's blogger like facebook share, twitter share, without any third party tool.
Thanks
Step 1:
Go to your theme’s function.php file and paste below code. This will add sharing button at the bottom of the post
function crunchify_social_sharing_buttons($content) {
if(is_singular() || is_home()){
// Get current page URL
$crunchifyURL = get_permalink();
// Get current page title
$crunchifyTitle = str_replace( ' ', '%20', get_the_title());
// Get Post Thumbnail for pinterest
$crunchifyThumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
// Construct sharing URL without using any script
$twitterURL = 'https://twitter.com/intent/tweet?text='.$crunchifyTitle.'&url='.$crunchifyURL.'&via=Crunchify';
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$crunchifyURL;
$googleURL = 'https://plus.google.com/share?url='.$crunchifyURL;
$bufferURL = 'https://bufferapp.com/add?url='.$crunchifyURL.'&text='.$crunchifyTitle;
// Based on popular demand added Pinterest too
$pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$crunchifyURL.'&media='.$crunchifyThumbnail[0].'&description='.$crunchifyTitle;
// Add sharing button at the end of page/page content
$content .= '<div class="crunchify-social">';
$content .= '<h5>SHARE ON</h5> <a class="crunchify-link crunchify-twitter" href="'. $twitterURL .'" target="_blank">Twitter</a>';
$content .= '<a class="crunchify-link crunchify-facebook" href="'.$facebookURL.'" target="_blank">Facebook</a>';
$content .= '<a class="crunchify-link crunchify-googleplus" href="'.$googleURL.'" target="_blank">Google+</a>';
$content .= '<a class="crunchify-link crunchify-buffer" href="'.$bufferURL.'" target="_blank">Buffer</a>';
$content .= '<a class="crunchify-link crunchify-pinterest" href="'.$pinterestURL.'" target="_blank">Pin It</a>';
$content .= '</div>';
return $content;
}else{
// if not a post/page then don't include sharing button
return $content;
}
};
add_filter( 'the_content', 'crunchify_social_sharing_buttons');
Step 2:
Open style.css file of your WordPress theme and put below code for better styling.
.crunchify-link {
padding: 4px 8px 6px 8px;
color: white;
font-size: 12px;
border-radius: 2px;
margin-right: 2px;
cursor: pointer;
-moz-background-clip: padding;
-webkit-background-clip: padding-box;
box-shadow: inset 0 -3px 0 rgba(0,0,0,.2);
-moz-box-shadow: inset 0 -3px 0 rgba(0,0,0,.2);
-webkit-box-shadow: inset 0 -3px 0 rgba(0,0,0,.2);
}
.crunchify-link:hover,.crunchify-link:active {
color: white;
}
.crunchify-twitter {
background: #00aced;
}
.crunchify-twitter:hover,.crunchify-twitter:active {
background: #0084b4;
}
.crunchify-facebook {
background: #3B5997;
}
.crunchify-facebook:hover,.crunchify-facebook:active {
background: #2d4372;
}
.crunchify-googleplus {
background: #D64937;
}
.crunchify-googleplus:hover,.crunchify-googleplus:active {
background: #b53525;
}
.crunchify-buffer {
background: #444;
}
.crunchify-buffer:hover,.crunchify-buffer:active {
background: #222;
}
.crunchify-pinterest {
background: #bd081c;
}
.crunchify-pinterest:hover,.crunchify-pinterest:active {
background: #bd081c;
}
.crunchify-social {
margin: 20px 0px 25px 0px;
-webkit-font-smoothing: antialiased;
font-size: 12px;
}
If you want to show Sharing button at the top of the post then use this code:
function crunchify_social_sharing_buttons($content) {
if(is_singular() || is_home()){
// Get current page URL
$crunchifyURL = get_permalink();
// Get current page title
$crunchifyTitle = str_replace( ' ', '%20', get_the_title());
// Get Post Thumbnail for pinterest
$crunchifyThumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
// Construct sharing URL without using any script
$twitterURL = 'https://twitter.com/intent/tweet?text='.$crunchifyTitle.'&url='.$crunchifyURL.'&via=Crunchify';
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$crunchifyURL;
$googleURL = 'https://plus.google.com/share?url='.$crunchifyURL;
$bufferURL = 'https://bufferapp.com/add?url='.$crunchifyURL.'&text='.$crunchifyTitle;
// Based on popular demand added Pinterest too
$pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$crunchifyURL.'&media='.$crunchifyThumbnail[0].'&description='.$crunchifyTitle;
// Add sharing button at the end of page/page content
$variable .= '<div class="crunchify-social">';
$variable .= '<a class="crunchify-link crunchify-twitter" href="'. $twitterURL .'" target="_blank">Twitter</a>';
$variable .= '<a class="crunchify-link crunchify-facebook" href="'.$facebookURL.'" target="_blank">Facebook</a>';
$variable .= '<a class="crunchify-link crunchify-googleplus" href="'.$googleURL.'" target="_blank">Google+</a>';
$variable .= '<a class="crunchify-link crunchify-buffer" href="'.$bufferURL.'" target="_blank">Buffer</a>';
$variable .= '<a class="crunchify-link crunchify-pinterest" href="'.$pinterestURL.'" target="_blank">Pin It</a>';
$variable .= '</div>';
return $variable.$content;
}else{
// if not a post/page then don't include sharing button
return $variable.$content;
}
};
add_filter( 'the_content', 'crunchify_social_sharing_buttons');
Take a look here
I have problem displaying my wp_list_categories with Style. I am already using args, etc but that does not seem to help with the problem.
I want to display same sub-categories for single article.
Here my code :
<?php
if (is_home()) {
wp_list_categories('orderby=id&title_li=none&depth=1');
} else {
$category = get_the_category();
$cat_term_id = $category[0]->term_id;
$cat_category_parent = $category[0]->category_parent;
$listcat = wp_list_categories('echo=0&child_of='.$cat_category_parent.'&title_li=');
$listcat = str_replace("cat-item-".$cat_term_id, "cat-item-".$cat_term_id." current-cat", $listcat);
if ( in_category( $cat_term_id ) || post_is_in_descendant_category( $cat_term_id )) {
echo $listcat;
}
}
?>
</ul>
and here is the result :
http://i.stack.imgur.com/buYyl.jpg
I want the result will be like this :
http://i.stack.imgur.com/U3Pc6.jpg
I think this might work for you, but I'm not exactly sure which theme file you're referencing above.
<?php $parent_cat_id = 1; // Change this ID to match the ID value of the "Sepeda" category ?>
<?php $categories = get_categories( "child_of=$parent_cat_id" ); ?>
<?php if ($categories) : ?>
<ul id="category-list">
<?php // Print the link for 'Sepeda' ?>
<?php echo "<li class='category-name'><a href='" . get_category_link($parent_cat_id) . "'>" . get_cat_name($parent_cat_id) . "</a></li>"; ?>
<?php // Loop through the sub-categories of 'Sepeda' and print the names and links ?>
<?php foreach ($categories as $cat) {
echo "<li class='category-name'><a href='" . get_category_link( $cat->term_id ) . "'>" . $cat->name . "</a></li>";
} ?>
<?php wp_reset_query(); // Restore global post data ?>
</ul>
<?php endif; ?>
Then you could use this CSS to style the category list appropriately:
#category-list {
width: 250px;
padding: 5px;
background: white;
list-style: none;
}
.category-name {
background-color: #694489;
color: white;
min-height: 40px;
text-align: center;
line-height: normal;
padding-top: 10px;
}
.category-name + .category-name {
margin-top: 10px;
}
I'm very new to the process of CSS & PHP but with Wordpress & the widgets I'm trying to get better with my plugins.
I am trying to get my little twitter bird to appear next to my twitter content message, but it continues to be at the top of the messages.
An example of what I'm trying to achieve can be located here. http://globe-trekking.com/twitter_ideal.jpg (can't add image because this is my first post)
How can I over come this.
My relevant PHP code is:
$widgetContent .= "<span class='entry-content'><img class='twitter_bird' src='http://globe-trekking.com/running/wp-content/themes/newscast/images/bird_blue_16.png'>{$entryContent}</span>";
the full PHP code is:
$widgetContent .= '<ul>';
if ( ! is_array( $tweets ) || count( $tweets ) == 0 ) {
$widgetContent .= '<li class="wpTwitterWidgetEmpty">' . __( 'No Tweets Available', $this->_slug ) . '</li>';
} else {
$count = 0;
foreach ( $tweets as $tweet ) {
// Set our "ago" string which converts the date to "# ___(s) ago"
$tweet->ago = $this->_timeSince( strtotime( $tweet->created_at ), $args['showts'], $args['dateFormat'] );
//$entryContent .= '<li>';
$entryContent = apply_filters( 'widget_twitter_content', $tweet->text, $tweet );
$widgetContent .= "<span class='entry-content'><img class='twitter_bird' src='http://globe-trekking.com/running/wp-content/themes/newscast/images/bird_blue_16.png'>{$entryContent}</span>";
$widgetContent .= " <span class='entry-meta'>";
$widgetContent .= "<span class='time-meta'>";
$linkAttrs = array(
'href' => "http://twitter.com/{$tweet->user->screen_name}/statuses/{$tweet->id_str}"
);
$widgetContent .= $this->_buildLink( $tweet->ago, $linkAttrs );
$widgetContent .= '</span>';
if ( 'true' != $args['hidefrom'] ) {
$from = sprintf( __( 'from %s', $this->_slug ), str_replace( '&', '&', $tweet->source ) );
$widgetContent .= " <span class='from-meta'>{$from}</span>";
}
if ( !empty( $tweet->in_reply_to_screen_name ) ) {
$rtLinkText = sprintf( __( 'in reply to %s', $this->_slug ), $tweet->in_reply_to_screen_name );
$widgetContent .= ' <span class="in-reply-to-meta">';
$linkAttrs = array(
'href' => "http://twitter.com/{$tweet->in_reply_to_screen_name}/statuses/{$tweet->in_reply_to_status_id_str}",
'class' => 'reply-to'
);
$widgetContent .= $this->_buildLink( $rtLinkText, $linkAttrs );
$widgetContent .= '</span>';
}
$widgetContent .= '</span>';
if ( 'true' == $args['showintents'] ) {
$widgetContent .= ' <span class="intent-meta">';
$lang = $this->_getTwitterLang();
if ( !empty( $lang ) )
$linkAttrs['data-lang'] = $lang;
$linkText = __( 'Reply', $this->_slug );
$linkAttrs['href'] = "http://twitter.com/intent/tweet?in_reply_to={$tweet->id_str}";
$linkAttrs['class'] = 'in-reply-to';
$linkAttrs['title'] = $linkText;
$widgetContent .= $this->_buildLink( $linkText, $linkAttrs );
$linkText = __( 'Retweet', $this->_slug );
$linkAttrs['href'] = "http://twitter.com/intent/retweet?tweet_id={$tweet->id_str}";
$linkAttrs['class'] = 'retweet';
$linkAttrs['title'] = $linkText;
$widgetContent .= $this->_buildLink( $linkText, $linkAttrs );
$linkText = __( 'Favorite', $this->_slug );
$linkAttrs['href'] = "http://twitter.com/intent/favorite?tweet_id={$tweet->id_str}";
$linkAttrs['class'] = 'favorite';
$linkAttrs['title'] = $linkText;
$widgetContent .= $this->_buildLink( $linkText, $linkAttrs );
$widgetContent .= '</span>';
}
//$widgetContent .= '</li>';
if ( ++$count >= $args['items'] )
break;
}
}
$widgetContent .= '</ul>';
My CSS code is:
.widget_twitter div {
padding:0;
width:280px;
}
.widget_twitter ul li {
margin-bottom:5px;
margin-left:0px;
clear:both;
}
.widget_twitter a {
text-decoration:none;
color:#333333;
margin: 0 10px 10px 0;
}
.widget_twitter a:visited {
text-decoration:underline;
color:#FF00FF;
}
.widget_twitter a:hover {
text-decoration:underline;
color:#0000CC;
}
.widget_twitter .follow-button,
.widget_twitter .xavisys-link {
margin:0 10px 10px 25px;
}
.widget_twitter .entry-content {
width:260px;
display: inline-block;
line-height:22px;
margin-top:10px;
margin-left: 13px;
}
.widget_twitter .entry-content twitter_bird {
vertical-align:middle;
}
.widget_twitter .entry-meta {
display:block;
font-size:80%;
margin-bottom: 10px;
margin-left: 13px;
}
.widget_twitter .intent-meta a {
background-image: url('images/everything-spritev2.png'); /** from Twitter resources */
display: inline-block;
text-indent: -9999px;
margin: 0 10px 10px 0;
height: 16px;
width: 16px;
}
.widget_twitter .in-reply-to-meta {
margin: 0 10px 10px 0;
}
.widget_twitter .intent-meta a.in-reply-to {
background-position: 0 center;
}
.widget_twitter .intent-meta a:hover.in-reply-to {
background-position: -16px center;
}
.widget_twitter .intent-meta a.favorite {
background-position: -32px center;
}
.widget_twitter .intent-meta a:hover.favorite {
background-position: -48px center;
}
.widget_twitter .intent-meta a.retweet {
background-position: -80px center;
}
.widget_twitter .intent-meta a:hover.retweet {
background-position: -96px center;
}
Any assistance would be greatly appreciated. I've managed to get it to a "decent" appearance, but otherwise, this is the last step that I've tried a number of things on.
Regards,
Daniël
Sorry for fast answer, may be me wrong, but try to use float:left for bird image.