lightbox effect on wordpress post attached images - function

I have this code to display the attached images on a post:
<?php
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID,
'exclude' => get_post_thumbnail_id()
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo '<a href="';
echo wp_get_attachment_url( $attachment->ID );
echo '" rel="lightbox">';
echo wp_get_attachment_image( $attachment->ID, 'large' );
echo '</a>';
}
}
?>
But i cannot work out why the Lightbox is not working! I have tried colorbox, shadowbox, ligthbox plugins etc... it just does not load. When you click on the image, it just opens in page.
What am i doing wrong?

See if your theme call
wp_head();
in your header file and
wp_footer();
in your footer file the plugins don't work if youar missing this.

Related

Create a div each month in wordpress loop

I'm trying to create a list of posts that has a seperator displaying each month.
It's supposed to look something like this:
January 2018
- blog post
- blog post
Febuary 2018
- blog post
etc....
The code i'm using is a simple loop. I've tried to get the seperator working using the the_date() function and change its date format. But it still triggers for each day.
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => -1
);
$the_query = new WP_Query($args); if($the_query->have_posts()): while($the_query->have_posts()): $the_query->the_post();
?>
<?php if(!the_date('F Y','','',false) == ''){ ?>
<div class="seperator">
<?php the_time('F Y'); ?> //echo month and year
</div>
<?php } ?>
<div class="post"> //the post content </div>
<?php endwhile; endif; wp_reset_query(); ?>
I don't really know what code to use to make it only trigger each month.
You should try something like this:
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'DESC'
);
$the_query = new WP_Query($args); if($the_query->have_posts()): while($the_query->have_posts()): $the_query->the_post();
if ($lastMonth && the_date('mm') !== $lastMonth) {
// new month
}
$lastMonth = the_date('mm');
?>
This way, in each iteration you're setting the month of publication in the lastMonth variable. The next iteration, you're checking if the month of publication is equal to the previous one. If not, you're in a new loop and you can insert your seperator.

How to create permalink URL for API in WordPress?

I use WordPress and list data from my API:
$url = "http://example.com/all-list";
$response = wp_remote_get( $url );
$data_body = json_decode( wp_remote_retrieve_body( $response ), true );
<?php foreach ( $data_body as $real_data ): ?>
<h1><?php echo $real_data["title"]; ?></h1>
<?php end foreach; ?>
But in I don't know how to give url.
Example: I'd like to give <a href="/real-data?id=<?php $real_data['id'] ?>"> then return new view template. It like get_permalink(); to view single page post.
How could I do this in WordPress?
Check this examples below.
// This would output '/client/?s=word&foo=bar'
echo esc_url( add_query_arg( 'foo', 'bar' ) );
// This would output '/client/?s=word&foo=bar&baz=tiny'
$arr_params = array( 'foo' => 'bar', 'baz' => 'tiny' );
echo esc_url( add_query_arg( $arr_params ) );
https://developer.wordpress.org/reference/functions/add_query_arg/

ad thumbnail to aw blog posts in magento

in magento 1.8.1 i have added a thumbnail image to aw blog posts header and into the aw blog sidebar widget next to the each headline
i did these:
In app/code/community/AW/Blog/Block/Manage/Blog/Edit/Form.php
change:
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
'method' => 'post',
));
to
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
'method' => 'post',
'enctype' => 'multipart/form-data'
));
In app/code/community/AW/Blog/Block/Manage/Blog/Edit/Tab/Form.php
add
$fieldset->addField('featured_image', 'image', array(
'name' => 'featured_image',
'label' => 'Featured Image'
));
below the line
$fieldset = $form->addFieldset('blog_form', array('legend' => Mage::helper('blog')->__('Post information')));
In app/code/community/AW/Blog/controllers/Manage/BlogController.php
add
if(isset($_FILES['featured_image']['name']) and (file_exists($_FILES['featured_image']['tmp_name']))) {
try {
$uploader = new Varien_File_Uploader('featured_image');
$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
$uploader->setAllowRenameFiles(false);
// setAllowRenameFiles(true) -> move your file in a folder the magento way
// setAllowRenameFiles(true) -> move your file directly in the $path folder
$uploader->setFilesDispersion(false);
$path = Mage::getBaseDir('media') . DS .'blogpic'.DS;
$uploader->save($path, $_FILES['featured_image']['name']);
$data['featured_image'] = $_FILES['featured_image']['name'];
}catch(Exception $e) {
}
}
// handle delete image
else {
if(isset($data['featured_image']['delete']) && $data['featured_image']['delete'] == 1)
$data['image_main'] = '';
else
unset($data['featured_image']);
}
below the line
$model = Mage::getModel('blog/post');
And added a "featured_image" column to the aw_blog table in database. Use the type VARCHAR(255) default null and null enable .
and add
<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$post->getFeaturedImage() ?>" alt="featuredImage" />
to
/app/design/frontend/base/default/template/aw_blog/blog.phtml
below line
<?php foreach ($posts as $post): ?>
<div class="postWrapper">
<div class="postTitle">
<h2><a href="<?php echo $post->getAddress(); ?>" ><?php echo $post->getTitle(); ?></a></h2>
the problem is: the images are saving in right place in media/blogpic but they are not shown in frontend
In your blog.phtml subst
<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$post->getFeaturedImage() ?>" alt="featuredImage" />
with
<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).DS.'blogpic'.DS.$post->getFeaturedImage() ?>" alt="featuredImage" />
Hope it helps.
The easiest way to add a featured image or thumbnail image to the Magento version of AWBlog without coding is as follows:
-In the blog post go to the SHORT CONTENT text field
-In that field enter your image url
<img src="{{media url="wysiwyg/blogimages/myimages/your.jpg"}}" alt="folding chairs" />
-Underneath that enter your blurb that shows
When you save and open the blog post in the blog overview you will see you featured image shows with the content blurb just below it.

WordPress: Displaying whole template, not just the_content

I've got a single page website with a front-page.php that shall include all my custom templates (each one is a static page).
<?php get_header();
$args = array(
'sort_order' => 'ASC',
'sort_column' => 'menu_order',
'post_type' => 'page',
'post_status' => 'publish'
);
$pages = get_pages($args);
foreach ($pages as $page_data) {
$content = apply_filters('the_content', $page_data->post_content);
?>
<?php echo "$content" ?>
<?php
}
get_footer();
?>
With "the_content" it references only the content of my text in the backend, but not all my tags surrounding my the_content tag in the template itself, for example:
<?
/*
Template Name: Features
*/
the_post()
?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<section>
<? the_content() ?>
</section>
<?php endif; ?>
In this case, the surrounding tags section aren't selected and don't appear in the markup.
What do I have to change in my front-page.php to select the whole template, not only its template?
Thanks so much in advance!
You could put the loop part of each page template in a separate template part and call the parts dynamically on your front page with get_template_part:
foreach ( $pages as $page_data ) {
$template = get_post_meta( $page_data->ID, '_wp_page_template', true ); // get page template path
$template = substr( $template, 0, -4 ); // chop off .php from the string
get_template_part( 'loop', $template );
}
For a template 'Features' (filename features.php) it would look for loop-features.php, etc. Fallback will be loop.php.

Different sidebars for different pages on Wordpress

I'm trying to design a theme on WordPress (version 3.3.2) but I am having a few problems in having the sidebar display a different set of widgets on certain pages.
I have tried several online tutorials and this one in particular http://www.rvoodoo.com/projects/wordpress/wordpress-tip-different-sidebars-on-different-pages/ but unfortunately there is no change in the sidebar when I move to a different page
I registered two sidebars on my functions.php as shown below, one which I would consider as main, and the other as a custom sidebar, and I also added different widgets to these sidebars.
<?php register_sidebar( //register sidebar
array(
'name' => 'Right-side',
'before_widget' => '<div class="rightwidget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
));
register_sidebar( //register second sidebar
array(
'name' => 'Second-right',
'before_widget' => '<div class="rightwidget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
));
?>
Following that, I created the files sidebar.php and sidebar-second.php to be able to call them.
sidebar.php
<div id="sidebar">
<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Right-side')) : ?>
<h3 class="widget-title">No widget added</h3>
<p> Please add some widgets</p>
<?php endif; ?>
</div><!--ends sidebar-->
sidebar-second.php
<div id="sidebar">
<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Second-right')) : ?>
<h3 class="widget-title">No widget added</h3>
<p> Please add some widgets</p>
<?php endif; ?>
</div><!--ends sidebar-->
And then I added replace my <?php get_sidebar() ; ?> statement with following conditional
<?php if( is_page('225') ) : ?>
<?php dynamic_sidebar('second'); ?>
<?php else : ?>
<?php get_sidebar() ; ?>
<?php endif ; ?>
However only the widgets added to the sidebar.php are displayed on every page. Any help on how I could change this, or pointers on what I could be doing wrong. Thanks.
I looks like you are using <?php dynamic_sidebar('second'); ?> where you should be using <?php get-sidebar('second'); ?>
What get_sidebar('foo') does is look for a file named 'sidebar-foo.php' in the root directory of your theme and includes it. dynamic_sidebar('bar'), on the other hand, looks for a sidebar registered with:
<?php register_sidebar( array( 'name' => 'bar' ... ) ) ?>
Hope this helps!
Why don't you use the Custom Sidebar Plugin?
It's really easy to use and does not need any coding
You have two sidebars. when you want to use the sidebar-second file on a particular page, instead of calling
<?php get_sidebar('second') ; ?>
TRY
<?php get_sidebar('sidebar-second.php') ; ?>
this should do the trick