No valid Headers on plugin in wordpress - wordpress

I have created a plugin, for some reason when I try to upload and activate it via a zip. I get the message 'no valid headers'. If I just drop the folder via ftp it seems ok. Any suggestions?
here is the plugin main files:
<?php
/*
* Plugin Name: Album Gallery
* Plugin URI: http://vinteractive.co.uk
* Description: An Album based Slider Gallery.
* Version: 1.0
* Author: Vincent Stephens
* Author URI: http://vinteractive.co.uk
* License: Do Not Redistribute
*/
define('ALBUM_GALLERY_URL', plugins_url() . '/album-gallery/');
define('ALBUM_GALLERY_ABSPATH', ABSPATH . 'wp-content/plugins/album-gallery/');
define( 'ACF_LITE' , true );
include(ALBUM_GALLERY_ABSPATH . 'custom-fields/acf.php');
include(ALBUM_GALLERY_ABSPATH . 'custom-fields/album-fields.php');
include(ALBUM_GALLERY_ABSPATH . 'custom-post-types/albums-gallery-post-type.php');
include(ALBUM_GALLERY_ABSPATH . 'shortcodes/shortcodes.php');
// Enque Scripts and styles
function album_gallery_scripts() {
wp_register_script('jquery-for-nivo', plugins_url('/js/jquery-1.9.0.min.js', __FILE__), array('jquery'),'1.1', true);
wp_enqueue_script('jquery-for-nivo');
wp_register_script('nivo-slider', plugins_url('/nivo/scripts/jquery.nivo.slider.js', __FILE__), array('jquery'),'1.1', true);
wp_enqueue_script('nivo-slider');
wp_register_script('album-gallery-script', plugins_url('/js/album-gallery.jquery.js', __FILE__), array('jquery'),'1.1', true);
wp_enqueue_script('album-gallery-script');
wp_register_style('album-gallery', plugins_url('/css/album-gallery.css', __FILE__));
wp_enqueue_style('album-gallery');
wp_register_style('nivo-slider', plugins_url('/nivo/nivo-slider.css', __FILE__));
wp_enqueue_style('nivo-slider');
wp_register_style('style', plugins_url('/nivo/style.css', __FILE__));
wp_enqueue_style('style');
// Nivo Theme
wp_register_style('theme-default', plugins_url('/nivo/themes/default/default.css', __FILE__));
wp_enqueue_style('theme-default');
}
add_action( 'wp_enqueue_scripts', 'album_gallery_scripts' );
?>
Short Codes file:
<?php
function album_gallery_shortcode() {
?>
<span class="info_btn"></span>
<?php
// Loop for Album Gallery Post Type
$args = array(
'post_type' => 'albums_gallery',
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$album_name = get_the_ID();
$album_description = get_field('album_description');
?>
<div class="album album_<?php echo $album_name ?>">
<?php for ($i = 0; $i <= 0; $i++) { ?>
<div class="description album_<?php echo $album_name ?>">
<?php echo $album_description; ?>
</div>
<?php } ?>
<div class="slider-wrapper theme-default">
<div class="slider" class="nivoSlider">
<?php
$images = Array();
for($i = 1; $i <= 6; $i++) {
$image = get_field("image_{$i}");
if(!$image || !$image['url']) {
break;
}
$caption = get_field("image_{$i}_caption");
?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" title="<?php echo $caption; ?>" />
<?php } ?>
</div>
</div>
</div>
<!-- End Album -->
<?php endwhile; wp_reset_query(); ?>
<!-- // Loop for Album Gallery Post Type -->
<div class="thumbnails">
<?php
$args = array(
'taxonomy_albums' => '',
'post_type' => 'albums_gallery',
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
// album name becomes post id
$album_name = get_the_id();
$album_thumb = get_field('thumbnail');
$album_caption = get_field('album_caption');
if( !empty($album_thumb) ): ?>
<div class="thumbs" style="width: 130px; float: left; margin: 5px;">
<img class="thumb thumb_album_<?php echo $album_name; ?>" src="<?php echo $album_thumb['url']; ?>" alt="<?php echo $album_thumb['alt']; ?>" width="130" />
<p class="title"><?php the_title(); ?></p>
<p class="caption"><?php echo $album_caption ?></p>
</div>
<?php endif; ?>
<?php endwhile; wp_reset_query(); ?>
</div>
<!-- end thumbnails -->
<?php
}
add_shortcode( 'album-gallery', 'album_gallery_shortcode' );
?>

I suspect that it has something to do with the Advanced Custom Posts plugin that you include with your plugin. I had a similar issue and I solved it by moving the acf folder one level down. Meaning, instead of myplugin/advanced-custom-fields I put it in myplugin/inc/advanced-custom-fields
and it worked.
Of course, don't forget to change the path on your plugin's main file to
include(ALBUM_GALLERY_ABSPATH . 'inc/custom-fields/acf.php');
BTW, I prefer to call the plugin like that:
if( !class_exists('Acf') )
{
define( 'ACF_LITE' , true ); // Hide it from admin
include_once('inc/advanced-custom-fields/acf.php' );
}
Because you don't want your users to load it again if they already have it installed.

I had a similar problem when including ACF in a plugin and it took me forever to figure it out, especially since I drop a plugin header template in the same way each time I create a new plugin.
The problem stemmed from the included acf.php plugin header. Remove the wordpress comment header from that file, and it seems to install fine, no matter what directory level you include it from.

Related

Blog posts won't open on my custom WordPress theme

This could be a dumb question, but I just can't figure it out. I'm working on a custom WordPress theme I created by converting a html website. But when I use WP_Query, it doesn't load my blog posts. Yes, it displays a list of blog posts as it should with the loop, but when I click on each title or the 'read more' link of a post, it only changes the url in the address bar to the link of the post and then simply refreshes the hope page. It doesn't open I'm really tired. Here's the query loop in my index.php
<?php
$categories = get_categories();
foreach ( $categories as $category ) {
//define args for query
$args = array(
'cat' => $category->term_id,
'post_type' => 'post',
'posts_per_page' => '30',
);
//The main query
$query = new WP_Query( $args );
if ( $query->have_posts() ) { ?>
<section class="<?php echo $category->name; ?> listing">
<h2>Latest in <?php echo $category->name; ?>:</h2>
<?php while ( $query->have_posts() ) {
$query->the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'category-listing' ); ?>>
<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'thumbnail' ); ?>
</a>
<?php } ?>
<h3 class="entry-title">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h3>
<?php the_excerpt(); ?>
</article>
<?php } // end while ?>
</section>
<?php } // end if
// Use reset to restore original query.
wp_reset_postdata();
}
?>
</div><!-- blog-main-content-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Please what do I do
Based on your comment above, you are missing a template file for your posts page. In your current configuration, the posts loop will be displayed on all pages of your website since you only have an index.php file. You should create a single.php template to display your single blog posts.
Here is the WordPress template hierarchy for reference: https://developer.wordpress.org/themes/basics/template-hierarchy/

Rendering an image on a WooCommerce product page

Using the Advanced Custom Fields plugin, I am trying to render an image on a single product page in WooCommerce.
I found this snippet of code from someone who is doing the same thing, but is rendering a text field instead. How would I change this to render an image?
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_top_category_desc', 1 );
function woocommerce_template_top_category_desc (){
$terms = get_the_terms( $post->ID, 'wc-attibute-class' );
if ( !empty($terms)) {
$term = array_pop($terms);
$text= get_field('txt-field', $term);
if (!empty($text)) {
echo $text;
}
}
}
So far I have this, but it's not working. The add action is correct because I was using it for something else, but starting at $terms is where I get lost and is obviously not right.
add_action( 'woocommerce_product_thumbnails' , 'add_below_featured_image', 9 );
function add_below_featured_image() {
$terms = get_the_terms( $post->ID, '496' );
if ( !empty($terms)) {
$term = array_pop($terms);
$image = get_field('banner_feedback', $term);
if (!empty($image)) {
echo $image;
}
}
}
Figured it out.
add_action( 'woocommerce_product_thumbnails' , 'add_below_featured_image', 9 );
function add_below_featured_image() {
if( is_single( pageidhere ) ) {
echo '<br><img src="urlhere">';
}
}
Steps to add custom gallery below featured image in woocommerce single product page(you can modify suitably to add just a single image):
Create an ACF for Image Gallery.
Copy the template for product-image.php from /plugins/woocommerce/templates/single-product to themes/your-child-theme/woocommerce/single-product/
Add the following code to product-image.php just before the closing div of
"images"
Add the images you want in the gallery to your single product admin page in the ACF custom field.
`
<?php $images = get_field('product_image_gallery'); ?>
<div class="mycustom_image_gallery">
<?php if($images): ?>
<div class="popup-gallery">
<?php foreach( $images as $image ): ?>
<a href="<?php echo $image['url']; ?>"
class="lightbox-link"
title="<?php echo $image['caption']; ?>"
data-description="<?php echo $image['description']; ?>">
<div class="image-wrap">
<img src="<?php echo $image['sizes']['thumbnail']; ?>">
</div>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
`

Content gets replaced after adding "get_template_part"

I am trying to add a Slider on my home page using a template from themeforest but I don't get any support there.
I am adding the following code to my header:
<?php get_template_part ( 'includes/featured/featured-call'); ?>
and this code calls featured-call.php and from there another files is called, flexislider.php that looks like this:
<section>
<div class="spaced-wrap clearfix">
<div class="flexslider-container clearfix">
<div class="flexslider-loader">
<div class="flexslider">
<ul class="slides">
<?php
$captioncodes="";
$count=0;
query_posts( array( 'post_type' => 'mtheme_featured', 'showposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC') );
?>
<?php if( have_posts() ) : while( have_posts() ) : the_post(); ?>
<?php
$image_id = get_post_thumbnail_id(($post->ID), 'full');
$image_url = wp_get_attachment_image_src($image_id,'full');
$image_url = $image_url[0];
$custom = get_post_custom(get_the_ID());
$featured_description="";
$featured_link="";
if ( isset($custom["featured_bigtitle"][0]) ) $featured_bigtitle=$custom["featured_bigtitle"][0];
if ( isset($custom["featured_description"][0]) ) { $featured_description=$custom["featured_description"][0]; }
if ( isset($custom["featured_link"][0]) && $custom["featured_link"][0]<>"" ) {
$featured_link=$custom["featured_link"][0];
} else {
$featured_link = get_post_permalink();
}
//$textblock=$featured_description;
$title=get_the_title();
$text=$featured_description;
$permalink = $featured_link;
$count++;
?>
<li>
<a href="<?php echo $permalink; ?>">
<img src="<?php echo $image_url; ?>" alt="<?php the_title(); ?>" />
</a>
<?php
$titlecode ='<div class="flex-title">' .$title . '</div>';
$captioncodes ='<div class="flex-caption">' . $text . '</div>';
$bigtitle='<div class="flex-bigtitle">'.$featured_bigtitle.'</div>';
echo '<div class="flex-caption-wrap">';
echo $titlecode;
echo $captioncodes;
echo $bigtitle;
echo '</div>';
?>
</li>
<?php
endwhile; endif;
?>
</ul>
</div>
</div>
</div>
</div>
The problem I have is that once this works, it loads the sliders as posts to the home page and instead of the page I had selected (Home). The page loads fine if I delete the "get_template_part" from header.php, otherwise the sliders come as posts and I don't see the page I selected from reading on wordpress.
My website is http://van-london.com/
I made it!
All I needed was this code after the "get_template_part"
<?php wp_reset_query(); ?>
Done! :)

random comments on page wordpress

my question is, how can i show random comments on a page on wordpress? in my website i got a wp page where people leaves lots of comments, i want them to show randomly and not assorted by date time, here's the code of the paginated comments, what should i do? thanks :)
<?php foreach ($comments as $comment) : ?>
<li <?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>">
<div class="paginated-comments-number" style="float: left; color: #999; width: 30px; text-align: left;"></div>
<?php
if ( function_exists('get_avatar') )
echo get_avatar( $comment, 48 );
?>
<cite><?php comment_author_link() ?>
</cite>
<?php if ($comment->comment_approved == '0') : ?>
<em>Your comment is awaiting moderation.</em>
<?php endif; ?><br />
<small class="commentmetadata"><?php comment_date('F jS, Y') ?> at <?php comment_time() ?> <?php edit_comment_link('edit',' ',''); ?></small>
<?php comment_text() ?>
</li>
<?php
/* Changes every other comment to a different class */
$oddcomment = ( empty( $oddcomment ) ) ? 'class="alt" ' : '';
?>
<?php endforeach; /* end for each comment */ ?>
</ol>
<p>
<!-- Start Paginated Comments Pages -->
<?php if ( Paginated_Comments_have_pages() ) : ?>
</p>
<p>
<?php endif; ?>
<!-- End Paginated Comments Pages -->
<?php else : // this is displayed if there are no comments so far ?>
<?php if ('open' == $post->comment_status) : ?>
<!-- If comments are open, but there are no comments. -->
<?php else : // comments are closed ?>
Here's a suggestion for a shortcode function that does what you're asking for:
add_shortcode( 'randomComment', 'randomComment_handler' );
function randomComment_handler($post_id) {
extract( shortcode_atts( array(
'post_id' => '0',
), $atts ) );
$out = "";
$comments = get_comments("post_id=$post_id&status=approve");
if ($comments) {
$ndx = mt_rand(0,sizeof($comments)) - 1;
$comment = $comments[$ndx];
$out = "<div class='randomComment'><div class='randomAuthor'>".$comment->comment_author."</div><div class='randomText'>".$comment->comment_content."</div></div>";
}
return $out;
}
This goes into your functions.php, and lets you put the shortcode on any page or post to show a random comment:
[randomComment post_id="1337"]
Just change the post_id according to the post you want to pull the random comment from.

Display WordPress Posts in Static HTML page - Adding more details

I need to add links to WordPress Posts on a static HTML page. I got some information that has been helpful but need a few more elements to make it complete.
Here is the code I have so far:
<?php
$number = 5;
$wordpress_header = "blog/wp-blog-header.php";
// Include wordpress header
if (file_exists($wordpress_header))
{
include ($wordpress_header);
$myposts = get_posts('numberposts=$number&offset=0&category=0');
echo "<ul class='Bloglinks'>";
foreach(array_slice($myposts, 0, $number) as $post)
{
echo '<li><a href="';
the_permalink();
echo '">';
the_date();
echo " ";
the_title();
echo '</a></li>';
}
echo "</ul>";
}
else
{
echo "Unable to connect to Wordpress header file.";
die();
}
?>
This only shows the titles of the most recent posts. I need to be able to display the following:
<h5>The truth about Lazy Eye</h5>
<p class="blog-info">07.16.10 | <a class="comment-ref">3 Comments</a></p>
<h5>More Adult Learning Problems Linked to Eyes</h5>
<p class="blog-info">06.12.10 | <a class="comment-ref">1 Comments</a></p>
<h5>New Vision Examination Instruments Arrived!</h5>
<p class="blog-info">05.10.10 | <a class="comment-ref">13 Comments</a></p>
You should use the function query_posts() with the functions have_posts() and the_post(). Here is an example for the WordPress API:
//The Query
query_posts('posts_per_page=5');
//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
..
endwhile; else:
..
endif;
//Reset Query
wp_reset_query();
That will loop through all posts you have queried. So you can just insert your query from the get_posts() function into the query_posts() function.
EDIT: I think if you want to stick with the get_posts() function, you have to call the setup_postdata() function to get the new post (source code for the API):
<ul>
<?php
global $post;
$myposts = get_posts('numberposts=5&offset=1&category=1');
foreach($myposts as $post) :
setup_postdata($post);
?>
<li><?php the_title(); ?></li>
<?php endforeach; ?>
</ul>
But I would recommend to take the query_posts() function instead.
<?php
require($_SERVER['DOCUMENT_ROOT'] . '/wp-load.php');
$args = array(
// 'cat' => 3, // Only source posts from a specific category
'posts_per_page' => 6 // Specify how many posts you'd like to display
);
$latest_posts = new WP_Query( $args );
if ( $latest_posts->have_posts() ) {
while ( $latest_posts->have_posts() ) {
$latest_posts->the_post(); ?>
<article class="vertical-item content-padding ls">
<div class="item-media">
<img src="<?php the_post_thumbnail() ?>" alt="<?php the_title(); ?>">
</div>
<div class="item-content">
<h4 class="entry-title">
<?php the_title(); ?>
</h4>
<div>
<div class="media-body media-middle greylinks">
<br><a class="small-text" href="#"><?php the_time('l jS F, Y') ?></a>
</div>
</div>
</div>
<div class="item-footer">
<a class="lato lightgrey weight-black" href="<?php the_permalink(); ?>">Read this Article</a>
</div>
</article>
<? }
} else {
echo '<p>There are no posts available</p>';
}
wp_reset_postdata();
?>

Resources