Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all 8245 articles
Browse latest View live

louis-p on "Page id only breadcrumb trail"

$
0
0

So I am trying to configure my breadcrumb trail to page id only, I have an example of a website which I want to mimic but I am finding the breadcrumb trail php too difficult to edit.

The website I am trying to mimic is: http://fourdrubber.com/

and the code for my breadcrumbs are as follows.

if ( ! function_exists( 'presscore_get_breadcrumbs' ) ) :

	/**
	 * Returns breadcrumbs html
	 * original script you can find on http://dimox.net
	 *
	 * @since 1.0.0
	 *
	 * @return string Breadcrumbs html
	 */
	function presscore_get_breadcrumbs( $args = array() ) {

		$default_args = array(
			'text' => array(
				'home' => _x('Home', 'breadcrumbs', 'the7mk2'),
				'category' => _x('Category "%s"', 'breadcrumbs', 'the7mk2'),
				'search' => _x('Results for "%s"', 'breadcrumbs', 'the7mk2'),
				'tag' => _x('Entries tagged with "%s"', 'breadcrumbs', 'the7mk2'),
				'author' => _x('Article author %s', 'breadcrumbs', 'the7mk2'),
				'404' => _x('Error 404', 'breadcrumbs', 'the7mk2')
			),
			'showCurrent' => 1,
			'showOnHome' => 1,
			'delimiter' => '',
			'before' => '<li class="current">',
			'after' => '</li>',
			'linkBefore' => '<li typeof="v:Breadcrumb">',
			'linkAfter' => '</li>',
			'linkAttr' => ' rel="v:url" property="v:title"',
			'beforeBreadcrumbs' => '',
			'afterBreadcrumbs' => '',
			'listAttr' => ' class="breadcrumbs text-normal"'
		);

		$args = wp_parse_args( $args, $default_args );

		$breadcrumbs_html = apply_filters( 'presscore_get_breadcrumbs-html', '', $args );
		if ( $breadcrumbs_html ) {
			return $breadcrumbs_html;
		}

		extract( array_intersect_key( $args, $default_args ) );

		$link = $linkBefore . '<a' . $linkAttr . ' href="%1$s" title="">%2$s</a>' . $linkAfter;

		$breadcrumbs_html .= '<div class="assistive-text">' . _x('You are here:', 'breeadcrumbs', 'the7mk2') . '</div>';

		$homeLink = home_url() . '/';
		global $post;

		if (is_home() || is_front_page()) {

			if ($showOnHome == 1) {
				$breadcrumbs_html .= '<ol' . $listAttr . '><a href="' . $homeLink . '">' . $text['home'] . '</a></ol>';
			}

		} else {

			$breadcrumbs_html .= '<ol' . $listAttr . ' xmlns:v="http://rdf.data-vocabulary.org/#">' . sprintf($link, $homeLink, $text['home']) . $delimiter;

			if ( is_category() ) {

				$thisCat = get_category(get_query_var('cat'), false);

				if ($thisCat->parent != 0) {

					$cats = get_category_parents($thisCat->parent, TRUE, $delimiter);
					$cats = str_replace('<a', $linkBefore . '<a' . $linkAttr, $cats);
					$cats = str_replace('</a>', '</a>' . $linkAfter, $cats);

					if(preg_match( '/title="/', $cats ) ===0) {
						$cats = preg_replace('/title=""/', 'title=""', $cats);
					}

					$breadcrumbs_html .= $cats;
				}

				$breadcrumbs_html .= $before . sprintf($text['category'], single_cat_title('', false)) . $after;

			}

 elseif ( is_search() ) {

				$breadcrumbs_html .= $before . sprintf($text['search'], get_search_query()) . $after;

			} elseif ( is_day() ) {

				$breadcrumbs_html .= sprintf($link, get_year_link(get_the_time('Y')), get_the_time('Y')) . $delimiter;
				$breadcrumbs_html .= sprintf($link, get_month_link(get_the_time('Y'),get_the_time('m')), get_the_time('F')) . $delimiter;
				$breadcrumbs_html .= $before . get_the_time('d') . $after;

			} elseif ( is_month() ) {

				$breadcrumbs_html .= sprintf($link, get_year_link(get_the_time('Y')), get_the_time('Y')) . $delimiter;
				$breadcrumbs_html .= $before . get_the_time('F') . $after;

			} elseif ( is_year() ) {

				$breadcrumbs_html .= $before . get_the_time('Y') . $after;

			} elseif ( is_single() && !is_attachment() ) {
				$post_type = get_post_type();
				if ( $post_type != 'post' ) {

					$post_type_obj = get_post_type_object( $post_type );
					$slug = $post_type_obj->rewrite;
					$breadcrumbs_html .= sprintf($link, get_post_type_archive_link( $post_type ), $post_type_obj->labels->singular_name);

					if ($showCurrent == 1) {
						$breadcrumbs_html .= $delimiter . $before . get_the_title() . $after;
					}
				} else {

					$cat = get_the_category(); $cat = $cat[0];
					$cats = get_category_parents($cat, TRUE, $delimiter);

					if ($showCurrent == 0) {
						$cats = preg_replace("#^(.+)$delimiter$#", "$1", $cats);
					}

					$cats = str_replace('<a', $linkBefore . '<a' . $linkAttr, $cats);
					$cats = str_replace('</a>', '</a>' . $linkAfter, $cats);

					$breadcrumbs_html .= $cats;

					if ($showCurrent == 1) {
						$breadcrumbs_html .= $before . get_the_title() . $after;
					}
				}

			} elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {

				$post_type_obj = get_post_type_object(get_post_type());
				if ( $post_type_obj ) {
					$breadcrumbs_html .= $before . $post_type_obj->labels->singular_name . $after;
				}

			} elseif ( is_attachment() ) {

				if ($showCurrent == 1) {
					$breadcrumbs_html .= $delimiter . $before . get_the_title() . $after;
				}

			} elseif ( is_page() && !$post->post_parent ) {

				if ($showCurrent == 1) {
					$breadcrumbs_html .= $before . get_the_title() . $after;
				}

			} elseif ( is_page() && $post->post_parent ) {

				$parent_id  = $post->post_parent;
				$breadcrumbs = array();

				while ($parent_id) {
					$page = get_page($parent_id);
					$breadcrumbs[] = sprintf($link, get_permalink($page->ID), get_the_title($page->ID));
					$parent_id  = $page->post_parent;
				}

				$breadcrumbs = array_reverse($breadcrumbs);

				for ($i = 0; $i < count($breadcrumbs); $i++) {

					$breadcrumbs_html .= $breadcrumbs[$i];

					if ($i != count($breadcrumbs)-1) {
						$breadcrumbs_html .= $delimiter;
					}
				}

				if ($showCurrent == 1) {
					$breadcrumbs_html .= $delimiter . $before . get_the_title() . $after;
				}

			} elseif ( is_tag() ) {

				$breadcrumbs_html .= $before . sprintf($text['tag'], single_tag_title('', false)) . $after;

			} elseif ( is_author() ) {

				global $author;
				$userdata = get_userdata($author);
				$breadcrumbs_html .= $before . sprintf($text['author'], $userdata->display_name) . $after;

			} elseif ( is_404() ) {

				$breadcrumbs_html .= $before . $text['404'] . $after;
			}

			if ( get_query_var('paged') ) {

				$breadcrumbs_html .= $before;

				if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) {
					$breadcrumbs_html .= ' (';
				}

				$breadcrumbs_html .= _x('Page', 'bredcrumbs', 'the7mk2') . ' ' . get_query_var('paged');

				if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) {
					$breadcrumbs_html .= ')';
				}

				$breadcrumbs_html .= $after;

			}

			$breadcrumbs_html .= '</ol>';
		}

		return apply_filters( 'presscore_get_breadcrumbs', $beforeBreadcrumbs . $breadcrumbs_html . $afterBreadcrumbs, $args );
	} // end presscore_get_breadcrumbs()

endif;

my site is not live and only just in the interim of being built - no content etc,

but the breadcrumb trail is displaying archives and categories which I just plainly don't want to display.

Kind regards


arvobowen on "Get all the types of image sizes from WordPress DB"

$
0
0

Is it possible to simply query the WordPress DB for the types of images created when an image is uploaded?

For example, I upload an image and it creates 7 images...
aMEsvTUklw0uZ3gk3Q6lAj6302a.jpg
aMEsvTUklw0uZ3gk3Q6lAj6302a-50x50.jpg
aMEsvTUklw0uZ3gk3Q6lAj6302a-150x150.jpg
aMEsvTUklw0uZ3gk3Q6lAj6302a-200x300.jpg
aMEsvTUklw0uZ3gk3Q6lAj6302a-400x280.jpg
aMEsvTUklw0uZ3gk3Q6lAj6302a-680x330.jpg
aMEsvTUklw0uZ3gk3Q6lAj6302a-683x1024.jpg

I know that a bunch are generated due to the current theme I use. So the breakdown... The first image is of course the original. I think 150x150, 200x300, and 683x1024 are standard default settings for WordPress itself (that I can change in the settings). The rest (50x50, 400x280, 680x330) I think are generated per my theme.

I want to be able to simply query the raw WordPress database and get back the 6 EXTRA images to create.

Is this possible?

nathanwinkelmes on "Turn off display of anything before a certain year (Digg Digg plugin)"

$
0
0

Ok so I have a sort of odd request. I am working on a blog migration and the writer implemented the Digg Digg plugin in 2005 for social sharing. Because of this, all posts before then have zero shares. We want to turn off the plugin display for any post before this date. I am hoping to get some insight on what exactly I need to do to make this work. I have an idea of what to do but I need some direction and some technical advice.

Thanks!

rflores on "Using Action Hooks"

$
0
0

Got a project with WordPress that uses the wp-client & woocommerce plugin. New users get registered on checkout. I need to call a 3rd party's REST API to update a remote database when new users are registered and when current users get updated. I also need to update product subscriptions through the 3rd party's REST API.

I created my own plugin to do this but I'm pulling my hair out because I can't figure out how to do this. I tried using an action hook for either the WordPress "user register" and I even tried to use the WP-Client action hook "wpc_client_new_client_registered".

I tried using echo statements to see if they fire off but all that happens is that the checkout complete page commences. How do I use these hooks and how can I get the registered user's data so I can use cURL to call the REST API?

joe.klovance on "Wordpress with codeigniter"

$
0
0

I have Codeigniter integrated with Wordpress in that I can render Codeigniter pages within the Wordpress shell. I used the method in this link; https://rivers-media.com/wordpress-and-codeigniter-together-at-last/

My problem now is that no Wordpress pages render. All I get is a blank page. I was thinking that I could create a Codeigniter controller that would render a Wordpress page. All I would need is the call that, given a page ID, would render the page. Does anyone know of such a render call?

liquid8 on "WC_Order -class not found"

$
0
0

Hi,

I am making a plugin where I have done the following at one point of the code:

global $woocommerce;
$order = new WC_Order($orderID);

I am getting this error:
Fatal error: Class 'WC_Order' not found in /

By googling I have only found the solutions where the answer has been to add that global $woocommerce to my code before using the WC_Order-class. This code is inside my custom class. What am I missing here? :)

kainsight on "Re-styling webform button"

$
0
0

Having trouble styling my webform button. If you visit http://www.acquireretainengage.com a pop-up window appears (there is no content as we are still testing the site, which is not live yet)

The standard grey button styling just won't go away. I have set a class in Custom CSS:

.myButton {
background-color:#2fe7bf;
-moz-border-radius:3px;
-webkit-border-radius:3px;
border-radius:3px;
border:1px solid #2fe7bf;
display:inline-block;
cursor:pointer;
color:#ffffff;
font-family:Arial;
font-size:15px;
padding:9px 23px;
text-decoration:none;
text-shadow:0px 1px 0px #2fe7bf;
}

And the button code is this:

<tr><td padding='10px'>
<p class='myButton'>
<input type='submit' value='Submit' /></p>
</td>
</tr>

What am I doing wrong? It seems the button class has increased the size of the button with the edges being the colour I am after, but the center is still grey and it won't budge.

Igor Yavych on "the_excerpt and the_content filters"

$
0
0

I'm in a kind of a bind. I'm adding rating to posts. It's done with the_content filter. Thing is, some themes use excerpt instead of content in, say, archive loops. Adding rating to that is as simple as just adding filter for the_excerpt. Problem is, when excerpt is retrieved, it fires the_content filter too (so rating is actually added), but after that, content is stripped off all html tags, so rating as it is (shapes) is gone but vote counter remains. This leads to non pretty situation like this image
Now I'm wondering what's the good way around it? I don't think there is a way to see list of actions which will call action handler for the current post (so that if action handler is called from the_content filter (check by current_filter()) and there is the_excerpt in 'queue' for this post just return content without changes) or a way to know to know if the_content was fired by function to retrieve excerpt. Of course, very dirty and horrible workaround would be to check content for vote counter text when action handler is fired by the_excerpt and just replace it with empty string but that's not a good solution. Am I missing something here? Is there a cleaner way of doing this?


terminator_5505 on "Force single page template using a reserved term as URL parameter"

$
0
0

I'm using a single page template that is triggered by a url parameter by following this tutorial:
http://scratch99.com/wordpress/development/how-to-change-post-template-via-url-parameter/

my main problem is that I have to use the parameter m as example.com/?m=1
but it return a 404 error page
the parameter m is used for month in wordpress and it is a reserved term
http://codex.wordpress.org/Reserved_Terms

My question
Can I force wordpress to display my custom template with url parameter ?m=1
I don't want to use another url parameter is there anyway or a workaround to trigger a single page template using a reserved url parameter ??

thank you

pipspeak on "html tags in tinyMCE meta box not being encoded on page"

$
0
0

I have a meta box that uses tinyMCE instead of a plain textarea, but all html tags I use are simply being passed as text instead of correctly rendered on the page. Seems to be a filters issue, but I have no idea where to apply filters in the meta box functions. I would basically like to use exactly the same filters and html decoding in this meta box as are used in the post's main tinyMCE-powered text area.

I added tinyMCE using this code:

$value = get_post_meta( $post->ID, 'new_field', true );
$editor_id = 'new_field';
$settings = array( 'media_buttons' => false );
wp_editor( $value , $editor_id, $settings );

When saving I apply esc_textarea:

$my_data = esc_textarea( $_POST['new_field'] );

Sometime between that and the page, the HTML tags just get ignored. Any suggestions appreciated.

csleh on "help to fix php error: strlen() expects parameter 1 to be string, array given"

$
0
0

My goal is for $related to be used if any of the sub_fields are populated.

$topic_tags = get_sub_field('topic_related_tags');
 $topic_post = get_sub_field('related_post');
 $topic_page = get_sub_field('related_page');
	  $related = (strlen($topic_tags) + strlen($topic_post) + strlen($topic_page ) >0)?true:false;

Using
$related = (isset($topic_tags) && isset($topic_post) && isset($topic_page ))?true:false;
results as true even if there aren't any sub_fields.

But using (strlen()) gives an error where the title will go.
"Warning: strlen() expects parameter 1 to be string, array given..."

obviously I'm not a php coder but I have exhausted my google skills trying to figure it out.

HumbleThinker on "Adding a Plugin's Shortcode to Theme's PHP Files"

$
0
0

So I found a few threads asking this same question, but none of the answers were helpful to me. I'm having issues with the evolve Bootstrap Slider that I'm not getting help with (like the theme otherwise) so I want to add the Ultimate Responsive Slider to evolve's header.php file to add the slide to the header of each page as opposed to the body. Assuming it exists, what is the php code for utilizing the shortcode for a plugin. An example of the UR Slider's shortcode is [URIS id=108]. Thanks for any help.

djchub on "jquery not working in posts"

$
0
0

Hello,

I've been using this jquery code:-

var j=jQuery.noConflict();

// Use jQuery via $j(...)
j(document).ready(function(){

        j('#cs_overlay-menu').click(function() {
alert("hello");
              j('.cs_overlay').addClass('cs_overlay-open');
              j('cs_menuButton').hide();
});
       j('.cs_overlay-close').click(function() {
             j('.cs_overlay').removeClass('cs_overlay-open');
             j('cs_menuButton').show();
});
});

Its for a search function in the nav bar. It works perfectly. But if the search is in the posts page, it doesnt work.

nathanwinkelmes on "Categories Title Change"

$
0
0

Ok so I have successfully added my categories page and each category lists all of the posts on a new page when you click on the category. The problem is that when you are taken to the specific category page the title still displays as "Categories" rather than the respective category title. I am attaching my code from archive.php in the twentyfourteen theme.

<h1 class="page-title" style="text-transform:uppercase;">
<?php
     if ( is_day() ) :
          printf( __( 'Daily Archives: %s', 'twentyfourteen' ), get_the_date() );

     elseif ( is_month() ) :
          printf( __( 'Monthly Archives: %s', 'twentyfourteen' ), get_the_date( _x( 'F Y', 'monthly archives date format', 'twentyfourteen' ) ) );

     elseif ( is_year() ) :
          printf( __( 'Yearly Archives: %s', 'twentyfourteen' ), get_the_date( _x( 'Y', 'yearly archives date format', 'twentyfourteen' ) ) );

     elseif ( is_category('22') ) :
          _e('Featured Articles', 'twentyfourteen');

     else :
          _e( 'Categories', 'twentyfourteen' );

     endif;
?>
</h1>

Anderspin on "Can't get my plugin to echo ""

$
0
0

Hi!
I can't get my code properly and I don't know what I'm doing wrong.

I mean to echo a link made out of a wp_query. But when I run it it skips the "<a href=" -part. The result is that the post title won't be a link to the post.
Can anybody help me? I probably am making som silly misstake.

function get_news(){
	   $the_query = new WP_Query( array('category_name' => 'Nyhet'));

	   echo '<ul>';

	   while ( $the_query -> have_posts() ) {
	       $the_query -> the_post();
	       echo "<li>". the_post_thumbnail('news')."<a href='". the_permalink()."'>". the_title()."</a><p>".the_excerpt()." </p><hr></li>";

	   }

	   echo '</ul>';

	   }
	    wp_reset_postdata();

add_action('nyheter','get_news');

Thank you.


Grigory Volochiy on "Can't include wp-blog-header.php in external plugin's file under multisite"

$
0
0

I create a plugin, and it needs to have a php file, which needs be launched by CRON. And this php file need to use native WP functions.

To include this ability in that php file, I use the following code:

$file_root_directory = dirname(__FILE__); //get current file direct path

$target_string_array = explode('wp-content', $file_root_directory); //it is the way, how I get site directory

require_once ($target_string_array[0] . 'wp-blog-header.php'); //include native wp functions

This code works good when I use the plugin on usual single site installation.
But, when I install this plugin on multisite network and try to launch that php file - the script just breaks execution on line with "require_once" without even any error.

If I try to include any other php files - they are included successfully (these files just contain php functions and do nothing until they are not called).

How I understood that php file aborted execution on line with include "wp-blog-header.php", despite the script does not generate any error:

I just used this code and made a log:

file_put_contents(dirname(__FILE__) . '/log.txt', 'point 1' . "\r\n\r\n", FILE_APPEND);

$file_root_directory = dirname(__FILE__); //get current file direct path

file_put_contents(dirname(__FILE__) . '/log.txt', 'point 2' . "\r\n\r\n", FILE_APPEND);

$target_string_array = explode('wp-content', $file_root_directory); //it is the way, how I get site directory

file_put_contents(dirname(__FILE__) . '/log.txt', 'point 3' . "\r\n\r\n", FILE_APPEND);

require_once($target_string_array[0] . 'wp-blog-header.php'); //include native wp functions

file_put_contents(dirname(__FILE__) . '/log.txt', 'point 4' . "\r\n\r\n", FILE_APPEND);

The last point was "point 3".

Due to the fact, that the plugin works successfully on my local server (both - on single installation and multisite mode) but refuses to work on external server, I decided that the problem is in wp-config.php or in .htaccess files (apparently, some of the apach module that causes that bug in external server is disabled in the local server)

But I can't see any suspicious in those files.

In the wp-cofig.php I aded the following lines (accordingly to the multisite installation guide):

define('WP_ALLOW_MULTISITE', true);

define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'site-name.org');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

just before comment line:

/* That's all, stop editing! Happy blogging. */

The .htaccess looks like the following:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
</IfModule>

# END WordPress

On the local server and on the external server I use Sub-Directory for sites in network. And all other plugin's functionality works properly on both (like a wp hooks, sending data, working with database, etc). The problem is only when I try to launch that file, and exactly during including wp-blog-header.php, and only in external server.

Any one have some ideas, where I should to dig?

melissasms on "Custom Post Types"

$
0
0

I was asked to add a blog to an existing Wordpress installation. The problem is the "posts" category has been renamed, customized, and functions entirely different from the default set-up. The previous developer set up the website nicely, but I am not sure if adding a blog to their existing site is possible. They seemed to use the "Advanced Custom Fields" plug-in as well as custom functions in the back-end to give the posts area new functionality. If I go to edit a post (which is now called a resource), I don't get a text field where the content usually goes and see new areas for uploading material.

Website for reference: http://www.sani-care.com
The individual materials under the dealers section is currently what is set-up as "posts".

My question is how can I add a blog if the default posts section has been modified to such an extent? Is there anyway to duplicate the "posts" section of Wordpress?

emmyqg on "Show/Hide Content using multiple tags as chosen by reader"

$
0
0

I have an idea that I feel should be possible, but I can't figure out what plugin or hack might do this. I'm creating a link list and trying to sort or hide/show them by multiple categories, based on the reader's choice.

Example: let's say there are 5 links in the list (it's more like 50, hence the need for sorting). They could be:
1) Star Wars: A New Hope
2) Star Trek: Next Generation
3) Star Wars: Expanded Universe
4) Firefly / Serenity
5) Warehouse 13

I'd like to show the links (each with a short description) based on what the reader chooses. So the reader could choose:
- Show all Star Wars [result shows 1 and 3]
- Show all Space Shows [result shows 1, 2, 3, 4]
- Show all TV Shows [result shows 2, 4, 5]
and so on.

So, each link/description needs to have multiple tags/categories and whether they are shown or not needs to be triggered by user click.

I love the plugin Collaps-O-Matic but unfortunately it only allows for one ID or rel= per entry, so it won't work for my multiple-tag needs.

Suggestions?

meno010 on "Add review box by function at top or bottom of content by filter"

$
0
0

Filter

add_filter( 'the_content', 'sandy_posts_filter' );
    function sandy_posts_filter( $content )
    {
        global $post;
        $review_box_pos =get_post_meta( $post->ID, 'repeatable_fields', true );

        if (is_array($review_box_pos)) {
            foreach ($review_box_pos as $key => $val) {

            switch ($val[nameooz]) {
                case 'top':
                    $content = sandy_reviews() . $content;
                    break;

                case 'bottom':

                //$content .= "Extra Content"  ;  Work at footer Perfect//
                $content .= sandy_reviews()  ; //shown at top only !!!
                    break;

            } //End Switch

    }

    }

    return  $content ;
    }

Function

//////////////////// Reviews Box ///////////////////////
    function sandy_reviews() {
        $get_meta = get_post_custom($current_ID);
        $reviews = (get_post_meta(get_the_ID(), 'repeatable_fields', true));

        $sumArray = array();
        if (is_array($reviews))
        foreach($reviews as $k => $val) {
        foreach($val as $id => $value) {
        $sumArray[$id] += $value;
        }
        }

        $Reviwes_count = count($reviews);
        $Total_Reviwes = round(($sumArray[range] / $Reviwes_count), 1);

        if (!empty($reviews)) { ?>
                <div class = "reviews-box" >
                <div class = "reviews-box-title" >
        <?php
        $get_meta = get_post_custom($current_ID);

        if (!empty($reviews))
        foreach($reviews as $val) {
        echo $val["nameoo"];
        } ?>
                </div>

    <?php
        //Get Round Number
        if (!empty($reviews))
        foreach($reviews as $key => $val) {
        if (!empty($val[range]))

        $reviews_title = $val[nameoo];
        $ranges = $val[range];
        $range1 = ($val[range] * 0.01) * (5);
        $range2 = floor(($range1 * 2) / 2);

        $Reviwes = ($range1 * 20);

    ?>
            <div class = "reviews-box-row" >
            <div class = "reviews-box-keywords" > <?php echo $val[name]; ?> </div> <div class = "reviews-box-ranges" >
            <span style = "display: block;float:left; width: 65px; height: 13px; background: url( <?php echo get_template_directory_uri();?>/images/star-rating-sprite.png) 0 0;" >
            <span style = "display: block;float:left; width: <?php echo $ranges.'%';?>; height: 13px; background: url( <?php echo get_template_directory_uri();?>/images/star-rating-sprite.png) 0 -13px;" > </span> </span> <?php
            echo "</div></div>";}
    ?>
            <div class = "reviews-box-percent" > Summary </div>
            <!-- <div class="reviews-box-ranges"><?php //echo ($val[range]*0.01)*(5);?></div> -->
            <div class = "reviews-box-ranges-percent" >
            <div class = "Total_Reviwes" > <?php echo $Total_Reviwes.""; ?> </div>
            <span style = "display: inline-block; margin:0 auto;width: 65px; height: 13px; background: url( <?php echo get_template_directory_uri();?>/images/star-rating-sprite.png) 0 0;" >
            <span style = "display: block; margin:0 auto;float:left;width: <?php echo $Total_Reviwes.'%';?>; height: 13px; background: url( <?php echo get_template_directory_uri();?>/images/star-rating-sprite.png) 0 -13px;" > </span> </span>

    <?php

        echo "</div>";
        echo "</div>";
        }
        }

    //////////////////// Reviews Box END///////////////////////

1- Why this function not shown at bottom of content ?

2- Why when we used this filter at top of content it's show review box at

summary of content at category page !!

lolo23 on "Problem with custom shortcode using mysql query"

$
0
0

I have some code, which is currently working correctly in my content templates, that I wish to put into a shortcode to use on the home page. Problem is, it just displays the word 'Array' on my page.
Here is the code:

function cat_posts_function($atts){
   extract(shortcode_atts(array(
	  'cat' => 2
   ), $atts));
   	global $wpdb;
	$querystr = $wpdb->get_results
	("
		SELECT wposts.*
		FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
		WHERE wposts.ID = wpostmeta.post_id
		AND wpostmeta.meta_key  = 'product_name'
		AND wposts.post_type = 'post'
		AND ID IN ( SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = '$cat' )
		GROUP BY wpostmeta.meta_value
	");
	$pageposts = $wpdb->get_results($querystr, OBJECT);

	 	 if ($pageposts):
			global $post;
			foreach ($pageposts as $post):
			setup_postdata($post);
			'<a href="'.get_permalink().'"><img class="th_list" src="'.site_url().'/images/'.get_field("product_code").'.jpg" /></a>';
			endforeach;
			wp_reset_postdata();
		endif;
	return $pageposts;
}
add_shortcode( 'cat_posts', 'cat_posts_function' );

Does anyone know where I've gone wrong?
Thanks

Viewing all 8245 articles
Browse latest View live




Latest Images