Interlinking in pages from Admin backend wordpress 3.1 - wordpress

I want to do interlinking within wordpress pages and say my URL is www.test.com for example and i have www.test.com/p1 www.test.com/p2 and www.test.com/p3 pages and I want to add p1 and p2 links in p3 from admin side.. right now, I just insert and same for p2.. but if my permanlink changes than i need to change content again.. Is there any solution to this.. so I can able to insert just ID of page with and it will convert it automatically to link.

You can use the shortcode api to generate links with post-ids.
When you add following code into your function.php
add_shortcode('permalink', 'permlink_replace_func');
function permlink_replace_func($atts){
extract(shortcode_atts(array(
'id' => '',
'lable' => 'link'
), $atts));
$permpost = get_post($id);
$html = '<a href="'.get_permalink($id).'" >';
if ($lable==null) {
$html .= $permpost->post_title;
} else {
$html .= $lable;
}
$html .= '</a>';
return $html;
}
you can enter a string like [permalink id ="8" lable="hallo world"] in the content area of a post to get a link to another post per id.
More information about shortcodes you can find at the WordPress Shortcode API.

Related

How do you get wordpress plugin shortcode to $_GET url parameters

I have a plugin on a page update-data which has a shortcode on the page of [updatedata]
here is what an update row looks like
<td>UPDATE</td>
Here is what the plugin code is
<?php
/*
plugin name: deano plugin update
description: deano test database to update data into books table
author: Dean-O
*/
$path = preg_replace('/wp-content.*$/', '', __DIR__);
require_once($path.'/wp-load.php');
error_log("here"); // echos to log file
error_log(var_dump($id)); // echos a blank line to the log file
error_log("here 2"); // echos to the log file
function deanoupdatedata($atts, $content = null ) {
$a = shortcode_atts( array(
'id' => 'id'
), $atts );
return '<a id="' . esc_attr($a['id']) . '</a>'; // never displays
}
add_shortcode('updatedata','deanoupdatedata');
?>
How can I get the url parameter id in the plugin when I click on update link?
Try if($_GET['id']) instead of isset and istead of error_log use var_dump to get the exact value
It is a bad practice. You should pass the data to a shortcode using the shortcode's attributes.

social icon location in wordpress

function flx_social_sharing_buttons($content) {
// Show this on post and page only. Add filter is_home() for home page
if(is_singular()){
// Get current page URL
$shortURL = get_permalink();
// Get current page title
$shortTitle = get_the_title();`enter code here`
// Construct sharing URL without using any script
$twitterURL = 'https://twitter.com/intent/tweet?text='.$shortTitle.'&url='.$shortURL.'&via=flx';
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$shortURL;
$googleURL = 'https://plus.google.com/share?url='.$shortURL;
$tumblrURL = 'http://www.tumblr.com/share/link?url='.$shortURL;
// Add sharing button at the end of page/page content
$content .= '<div class="flx-social">';
$content .= '<a class="flx-link flx-facebook" href="'.$facebookURL.'" target="_blank"><i class="fa fa-facebook"></i></a>';
$content .= '<a class="flx-link flx-twitter" href="'. $twitterURL .'" target="_blank"><i class="fa fa-twitter"></i></a>';
$content .= '<a class="flx-link flx-googleplus" href="'.$googleURL.'" target="_blank"><i class="fa fa-google-plus"></i></a>';
$content .= '<a class="flx-link flx-tumblr" href="'.$tumblrURL.'" target="_blank"><i class="fa fa-tumblr"></i></a>';
$content .= '</div>';
return $content;
}else{
// if not post/page then don't include sharing button
return $content;
}
};
add_filter( 'the_content', 'flx_social_sharing_buttons');
i use this code to display sociAl sharing buttons below my post ,
i need to add shortcode functionality so that it appears wherever i want
how to do it pls help
You simply can do it with bellow code,
<?php echo do_shortcode('[the_content]'); ?>
just pest this code where you want social icons and u can get it on those place.
I'm not sure that I understand your question correctly, but hopefully you'll be able to use the following to address your challenge.
If I wanted to repurpose the function to render the social sharing buttons, I would start of by changed the first line to
function flx_social_sharing_buttons($content = false) {
The code should at this stage still, as expected, add the social sharing buttons after each post. To add it programmatically or within a post or page you can add the following line, creating a shortcode:
// Add the [my-social-buttons] shortcode
add_shortcode( 'my-social-buttons', 'flx_social_sharing_buttons' );
Documentation available at: https://codex.wordpress.org/Shortcode_API
Great resource for creating shortcodes and other Wordpress features:
http://generatewp.com
You can now use the shortcode in a post or page. To use it inside a php file, do the following
echo do_shortcode('[my-social-buttons]');
If you find that you'd rather now use your function programatically all that's left to do is to remove the original hook, if your social sharing buttons are now duplicated:
// Remove or comment out
// add_filter( 'the_content', 'flx_social_sharing_buttons');

Custom Fields/Values displaying out of order

I'm using the Types Wordpress plugin to enable custom fields. The plugin allows you to rearrange the order of the images in the admin page editor. Here's my code in my single.php to display multiple images in the custom field and have a link to itself to also use Fancybox:
<?php
$mykey_values_img = get_post_custom_values('wpcf-image');
if ($mykey_values_img != null) {
foreach ( $mykey_values_img as $key => $value ) {
?>
<img src="<?php echo $value; ?>" />
<?php
} //foreach
} //if
?>
Problem:
Right now this code works perfectly on my local copy running on MAMP. However, when I put it online hosted on iPage, the images are out of order. I don't know what's causing this discrepancy. When I use the shortcode from Types to display the images instead of the php above they are in order, but I don't have the option of using Fancybox. I was also wondering if there is a better way to display an image from Wordpress that will insert the alt tag for the image.
I just encountered this problem too, and your first answer led me to a tighter solution.
I also used types_render_field(), but if you include a 'raw' parameter, you can avoid the string manipulation.
$images_raw = types_render_field('image', array('raw'=>'true','separator'=>';'));
$images = explode(';', $images_raw);
foreach ($images as $link) {
echo '' . $link . '">"';
}
Then, if you're nasty, you can get the ID of the attachment from its SRC. Using that ID, you can get all the info you need about that attachment, like a caption, or whatnot.
I figured out a work around to get it working. Its not ideal but it works.
The Types plugin came with its own php function to display the custom field called types_render_field. It displayed my images in order. To get fancybox working I had to do sort of a hack on the string. Here's the code:
$images = ( types_render_field( "image", array( 'size' => 'full', 'alt' => get_the_title(), 'title' => get_the_title() ) ) );
$imgArray = explode(">", $images);
foreach ( $imgArray as $value ) {
$pos1 = strpos($value, 'src="', 0)+5;
$pos2 = strpos($value, '" ', $pos1);
$link = substr($value, $pos1, $pos2 - $pos1);
echo ''.$value.">";
}

How to display taxonomies instead of categories in my website home page by using WordPress (PHP)?

I have a taxonomy called operating_system.In the admin panel I have created a few taxonomy. On the homepage I want to display the taxonomies instead of categories. what can i do to get exact answer.please suggest me a suitable code.
How about this:
<?php
$args=array(
'name' => 'genre'
);
$output = 'objects'; // or objects
$taxonomies=get_taxonomies($args,$output);
if ($taxonomies) {
foreach ($taxonomies as $taxonomy ) {
echo '<p>' . $taxonomy->name . '</p>';
}
}
?>
You can see more details and examples in the codex.

Drupal Site Map Module

I am looking for a module that can create sitemap in Drupal, but couldn't find any. I tried Site Map module, but it can only generate a sitemap page; it can't create a sitemap block at the end of every page. I also tried site menu module, but it can't create a sitemap block as shown above, as well.
Maybe it's just that I don't know how to configure, but I read every readme file, and tried for a few days, still can't get it to work.
Anyone has any idea?
I had the same problem, after trying a module (site-map) but missing customization options I wrote a custom module. Took less time then messing with the site-map module, for just getting a site map the following code is enough (adapt your-menu):
function sitemap_render_menu ($menu) {
$output = "<ul>";
foreach ($menu as $item) {
$link = $item["link"];
if ($link["hidden"]) {
continue;
}
$output .= "<li>" . $link["title"] . "</li>";
if ($item["below"]) {
$output .= sitemap_render_menu($item["below"]);
}
}
$output .= "</ul>";
return $output;
}
function sitemap_content () {
$output = "<h1>Sitemap</h1>";
$output .= "<span id=\"sitemap\">";
$output .= sitemap_render_menu(menu_tree_all_data("your-menu"));
$output .= "</span>";
return $output;
}
function sitemap_menu () {
$items = array();
$items["sitemap"] = array (
"title" => "Sitemap",
"page callback" => "sitemap_content",
"access arguments" => array("access content"),
"type" => MENU_CALLBACK);
return $items;
}
There is a basic comparison of sitemap modules at http://groups.drupal.org/node/15980
I have used sitemenu and it worked for my needs, but the real answer depends on how you structure your site with taxonomy, content types, etc.
Something like Auto Menu might work for you here as well. You could simply add the menu it generates to a footer block on your front page.
With the Site Map module installed, this php code will print the site map.
<?php echo theme('site_map'); ?>
You could create an empty views block and specify the above for the empty text, selecting the PHP Code input format.
There may be a better way to create a custom block to display php code, but I don't know it.
My idea here is to use Views module with customized block type.
I think you can benefit from Menu block module. as you can create menu blocks for all the menus you need in the footer. Then you can add them all in footer or in a one block using minipanels block (from panels module).
You can use Footer_sitemap module which provides us with the configurable block.
https://drupal.org/project/footer_sitemap
This is a little mod of best answer it uses current theme to show hierarchy
function sitemap_render_menu ($menu) {
$output = "<ul class='menu'>";
foreach ($menu as $item) {
$link = $item["link"];
if ($link["hidden"]) {
continue;
}
$cc=($item["below"]) ? "class='collapsed'" : '';
$output .= "<li $cc>" . $link["title"] . "";
if ($item["below"]) {
$output .= sitemap_render_menu($item["below"]);
}
$output .= "</li>";
}
$output .= "</ul>";
return $output;
}
function sitemap_content ($title,$menu) {
$output = "<h1>$title</h1>";
$output .= "<span id=\"sitemap\">";
$output .= sitemap_render_menu(menu_tree_all_data($menu));
$output .= "</span>";
return $output;
}
function sitemap_menu () {
$items = array();
$items["sitemap"] = array (
"title" => "Sitemap",
"page callback" => "sitemap_content",
"access arguments" => array("access content"),
"type" => MENU_CALLBACK);
return $items;
}
print sitemap_content("Navigational menu","Navigation");
A simple solution which doesn't depend on content being included as a menu item can be achieved by :
Creating a new view
Output as a block
Using Fields:
Content Title (configured to "Link this field to the original piece of content"
Content Type (configured to "Exclude from display")
Format as
Unformatted list with settings - Grouping field Nr.1 select Content:Type;
Filter Criterea:
Content: Published (Yes)
Content Type - Configure to select the content types you wish to include;
Sort criteria - Configure as per your preference

Resources