.

.
Showing posts with label Wordpress. Show all posts
Showing posts with label Wordpress. Show all posts

Get Blog Post Outsite Wordpress


<?php
   require 'blog/wp-load.php';  
   ?>
<?php
//instantiate a WP_Query and get the latest 10 posts
$wp_query = new \WP_Query();
$wp_query->query('showposts=3');
?>
<?php
//Iterate through the returned posts. The starts the WP "Loop"
while ($wp_query->have_posts()) :
  $wp_query->the_post();
?>
<a href="<?php the_permalink() ?>" target="_blank">
                  <?php the_title(); ?>
                  </a>
<?php if(has_post_thumbnail())
              {?>
<a href="<?php the_permalink() ?>" target="_blank"><img src="<?php echo the_post_thumbnail_url('large'); ?>" style="width:100%;" ></a>
                <?php }?>
<?php //$authorId = the_author_ID();
              
                $args = get_avatar_data(the_author_ID(),'' );
               
      $imgurl= $args['url'];
     
      ?>
                    <img src="<?php echo $imgurl; ?>" style="border-radius:100%;width:80px;height:80px;z-index:999;margin-left:-15px !important;" align="middle">
                    <h3><?php echo ucwords(get_author_name());?></h3>
<?php the_time( get_option( 'date_format' ) ); ?>
  <p> <a href="<?php comments_link(); ?>">
    Leave a Comment
</a></p>
How to Allow my own theme to support multiple menus in wordpress

How to Allow my own theme to support multiple menus in wordpress

Add the following to your functions.php file. The 2 menus are the “Primary”, and “Secondary” menus.

/Register Navigations
add_action( 'init', 'my_custom_menus' );
function my_custom_menus() {
   register_nav_menus(
        array(
            'primary-menu' => __( 'Primary Menu' ),
            'secondary-menu' => __( 'Secondary Menu' )
        )
    );
}
To add them to your site you need to add the following to your WordPress template files (most likely your header.php and footer.php files).
<?php wp_nav_menu (array('theme_location' => 'primary-menu','menu_class' => 'nav'));?>
<?php wp_nav_menu (array('theme_location' => 'secondary-menu','menu_class' => 'nav'));?>
Adding .active class to active menu item

Adding .active class to active menu item

Add this code in function.php file in your theme
add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);
function special_nav_class($classes, $item){
     if( in_array('current-menu-item', $classes) ){
             $classes[] = 'active ';
     }
     return $classes;
}
How to Change site URL By htaccess file

How to Change site URL By htaccess file

I have to change the url Like its  satihoga.com . I want to change it http://www.satihoga.com/.
then I solve it .Its a wordpress project . & By permalinks & htaccess file I solve it.
By Changing in .htaccess file .
To change wordpress .htacces file in this:

.htaccess file

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]


RewriteCond %{HTTP_USER_AGENT} ^-?$

RewriteRule ^ - [F]

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^

RewriteCond %{HTTP_USER_AGENT} ^-?$

RewriteRule ^ - [F]



RewriteEngine on

RewriteCond %{HTTP_REFERER} !^http://www.satihoga.com/
</IfModule>

# END WordPress


And Also change in WP dashboard
Go to settings.
then General & Change the Site url & website address OR url  IN TO  http://www.satihoga.com/

how to make a custom wordpress theme

Overview of Wordpress main files :
  • header.php - Contains everything you'd want to appear at the top of your site.
  • index.php - The core file that loads your theme, also acts as the homepage (unless you set your blog to display a static page).
  • sidebar.php - Contains everything you'd want to appear in a sidebar.
  • footer.php - Contains everything you'd want to appear at the bottom of your site.
  • archive.php - The template file used when viewing categories, dates, posts by author, etc.
  • single.php - The template file that's used when viewing an individual post.
  • comments.php - Called at the bottom of the single.php file to enable the comments section.
  • page.php - Similar to single.php, but used for WordPress pages.
  • search.php - The template file used to display search results.
  • 404.php - The template file that displays when a 404 error occurs.
  • style.css - All the styling for your theme goes here.
  • functions.php - A file that can be used to configure the WordPress core, without editing core files.

These tags tell WordPress where to insert the dynamic content. A good example is the <?phpthe_title(); ?> tag, which pulls in the post title and displays it in your theme:
Your HTML code :
Click to Enlarge

Now we go to build wordpress theme and the first step to make style.css (Configuring the stylesheet)
All the details of a WordPress theme are contained within the stylesheet. At the top of your style.css add the following code, then amend the details to suit.
/*
Theme Name:
Theme URI:
Description:
Version: 1
Author:
Author URI:
*/

Now come to header.php
Open up your header.php file, and paste in the head section from your concept HTML file. Then we need to go in and replace certain elements with the correct WordPress template tags to ensure it all works correctly.
Click to Enlarge


If you add css folder in your theme it consists three css files like layout.css,reset.css,styles.css
the to add in your main style.css this code

@import url('css/layout.css'); 
@import url('css/reset.css'); 

@import url('css/styles.css'); 


Now building the index.php
The next step is to flesh out the main body of the website. Open up the index.php file and paste in the main bulk of the concept HTML.
Click for Enlarge

Now time to sidebar.php
The sidebar in my design is where the list of pages and categories are held. The sidebar.php file was called from the index using the get_sidebar(); tag, so anything within this sidebar.php file is inserted into the theme in the right place
Click for Enlarge


Rounding off the footer.php
The footer.php file is probably the most simple file for this theme. The only thing that goes in here is the wp_footer(); tag just before the </body>, so that any extra info can be inserted in the correct place.
Click for Enlarge

Constructing the page and single view
WordPress is made up of posts and pages. Posts use the single.php template file, whereas pages use the page.php template file.

They're pretty much the same, apart from that you tend to include the comments_template(); tag for posts, and not for pages.

Creating the archive.php
The archive.php file is used to display a list of posts whenever they're viewed by category, by author, by tag etc.

It's basically the same as the index file, but with the addition of a tag at the very top that renders a useful page title, so the user knows where they are. 'Browsing the Articles category' for instance.

HOW TO ADD OR GET MEDIA IMAGES IN WP.




u add media and featured image in post and u can get media image if media image add.
.firstly add this function in functions.php

function catch_that_image() {
  global $post, $posts;
  $first_img = '';
  ob_start();
  ob_end_clean();
  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  $first_img = $matches[1][0];

  if(empty($first_img)) {
    $first_img = bloginfo(template_directory)."/images/download.jpg";  // this image used when                        //no image found
  }
  return $first_img;
}

Now this used where u want to add image .
if ( get_the_post_thumbnail($post_id) != '' ) {

 $large_image_url=wp_get_attachment_image_src(get_post_thumbnail_id(),'large');
  echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
  echo '<img src="';
 echo $large_image_url[0];
 echo '" alt=""  style="width:281px;height:154px;"/>';
 echo '</a>';

} else {

 echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';


 echo '<img src="';
 echo catch_that_image();
 echo '" alt=""  style="width:281px;height:154px;"/>';
 echo '</a>';

}
OR

if ( get_the_post_thumbnail($post_id) != '' ) {

  echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
   the_post_thumbnail();
  echo '</a>';

} else {

 echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
 echo '<img src="';
 echo catch_that_image();
 echo '" alt="" />';
 echo '</a>';


}