How to communicate php between javascript? - html

How can i get the html table rows , then by clicking the button it will show the values in another page. in short i want to hold this variables in session to be use in other purposes.

Since you mentioned sessions, you can use sessions.
Here is an example (without using table rows, but you get the idea):
page1.php
<?php
session_start();
$_SESSION['someName'] = 'someDate';
?>
page2.php
<?php
session_start();
if(isset($_SESSION['someName'])){
echo $_SESSION['someName']; //outputs someDate
}
?>
page2-js.php
<?php
session_start();
if(isset($_SESSION['someName'])){
echo '<script>alert("'.$_SESSION['someName'].'")</script>'; //outputs someDate
}
?>

Related

How to insert <!--nextpage--> inside php if?

I would like to have a page break after the entry 90. I tried this. But it is not working. What is the error in this code?
<?php if ($entry[0] == 90):
echo <!--nextpage-->;
?>
First off, you don't end your if. Second, the echo still have to be within quotes, even though you're outputting a comment. So the correct structure would be this:
<?php if ($entry[0] == 90):
echo '<!--nextpage-->';
endif;
?>

I want to extract URL contain in my Wordpress post

I have around 1K posts in my blog. Every post contain URL something like "www.example.com/abcd.html" or "www.example.com/1234.html".
I want to extract those URL from every posts into a file.
Is there any query to do this job done?
Thanks,
Extracting URL within wordpress not easy part to extract. Why to more efforts if there are plugins available.
Install the following plugins and export them in CSV
https://wordpress.org/plugins/export-all-urls/
This will display all post link with title
<?php query_posts('posts_per_page=-1'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php
$content = $urls = wp_extract_urls( get_the_content() );
echo "<pre>";
print_r($content);
echo "<pre>";
endwhile;
endif; ?>

EntityMalformedException when retrieving Drupal 7 custom field

I am playing with Drupal and I am trying to add a second line to the site slogan.
The following is the piece of page.tpl.php where I am working.
<?php if ($site_name || $site_slogan): ?>
<div id="name-and-slogan" class="hgroup">
<?php if ($site_name): ?>
<h1 class="site-name">
<a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>">
<?php print $site_name; ?>
</a>
</h1>
<?php endif; ?>
<?php if ($site_slogan): ?>
<p class="site-slogan"><?php print $site_slogan; ?></p>
<?php endif; ?>
<?php
/* ADDED */
$node = menu_get_object();
$siteslogan2 = field_get_items('node', $node, 'field_siteslogan2');
?>
<?php if ($siteslogan2): ?>
<p class="site-slogan2"><?php print $siteslogan2; ?></p>
<?php endif; ?>
</div>
<?php endif; ?>
I basically added a new Content Type with a field called siteslogan2 (field_siteslogan2) and now I would like to retrieve and show it here.
The first problem is that the $node var is not defined (even if according to the documentation it should be). The second problem is that I receive EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() when I define it manually and run it.
First of all, is this the right approach to the problem? Secondly, why do I receive the EntityMalformedException and how can I fix it?
var_dump($node) produces NULL. It must be the way I get the $node content that is not good. The doc is a bit cryptic to me when it says:
$node: The node object, if there is an automatically-loaded node associated with the page, and the node ID is the second argument in the page's path (e.g. node/12345 and node/12345/revisions, but not comment/reply/12345).
This sort of thing is can be done using a preprocessing function in your theme's template.php to define and set a variable in the $varables array.
This variable then becomes available to whichever template ( page, node, form, etc ) you have done the preprocessing on. Your theme's template.php file will most likely have comments on how to do this.
for instance, doing this in the template.php creates or modifies the value of the variable $display_header, making it available for use in node.tpl.php
function yourthemename_preprocess_node(&$variables, $hook) {
$variables['display_header'] = false;
}
You can then modify the node template file to use this variable.
For something simple like a sub-slogan, you can add a setting to the theme, so it shows up on the theme's configuration page like any other theme setting.
This requires implementing this function in your theme's theme-settings.php:
function yourthemename_form_system_theme_settings_alter(&$form, $form_state) {}
This provides information to the settings form regarding the new setting. like this:
https://api.drupal.org/api/drupal/modules!system!theme.api.php/function/hook_form_system_theme_settings_alter/7
Hopefully that's enough to get you started.

how to fetch next row when given row is hidden using pagination?

It rather hard for me to come up with a short form of my question so bear with me:
Using jQuery and AJAX, I have all posts stored in my MySQL database displaying on index.php. Each post has a button the lets the user hide that post's DIV.
Now, I want to make it so that I only see 10 results and paginate the rest. I know there are plenty of pagination plugins out there but none of them displays the next post when the user hides one of the 10 already shown posts.
So if I see Posts 1-10 on page 1 (posts 11-20 on page 2) and user hides post 8, I should see Posts 1,2,3,4,5,6,7,9,10,11 on page 1 with posts 12-21 on page 2 and so on.
Question is: How do I do that? Here's what I have right now (fetch posts from database, display posts on page + hide button toggling):
// Javascript
$(document).ready(function() {
$(document).on("click", ".hide", function(){
postID = $(this).attr('id').replace('hide_', '');
$('#post-' + postID).toggle();
return false;
});
});
// PHP
<?php
$pageposts = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->posts"), OBJECT);
?>
<?php if ($pageposts): ?>
<?php global $post; ?>
<?php foreach ($pageposts as $post): ?>
<?php setup_postdata($post); ?>
<div id="buttons_<?php the_ID(); ?>">
<div id="hide_<?php the_ID(); ?>" class="hide" style="position:absolute; right: 2.5em;">
<a id="hidebtn_<?php the_ID(); ?>" href="#"><span></span></a>
</div>
</div>
<div id="post-<?php the_ID(); ?>">
/* display post content */
</div>
<?php endforeach; ?>
<?php endif; ?>
An easy way to figure out what would be the next ID to grab would be to store the MAX id on the page, so if your page displays 1-10, 10 would be stored as the MAX id.
When a user hides a post, the mysql query would pull 1 result where id > the stored max id.

Header on Individual Posts

I want to be able to customize my header on individual posts on my blogspot website. Currently, the header is set to:
(Post Name) Free Craft Patterns, Templates, and DIY Tutorials. I want to take away the plural from these, without affecting my other main pages. Is there a way to do this? Here is my existing code:
<title>
<?php if ( is_home() ) { ?> <?php } ?>
<?php echo ucwords(wp_title('',true)); ?> <?php echo ucwords(get_bloginfo('name')); ?>
</title>
<?php echo ucwords(str_replace('s', '', get_bloginfo('name'))) ?>