• Resolved Cars10

    (@shonu)


    Having templates for the posts is awesome, but I just realised a limitation
    1. Create multiple instances of the widget by using any builder framework.
    2. Selecting for the homepage layout a template called Newsflash
    3. Want to give the whole container red color
    –>The color cann only be applied to list through template, not the whole container.

    Workaround:
    Clear label, place the Header inside the template and additionally wrap a div around all (inside IF statement) so that I can apply a class to reach by CSS.

    Could you offer FULL template switch, so I can get the label from the template and render it ?

    if ( $flexible_posts->have_posts() ):
    ?>
    	<div class="newsflash"  style="background-color: #FF8040">
    	<h4>Newsflash</h4>
    	<ul class="dpe-flexible-posts">
    	<?php while ( $flexible_posts->have_posts() ) : $flexible_posts->the_post(); global $post; ?>
    		<li id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    			<a href="<?php echo the_permalink(); ?>">
    				<?php
    					if ( $thumbnail == true ) {
    						// If the post has a feature image, show it
    						if ( has_post_thumbnail() ) {
    							the_post_thumbnail( $thumbsize );
    						// Else if the post has a mime type that starts with "image/" then show the image directly.
    						} elseif ( 'image/' == substr( $post->post_mime_type, 0, 6 ) ) {
    							echo wp_get_attachment_image( $post->ID, $thumbsize );
    						}
    					}
    				?>
    				<div class="title"><?php the_title(); ?></div>
    			</a>
    		</li>
    	<?php endwhile; ?>
    	</ul>
    	</div>

    thanks

    https://www.ads-software.com/plugins/flexible-posts-widget/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author DaveE

    (@dpe415)

    Hi Shonu,

    This is how WordPress widgets work in general. In other words, there is no “template” portion to the widget container markup. That’s all driven by WordPress core functionality. To work around that, you’d need to look into adding custom CSS classes to your widget containers. There are plugins and articles that will allow you to accomplish this.

    Cheers!

    Thread Starter Cars10

    (@shonu)

    Hey Dave, thanks for the feedback, but what I meant is:
    The template is a list
    The list needs a [dynamic] label that does not show when the list is empty.
    I can keep the label part empty and render the list that remains unrendered, if I take care of it in the template.
    Where is the label, when it IS rendered? Hardcoded in the template and I cannot reuse it [easily].
    Ugly workarounds I want to prevent.

    My idea:
    The widget instance defines a label.
    Let the template render the label.
    Essential question: How to access the label defined in the [reused] widget from inside the widget template?
    A) I can then obtain the value from widget
    B) The widget label from you remains visible (double display), until I remove it by CSS or jQuery (ugly way)
    C) Solution, provide a checkbox: [X] “template renders whole output”. If the template was 0 bytes or my code says not to render anything (empty list), nothing would be rendered as desired.

    is it clearer now? There are several solution steps and while I can workaround, I am just asking if we could make it max. usable in a dynamic way without user needing to workaround with css or jQuery to remove widget html when list is empty.

    thanks

    Plugin Author DaveE

    (@dpe415)

    Hi Shonu,

    I don’t completely understand your question or issue. If you examine any template provided with FPW, you can see where the widget output begins: echo $before_widget and where the widget title is outputted:

    if ( ! empty( $title ) )
    	echo $before_title . $title . $after_title;

    You are welcome to move that (and the $after_widget output) within the $flexible_posts->have_posts() check if it suits your needs. In fact, you are welcome to customize the output of the widget any way you’d like. If you create a new template file, and make it empty, the widget will display nothing: no wrapper, no title, no output. There is nothing preventing you from being able to hide the widget output when your settings result in no posts. I don’t understand what you’re unable to accomplish with your own template.

    Sorry for the confusion.

    Thread Starter Cars10

    (@shonu)

    Hmm, yes, sometimes I feel stupid or just need vacation.

    Thanks and myself sorry for my stupidity ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Breaking out of Template’ is closed to new replies.