I added this PHP function to display the excerpt of my products on the archive pages, however it affects the rest of my styling.
I'm trying to stop the CSS from my excerpts to affect the rest of the page. Basically I would like only the text without its own styling or bullets, or images, etc.
This is the code added :
<?php echo apply_filters( 'woocommerce_short_description', $post->post_excerpt ); ?>
add some html to your excerpt.. to target only that certain html...
example, adding a div with a class my-excerpt:
<div class="my-excerpt">
<?php echo apply_filters( 'woocommerce_short_description', $post->post_excerpt ); ?>
</div>
your css would then be:
.my-excerpt img {
border: 0;
}
Related
Is it possible to use the_content() excluding the galleries? I want to make this because I need the gallery displayed with flexslider. I already integrate flexslider. If I want to show the content of the post, for example: some text, separated images and of course a gallery. It will display the gallery with flexslider and then the content with the text, images and the gallery again. I don't want the gallery duplicated.
<div class="entry-content">
<?php $gallery = get_post_gallery( get_the_ID(), false );?>
<div class="flexslider flexslider-gallery">
<ul class="slides slides-gallery">
<?php foreach( $gallery['src'] AS $src ){ ?>
<li>
<img alt="Gallery image" src="<?php echo $src; ?>" />
</li>
<?php } ?>
</ul> <!-- end .slides -->
</div> <!-- end .flexslider -->
<?php the_content(); ?>
</div><!-- .entry-content -->
Ok here is the solution:
Add to functions.php
function remove_shortcode_from($content) {
$content = strip_shortcodes( $content );
return $content;
}
and then call it when you need, in my case in content-gallery.php:
add_filter('the_content', 'remove_shortcode_from');
the_content();
remove_filter('the_content', 'remove_shortcode_from')
Two ways:
1) The WordPress Gallery is contained in a div with class .gallery. If flexsider does not also use that class, you could simply set your CSS to:
.gallery { display: none; }
2) You could get the content with get_the_content, parse it using a DOM parser and delete the Gallery.
Option #1 is less efficient, but avoids the complexity of parsing the DOM.
Neither method is guaranteed to work if the site is use a non-standard gallery plugin that is creating non-WP HTML.
I want to show limit latest post of WordPress in main page. I'm using WordPress APIs and functions to show that, but after that get_the_content() remove and escape all of seved tags and my posts don't show correctly such as editor tags.
This function escape HTML tags:
<ul style="list-style: none;margin:5px" class="latest-posts">
<!-- LOOP START -->
<?php $the_query = new WP_Query( 'showposts=3' ); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<!-- THIS DISPLAYS THE POST THUMBNAIL, The array allows the image to has a custom size but is always kept proportional -->
<li> <?php the_post_thumbnail( array(100,100) );?></li>
<!-- THIS DISPLAYS THE POST TITLE AS A LINK TO THE MAIN POST -->
<li>
<a href="<?php the_permalink() ?>">
<?php the_title(); ?>
</a>
</li>
<!-- THIS DISPLAYS THE EXCERPT OF THE POST -->
<li>
<?php echo mb_substr(get_the_content(), 0, 1200).' ...'; ?>
</li>
<!-- READ MORE LINK -->
<li>more ...</li>
<?php endwhile;?>
<!-- LOOP FINNISH -->
</ul>
There are basically three possibilities how to output the excerpt of the post content.
with the excerpt() function, to output the content of the excerpt field in post editor, if it's not filled it will display the first 55 words of the post content ( use excerpt_length filter to control the length of the excerpt ).
to use the <!--more--> quicktag, the_content() tag will only show the excerpt up to the <!--more--> quicktag. That quicktag will not work in single pages templates.
to manually strip HTML from post content and to show custom excerpt. One way to do that is to use wp_filter_nohtml_kses() function:
echo mb_substr( wp_filter_nohtml_kses( get_the_content() ), 0, 1200 );
All methods above will strip the HTML from post content. To include HTML in excerpts use excerpt field in post editor, WordPress will preserve HTML you included in post editor. There are also some plugins like Advanced Excerpt that will create excerpt from content and preserve html, but I don't believe that there is a bullet proof way of doing that.
I have added four text widgets in one sidebar,
these sidebars are generated in four rows, one below the other.
What I want is to show them in one single row side-by-side.
I found class WP_Widget_Text in default-widgets.php, but I don't know how to do that.
One way is add the following code in style.css
<style type='text/css'>
.textwidget {
display:inline;
margin-left: 10px;
float:left;
}
</style>
you can also remove div tag from line 403
echo $before_widget;
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text;
echo $after_widget;
but this can't be a guaranteed solution, because $before_widget, $after_widget can output some code that can create div / add line breaks.
both these solutions are not update friendly. i.e. if you update WordPress or change your theme, you will see it won't work.
The best solution I feel is use one text widget, with some CSS as below.
<div style='float:left;display:block inline;margin-right:10px'>Widget text 1</div>
<div style='float:left;margin-right:10px'>Widget text 2</div>
<div style='float:left;margin-right:10px'>Widget text 3</div>
<div style='float:left'>Widget text 4</div>
you will have to use inline css. you can also add border and other styling to seprate the div's currently i have just added right margin
I'm quite new to wordpress, so bear with me. I have a site up and running allowing me to add content dynamically, the only problem is styling each post. I'm looking to wrap posts in a div, so images would be wrapped in one div and text posts would be wrapped in another, if that makes sense?Here's some code I've been using:
<?php if ( in_category('photos') ) { ?>
<div id="testing">
<?php } else { ?>
<div id="test-2">
<?php } ?>
The only problem with this is that it wraps all posts in a given category and doesn't put a closing '< / div >' after the content, if that makes sense?
Well, the only reason you're not getting any closing </div>s is because you're not putting it anywhere in your php.
This should work:
<?php while( have_posts() ) : the_post()
if( in_category( 'photos' ) { ?>
<div id="testing">
// All your post content and whatnot
<?php the_content(); ?>
</div>
<?php } else { ?>
<div id="test-2">
// All your post content
<?php the_content(); ?>
</div>
<?php }
endwhile; ?>
If you don't write complete markup in your theme files, you can't possibly expect Wordpress, or PHP, to automatically close your HTML tags.
"if that makes sense" No it doesn't really make sense as Wordpress by default adds a CSS-class for every category and tag to the surrounding div. If that is not the case in your theme, use the function post_class() to add the CSS-classes to your div.
See the post_class()-documentation for usage examples.
i am using wordpress and have come at a point that i have to hide the div if there is no widget displayed in it.
can some one tell me the code for detection of number of widgets displayed in a specific area.
try this
<?php if ( is_active_sidebar( 'your-widget-area' ) ) : ?>
<!--This div will not display if there is no active widgets
so place your div inside if condition-->
<div>
<?php dynamic_sidebar( 'your-widget-area' ); ?>
</div>
<?php endif; ?>