Wordpress Themes - WP Forum at BFA
Click Here To DONATE! Support the theme development, get more attention and additional benefits based on your donation level. Your forum name will be highlighted.

Wordpress Themes - WP Forum at BFA » WordPress Themes » Atahualpa 3 Wordpress theme » Sidebars & Widgets »

Add related php code to sidebar


Build custom WP THEMES, without
coding.
Click here for THEMEFRAME

From the author of Atahualpa, the #1 most
downloaded (700,000+) theme @ wordpress.org
  #1  
Old Sep 19, 2011, 10:13 AM
sidejack
 
6 posts · Sep 2011
Add related php code to sidebar

Hi,

I'd like to use a specific-tag related-post function like the below, but would like to use it in the sidebar. I have no idea how to do that . Would really appreciate your thoughts. I tried clumsily to add it to footer.php, but I don't think that's the right way to do it (and nothing seemed to happen). I looked at the widget tabs in Atahualpa options, but didn't quite understand how all that works. Basically, I'd like to add the following functionality to the right sidebar.

Code:
<?php
$tags = wp_get_post_tags($post->ID);
  if ($tags) {
  $first_tag = $tags[0]->term_id;
  $args=array(
  'tag__in' => array($first_tag),
     'post__not_in' => array($post->ID),
     'showposts'=>5,
     'caller_get_posts'=>1
    );

  $rel_posts = new WP_Query($args);
   if( $rel_posts->have_posts() ) {
   while ($rel_posts->have_posts()) : $rel_posts->the_post(); ?>

<div class="rel_posts">
<div class="rel_thumb"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(array(130,130)); ?></a></div>
<div class="rel_link"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></div> 
</div>
<?php
endwhile; 
}
}
?>   

<div class="clearer"></div>
Appreciate your time. Thanks a lot.

Last edited by sidejack; Sep 19, 2011 at 10:31 AM.
  #2  
Old Sep 19, 2011, 10:47 AM
juggledad's Avatar
juggledad
 
22,244 posts · Mar 2009
OSX 10.8.5 WP 3.8.x Atahualpa 3.7.x Safari 6.x Firefox 25 XP
add 'text' widget to the sidebar, add the code to it then get the 'exec-php' plugin
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
  #3  
Old Sep 19, 2011, 11:32 AM
sidejack
 
6 posts · Sep 2011
Quote:
Originally Posted by juggledad
add 'text' widget to the sidebar, add the code to it then get the 'exec-php' plugin
Hi. Thanks a lot. Unfortunately, that doesn't seem to work. I get nothing there except the text widget header. I thought perhaps it was that particular exec-php plugin and another might do the trick, so installed another php executor called Shortcode Exec PHP. This one also didn't work but it outputs some kind of debug information which might be of use. It outputs this into the sidebar area where it should execute --

Code:
Parse error: syntax error, unexpected '<' in /home/main_folder/public_html/mysite.com/wp-content/plugins/shortcode-exec-php/shortcode-exec-php-class.php(893) : eval()'d code on line 1
I don't know if that helps. So exec-php doesn't seem to want to execute it and this one outputs that. When that related post PHP code is placed in index.php though, it works fine. So far, it doesn't want to play ball in the sidebar.
  #4  
Old Sep 19, 2011, 12:36 PM
juggledad's Avatar
juggledad
 
22,244 posts · Mar 2009
OSX 10.8.5 WP 3.8.x Atahualpa 3.7.x Safari 6.x Firefox 25 XP
actually it is being executed, put
HTML Code:
echo 'hello there';
and you will see it prints out. The problem is that your code is not working
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
  #5  
Old Sep 19, 2011, 05:56 PM
sidejack
 
6 posts · Sep 2011
Okay, I think the problem is it needs to be in the loop so as to be called from tags in the post. When it's in the sidebar, it won't pick up the post's tags. If I put the code in the loop and then use exec-php with just this in a widget --

Code:
<div class="rel_posts">
<div class="rel_thumb"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(array(130,130)); ?></a></div>
<div class="rel_link"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></div> 
</div>
I can obviously put the current post in the sidebar because that's really just a stripped down, almost independent functionality anyway. How can I make it echo the functionality that shows in the actual post or force it to read the tags from the post?

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stuck with php code / left sidebar mikeindidginus Atahualpa 3 Wordpress theme 11 Jun 16, 2011 01:15 AM
Putting Code/Sign Up Form into Sidebar gradlebum Sidebars & Widgets 14 Apr 26, 2010 03:31 PM
how to insert php code into widget or sidebar Stingraynut Header configuration & styling 1 Apr 6, 2010 08:25 PM
[SOLVED] No sidebar.php...where do I put the code? d_random Atahualpa 3 Wordpress theme 0 Apr 3, 2009 12:42 PM
I'm not sure what file I need add code for the sidebar jockoe Atahualpa 3 Wordpress theme 0 Mar 18, 2009 09:45 AM


All times are GMT -6. The time now is 03:36 PM.


Powered by vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.