Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Wednesday, August 22, 2012

Wordpress: How to retrieve multiple page content?

Here is a quick snippet to retrieve content from multiple pages and display on any page, post or template. You  can even try creating a short-code for this functionality and could pass page id's to in the argument.

Below, is the screenshot for what I achieved from this code.



<?php
  /*
  Pass the page id's in an array.
  */
  $home_pages = array('11', '13', '16');
  $output =''; // Output variable

foreach($home_pages as $key => $val) {
      $output .= '<div class="box">';
      $page_id = $val; 
      $page_data = get_page( $page_id ); 
      $output .= get_the_post_thumbnail($page_id);
      $page_link = $page_data->guid; //This for SEF permalinks
      $page_link = explode('/?', $page_link);
      $page_link = $page_link[0];
      $page_link = $page_link . '/' . $page_data->post_name;
      $output .= '<h3>'. $page_data->post_title .'</h3>';
      $content = apply_filters('the_content', $page_data->post_content); 
      $content = substr($content, 0 , 100);
      $output .= $content . '...';
      $output .= '<br /><a href="'.$page_link.'" title="Read More">Read More...</a>';
      $output .= '</div>';
 }
 
 echo $output;
?>

Monday, August 13, 2012

Wordpress - shortcode for current theme path

You can find this short code useful when inserting some file or image from the relative path of your theme. Simply copy and paste following code inside your theme's functions.php and use the short code in your Page/ Post editor.

<?php
function currentThemePath() {
return get_option('home') . '/wp-content/themes/activeThemeName/';
}
add_shortcode('myThemePath', 'currentThemePath');
?>

Replace 'activeThemeName' with your current active theme name.
And use the short code [myThemePath] in your page/ post.