Wordpress: get content of a text widget - wordpress

I have a text widget in the left sidebar and I want it to be displayed somewhere else on the page and not in a sidebar. The widget's text is some HTML:
<a href...><img ...></a>
I can't figure out the code how to get the widget's content - the HTML. I found out, that the name of the widget seems to be "text-5" using this code:
print(wp_get_sidebars_widgets()['travelify_left_sidebar'][0]);
Why I use a widget for this is because I want it to be easy to alter the HTML code for my client.
thx in advance,
Koem

This template tag displays an arbitrary widget outside of a sidebar. It can be used anywhere in
<?php the_widget( $widget, $instance, $args ); ?>
Text widget
<?php the_widget( 'WP_Widget_Text', $instance, $args ); ?>
widget's classname: widget_text
instance:
title
text
filter
Example
Default usage:
<?php the_widget( 'WP_Widget_Text' ); ?>
You can also find whole solution about wordpress codex site
http://codex.wordpress.org/Function_Reference/the_widget

Related

How to reuse the same widgets in different wordpress pages

I have to the following page which has a widget called press as you can see in the screenshot
I had created another page (manually and by cloning pulgin) and I can't reuse the same widget in the new page.
Any ideas how can I do that?
you can add sidebar in particular page template
Ex. sidebar slug name : "left-sidebar"
<?php if ( is_active_sidebar( 'left-sidebar' ) ) : ?>
<?php dynamic_sidebar( 'left-sidebar' ); ?>
<?php endif; ?>
Or
you can use below plugin
https://wordpress.org/plugins/display-widgets/
Page template section screenshot
For Ex. About Us Template

Small thumbnail image not appearing in wordpress meta-grid plugin

Thumbnail image is inside Media-Grid plugin -> Grid Builder -> select any grid from grid list ->small thumbnail image in front of 'select an item' drop down list
Thumbnail image not appear online but work fine locally.
Can you please tell me where to start ?
here is image
enter link description here
For cropping thumbnail image, you it would not a proper way to use plugins:
Try with this code, it will helps you for all the rest of thumbnails in your whole site...
Put this code in your function.php file
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'custom-post-thumb', 140, 140,true );
}
Now use this in your code:
<?php if ( has_post_thumbnail()) : ?>
<?php the_post_thumbnail('custom-post-thumb', array('class' => 'attachment')); // here array('class' => 'attachment') apply if you want to apply class to that anchor tag ?>
<?php endif; ?>
Thanks

Remove featured image in Post

I want to remove the featured image in post and page, but keep it as thumbnail so that the site look good! My site is a wordpress based site.
Here's an example post of the site: http://www.tradingspotsilver.com/build-mt4-custom-ea-indicator-forex-free/
You could see that the featured image is on top of the post and occupy a lot of space. I've tried to look at the theme source but no luck.
The link given in your question is a single post page, you look in to your theme's root folder and can find a file named single.php, in that file you may find something like this
// "custom_size" could be anything like "single_page_image"
if ( has_post_thumbnail() ) : the_post_thumbnail('custom_size');
This line of code is responsible for showing the big image. Just remove this line and your image will not show up. Also, you may check this answer for custom image sizing.
For page template, you may look for a file named page.php and look for the similar code.
you can use timthumb for resizing:
with the code here: { https://code.google.com/p/timthumb/source/browse/trunk/timthumb.php }
create a file named timthumb.php in your theme folder, and at the place of the featured image php script, type:
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
//the_post_thumbnail();
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
<div class="img-hold"> <img src="<?php bloginfo('template_directory') ?>/timthumb.php?src=<?php echo $url; ?>&w=219&h=125" width="219" height="125" /></div>
<p><? }
echo $content;
?></p>
change the value of height and width as per your wish at &w=, &h= and also width= , height=
hope this helps
just remove the the_post_thumbnail code in the single.php and page.php or content.php.
this function use in wordpress for show featured so just remove or comment it.
check your single.php and content.php page to solve this problem its right there
if you dont require that code comment it / or modify it as you want.
dont mess things go easy with it or otherwise you will end up getting error
I had the same issue and i could not find any solution in single.php
Its simple although:
just comment:
from content.php page
This is for the Dazzle Theme
I found mine in "content-single.php and removed :
<?php the_post_thumbnail( 'dazzling-featured', array( 'class' => 'thumbnail' )); ?>
Picture was gone from post.
It is obviously varies depending on theme.
For theme Freemium you need to remove the following lines in wp-content/themes/freemium/single.php:
<?php $freemium_feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); if($freemium_feat_image!="") { ?>
<img src="<?php echo $freemium_feat_image; ?>" alt="Banner" class="img-responsive img-responsive-freemium" />
<?php } ?>

WordPress page content in Modal Pop-Up

I am working on a WordPress gallery website which has only three pages: Home, Gallery, and Bio (http://adamgreener.com/).
When you click Bio, the Bio content pops up, powered by Easy Modal plugin (the content is manually typed in HTML in the plugin settings).
I also have the exact same HTML content in a WordPress page (which mobile viewers see, rather than a popup).
The page is very simple to edit, but the Modal content is not so friendly to the average user. I am seeking a way that I can allow the user to edit only the Bio page, and have that modal content update at the same time.
What would be the best route for such an action?
Thanks in advance!
You could use get_page to get the page content, and a shortcode to display it in the popup. In the functions.php file of your WordPress theme, e.g.:
add_action( 'init', 'greener_shortcode_init', 11 );
function greener_shortcode_init()
{
add_shortcode( 'greener_bio', 'greener_bio_shortcode' );
}
function greener_bio_shortcode( $atts )
{
$page_id = 123; // the ID of the Bio page
$page_data = get_page( $page_id );
$return = '';
$return .= '<h2>' . $page_data->post_title . '</h2>';
$return .= $page_data->post_content;
return $return;
}
Then, in your modal, use the shortcode:
[greener_bio]
There are two possible ways to accomplish what you're going for, both described in depth in my blog post: https://allurewebsolutions.com/open-wordpress-post-modal-without-plugin
You can also just use my plugin for this: https://wordpress.org/plugins/wp-post-modal/
First Method
The first method requires modifying the template that serves the content you want to appear in the modal. For example, you have a template called modal-content-template.php.
Inside that template we wrap the content we want loaded into the modal with:
<?php if (!$_GET) { ?>
// content that gets loaded on mobile
<?php } ?>
Full example of a template where we are excluding the WordPress header and footer:
<?php if (!$_GET) { get_header(); } ?>
<article>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1 class="page-title"></h1>
<section class="entry-content cf">
<?php the_content(); ?>
</section>
</article>
<?php if (!$_GET) { get_footer(); } ?>
CodePen example for the JS required to make this work
Second Method
The second method is a little more elegant. We use the modalContent.load(post_link + ' #modal-ready'); method to load the modal content.
The modal contact is wrapped in a wrapper container with ID #modal-ready. This can be done without even touching the page template using a function that hooks into the content.
add_action('the_content', 'wrap_content');
function wrap_content($content)
{
return '<div id="modal-ready">' . $content . '</div>';
}

Wordpress: how to get an image in more/excerpt?

I need to make a homepage of a wordpress blog show just 1 paragraf of text followed by more, and below a big nice image.
However, excerpt does not take images.
Also, if i put the more page divider, no image appears. and even if it does, the 'more' link should be after the text, not after the image.
How can i get this to work?
UPDATE:
I noticed that in the source code, there is a link to an image, but it is not the right link.
currently my blog is at www.domain.com/wordpress and will be moved to www.domain.com.
currently the image has the code:
<img width="800" height="990" alt="" src="../wp-content/uploads/2011/05/2010_06_01_archive.jpg" title="2010_06_01_archive">
Somehow the build-in linkage is broken
Use wordpress's in-built "featured image" (can be set on post's editing page in wordpress admin).
On the page displaying the excerpts:
<div id="excerpts">
<?php
$args = array( 'numberposts' => 3, 'category'=> '1,3,5' ); }
// set number of excepts to show
// and optionally restrict to certain categories
$posts = get_posts($args);
foreach($posts as $post) : setup_postdata($post);
?>
<div class="single-excerpt">
<h3><?php the_title(); ?></h3>
<?php if ( has_post_thumbnail()) the_post_thumbnail('excerpt-thumb'); ?>
<!-- displays thumbnail if it exists -->
<p><?php the_excerpt();?></p>
</div><!-- single-excerpt -->
<?php endforeach; ?>
</div><!-- excerpts -->
In your theme's functions.php:
if ( function_exists( 'add_image_size' ) ) add_theme_support( 'post-thumbnails' );
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'excerpt-thumb', 0, 100, false );
// define excerpt-thumb size here
// in the example: 100px wide, height adjusts automatically, no cropping
}
function new_excerpt_length($length) {
return 42;
// define length of excerpt in number of words
}
add_filter('excerpt_length', 'new_excerpt_length');
You could also use the Wordpress plugin Easy Custom Auto Excerpt which allows you to configure the excerpt to include shortcode, images, and all HTML.
Make sure the image is properly sized, and the physical size is minimized as much as possible. (Gif is usually the best format for this.)
http://codex.wordpress.org/Image_Size_and_Quality

Resources