Advertisement
Paasky

WordPress examples

Sep 2nd, 2015
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.12 KB | None | 0 0
  1.  <<<<<< asenna (L/M/W)AMP >>>>>>
  2.  
  3. LAMP:
  4. http://www.beginninglinux.com/home/server-administration/installing-lamp-with-one-command---linux-apache-mysql-php
  5.  
  6. sudo apt-get update
  7. sudo apt-get install apache2
  8. sudo apt-get install mysql-server php5-mysql
  9. sudo mysql_install_db
  10. sudo mysql_secure_installation
  11. sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
  12. sudo service apache2 restart
  13.  
  14. MAMP:
  15. https://codex.wordpress.org/Installing_WordPress_Locally_on_Your_Mac_With_MAMP
  16.  
  17. WAMP:
  18. http://www.wampserver.com/en/
  19.  
  20.  
  21.  
  22.  <<<<<< luo kanta ja käyttäjä >>>>>>
  23.  
  24. *** komentorivi: ***
  25. mysql -u root
  26. create database wordpress;
  27. grant all privileges on wordpress.* to wpuser@localhost identified by 'salainensana';
  28.  
  29. *** phpmyadmin: ***
  30. Users > Add user
  31. Check "Create database with same name and grant all privileges."
  32.  
  33.  
  34.  
  35.  
  36.  <<<<<< style.css >>>>>>
  37.  
  38. /*​
  39. Theme Name: Kisut
  40. Author: Pekko Tuomisto​
  41. Author URI: http://kisut.fi​
  42. Template: twentyseventeen
  43. */​
  44.  
  45.  
  46.  
  47.  
  48.  <<<<<< functions.php >>>>>>
  49.  
  50. <?php
  51.     add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
  52.     function theme_enqueue_styles() {
  53.         wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
  54.         wp_enqueue_script( 'child-script', get_stylesheet_directory_uri() . '/script.js', array(), '1.0.0', true );
  55.     }
  56. ?>
  57.  
  58.  
  59.  
  60.  
  61.  <<<<<< font awesome link >>>>>>
  62.  
  63. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
  64.  
  65. ( http://fortawesome.github.io/Font-Awesome/icons/ )
  66.  
  67.  
  68.  
  69.  
  70.  <<<<<< custom post type >>>>>>
  71.  
  72.     register_post_type('cat', array(
  73.         'label' => 'Cats',
  74.         'public' => true,
  75.         'supports' => array(
  76.             'title', 'editor', 'author', 'revisions', 'thumbnail', 'custom-fields'
  77.         )
  78.     ));
  79.  
  80.  
  81.  
  82.  
  83. <<<<<< shortcode >>>>>>
  84.  
  85.     function show_cat_shortcode($atts) {
  86.  
  87.         // Attributes
  88.         extract( shortcode_atts(
  89.             array(
  90.                 'post_id' => ''
  91.             ), $atts )
  92.         );
  93.         $ret_string = '<img src="'. wp_get_attachment_url( get_post_thumbnail_id($post_id, 'thumbnail') ) .'">';
  94.  
  95.         return $ret_string;
  96.     }
  97.     add_shortcode( 'show_cat', 'show_cat_shortcode' );
  98.  
  99.  
  100.  
  101.  
  102. <<<<<< the loop >>>>>>
  103.  
  104. <?php
  105. $my_query = new WP_Query( 'post_type=cat' );
  106. if ( $my_query->have_posts() ) {
  107.     while ( $my_query->have_posts() ) {
  108.         $my_query->the_post();
  109. ?>
  110.  
  111. <div id="post-<?php the_ID(); ?>" class="post">
  112.     <h2>
  113.         <a href="<?php the_permalink() ?>">
  114.             <?php the_title(); ?>
  115.         </a>
  116.     </h2>
  117.  
  118.     <div class="entry">
  119.         <?php the_content(); ?>
  120.     </div>
  121.  
  122.     <div class="meta">
  123.         <?php echo get_post_meta( get_the_ID(), 'color', true ); ?>
  124.     </div>
  125.  
  126. </div>
  127.  
  128. <?php
  129.     }  // end while
  130. } else {
  131. ?>
  132.  
  133. <p class="no-posts">No cats :(</p>
  134.  
  135. <?php
  136. }  // end if else
  137. ?>
  138.  
  139.  
  140.  
  141. <<<<<< jQuery add content >>>>>>
  142.  
  143. jQuery(window).load(function(){
  144.     jQuery('#content').append('Toimii!');
  145.     jQuery('header').slideUp(2000).slideDown(500);
  146. });
  147.  
  148.  
  149. <<<<<< jQuery each -function >>>>>>
  150.  
  151. jQuery(window).load(function(){
  152.     var color = 111;
  153.     jQuery('a').each(function(){
  154.         jQuery(this).css('background', '#'+color);
  155.         color += 111;
  156.     });
  157. });
  158.  
  159.  
  160.  
  161. <<<<<< AJAX (PHP) >>>>>>
  162.  
  163.     // AJAX getCat(id)
  164.     add_action( 'wp_ajax_getCat', 'kisut_ajax_getCat' );
  165.     add_action( 'wp_ajax_nopriv_getCat', 'kisut_ajax_notLoggedIn' );
  166.  
  167.     function kisut_ajax_getCat() {
  168.         $id = intval($_REQUEST["id"]);
  169.        
  170.         if(get_post_type($id)=='cat'){
  171.             echo get_the_title($id);
  172.         } else {
  173.             echo 'not a cat!';
  174.         }
  175.  
  176.         die();
  177.     }
  178.    
  179.     function kisut_ajax_notLoggedIn() {
  180.         echo 'Log in first';
  181.         die();
  182.     }
  183.  
  184.  
  185.  
  186.  
  187. <<<<<< AJAX (jQuery) >>>>>>
  188. function getCat(id) {
  189.         jQuery.post(
  190.             'http://localhost/wordpress/wp-admin/admin-ajax.php',
  191.             {
  192.                 'action': 'getCat',
  193.                 'id': id
  194.             },
  195.             function(response){
  196.                 alert(response);
  197.             }
  198.         );
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement