I have developed a wordpress theme. There are 2 pages HOME and ABOUT US. For home page I use index.php and for about us page I used page.php template. But when I click on home page it shows the title "page not found".
And I create a page named HOME then it is showing page contents which I posted in Home page but I need to show contents of index.php. (for example in index.php I have a slider. and I have created a page named "Home". When I click on home tab it is showing the contents that I posted on home page, NO SLIDER IS SHOWING)
Here is the site admission247.com
my page.php code
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="page_content">
<?php // echo '<br/><br/>'; ?>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
It's difficult to tell without seeing the code.
Here is a snippet of code I use for my header.
<title><?php
global $page, $paged;
wp_title("«", true, "right");
bloginfo("name");
$site_description = get_bloginfo("description", "display");
if($site_description && (is_home() || is_front_page()))
echo " « $site_description";
if($paged >= 2 || $page >= 2)
echo " « " . sprintf(__("Page %s", "h18"), max($paged, $page));
?></title>
If you can, post as much code as you can. It will help others understand your problem more.
YOUR_try this
functions.php
function site_wp_title( $title, $sep ) {
global $paged, $page;
if ( is_feed() )
return $title;
// Add the site name.
$title .= get_bloginfo( 'name' );
// Add the site description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) )
$title = "$title $sep $site_description";
// Add a page number if necessary.
if ( $paged >= 2 || $page >= 2 )
$title = "$title $sep " . sprintf( __( 'Page %s', 'YOUR_SITE' ), max( $paged, $page ) );
return $title;
}
add_filter( 'wp_title', 'site_wp_title', 10, 2 );
header.php
<title><?php wp_title( '|', true, 'right' ); ?></title>
Related
Hi :) I am working on my site with the "flexible post widget" to show the related contents or the content that I am interested in showing on the sidebar.
The widget works very well and I'm interested in continuing to use it, especially for the design and adaptability options with my site.
The problem? It does not include a function for "exclude the current post".
I was reviewing the code (I add it to this thread) and I think I could add some lines of code for this function (exclude the post I'm reading).
Unfortunately I'm new to programming and I'm lost with what and where to add it.
Could you help me?
<?php
/**
* Flexible Posts Widget: Default widget template
*
* #since 3.4.0
*
* This template was added to overcome some often-requested changes
* to the old default template (widget.php).
*/
// Block direct requests
if ( !defined('ABSPATH') )
die('-1');
echo $before_widget;
if ( ! empty( $title ) )
echo $before_title . $title . $after_title;
if ( $flexible_posts->have_posts() ):
function be_exclude_current_post( $args ) {
if( is_singular() && !isset( $args['post__in'] ) )
$args['post__not_in'] = array( get_the_ID() );
return $args;
}
add_filter( 'widget_posts_args', 'be_exclude_current_post' );
?>
<ul class="dpe-flexible-posts">
<?php while ( $flexible_posts->have_posts() ) : $flexible_posts->the_post(); global $post; ?>
<li id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<a href="<?php echo the_permalink(); ?>">
<?php
if ( $thumbnail == true ) {
// If the post has a feature image, show it
if ( has_post_thumbnail() ) {
the_post_thumbnail( $thumbsize );
// Else if the post has a mime type that starts with "image/" then show the image directly.
} elseif ( 'image/' == substr( $post->post_mime_type, 0, 6 ) ) {
echo wp_get_attachment_image( $post->ID, $thumbsize );
}
}
?>
<div class="title"><?php the_title(); ?></div>
</a>
</li>
<hr>
<?php endwhile; ?>
</ul><!-- .dpe-flexible-posts -->
<?php
endif; // End have_posts()
echo $after_widget;
Add this to your theme's 'functions.php' and remove it from the widget template.
function be_exclude_current_post( $args ) {
if( is_singular() && !isset( $args['post__in'] ) )
$args['post__not_in'] = array( get_the_ID() );
return $args;
}
add_filter( 'dpe_fpw_args', 'be_exclude_current_post' );
So I have a custom PHP page in Wordpress that displays some content:
<? while(have_posts() ) : the_post(); ?>
<?the_content();?>
<? endwhile; ?>
I need to display the list of news related with this content, so I wrote a shortcode for that:
function generate_program_news(){
$news_args = array( 'posts_per_page' => 5, 'cat' => 4);
$news_query = new WP_Query($news_args);
$news_data;
while( $news_query->have_posts() ) {
$news_date = get_permalink();
$news_title = the_title();
$news_data = "<a>" .$news_date. ": " .$news_title. "</a>";
}
wp_reset_postdata();
return $news_data;
}
add_shortcode('program_news','generate_program_news');
But when I add [program_news] shortcode and try to access the page I used it in, the entire website dies off until I have the OpenServer rebooted. What am I doing wrong?
while( $news_query->have_posts() )
you must type
$news_query->the_post();
EDIT : Even after making the Permalink Settings to Post name, http://domain.com/?paged=3 still works.
I have posts collection in my home page which has pagination. Let's say I have
domain.com
If my Permalink settings is in default which is Plain Format like
http://domain.com/?p=123
Then my pagination http://domain.com/?paged=3 will work.
How ever if I want my permalink settings to be in Post Name Format like
http://domain.com/sample-post/
Then my pagination in my home page will not work anymore. I tried inspect element in the link of pagination if set in post name permalink and it's
http://domain.com/page/23/
Then what happened is it will not go to page 23. It will always redirect to my home page
http://domain.com
I already tried this
https://wordpress.stackexchange.com/questions/134339/pagination-on-custom-post-type-not-working-if-permalinks-set-to-rewrite-url
Which I put this code in my functions.php
add_filter( 'redirect_canonical','custom_disable_redirect_canonical' );
function custom_disable_redirect_canonical( $redirect_url ){
if ( is_singular('your_custom_post_type') ) $redirect_url = false;
return $redirect_url;
}
And it didn't work.
Update I checked the functions.php and i see this
/* -----------------------------------------------------------------------------
Woo commerce
*/
if (in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' )))) { // check if we have woo commerce installed
// breadcrumb
add_filter( 'woocommerce_breadcrumb_defaults', 'td_woocommerce_breadcrumbs' );
function td_woocommerce_breadcrumbs() {
return array(
'delimiter' => ' <span class="td-sp td-sp-breadcrumb-arrow td-bread-sep"></span> ',
'wrap_before' => '<div class="entry-crumbs" itemprop="breadcrumb">',
'wrap_after' => '</div>',
'before' => '',
'after' => '',
'home' => _x( 'Home', 'breadcrumb', 'woocommerce' ),
);
}
// number of products to display on shop page
add_filter('loop_shop_per_page', create_function('$cols', 'return 8;'));
if (!function_exists('woocommerce_pagination')) {
// pagination
function woocommerce_pagination(){
echo td_page_generator::get_pagination();
}
}
if (!function_exists('woocommerce_output_related_products')) {
// number of related product
function woocommerce_output_related_products() {
woocommerce_related_products(4,4); // Display 4 products in rows of 4
}
}
}
/**
* Add prev and next links to a numbered link list - the pagination on single.
*/
function wp_link_pages_args_prevnext_add($args)
{
global $page, $numpages, $more, $pagenow;
if (!$args['next_or_number'] == 'next_and_number')
return $args; # exit early
$args['next_or_number'] = 'number'; # keep numbering for the main part
if (!$more)
return $args; # exit early
if($page-1) # there is a previous page
$args['before'] .= _wp_link_page($page-1)
. $args['link_before']. $args['previouspagelink'] . $args['link_after'] . '</a>'
;
if ($page<$numpages) # there is a next page
$args['after'] = _wp_link_page($page+1)
. $args['link_before'] . $args['nextpagelink'] . $args['link_after'] . '</a>'
. $args['after']
;
return $args;
}
add_filter('wp_link_pages_args', 'wp_link_pages_args_prevnext_add');
add_theme_support('woocommerce');
It doesn't have woo commerce plugin but It has that code. Hope it helps you find out whats going on?
Is is not possible to have a page name and a custom post type with the same name. If you do, the page url-slug of the page name and custom post type slug are the same and will cause a not found error.
If you are using WP_Query for retrieving posts then change your code to below
$paged = ( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
$args = array(
'posts_per_page' => 5,
'post_type' => 'post',
'paged' => $paged,
);
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ) : $the_query->the_post();
the_title();
echo '<br>';
endwhile;
$big = 999999999;
echo paginate_links( array(
'format' => '?paged=%#%',
'current' => max( 1, $paged ),
'total' => $the_query->max_num_pages
) );
Beside other mentioned scenarios, Make sure you do not have the slug of the template you are using the loop on similar to any of the post types exist in the theme. If a page slug is similar to the post type slug, the pagination will not work properly.
I'm using a wordpress theme that creates custom pages.
However, when SEO Yoast is used to make custom title and meta descriptions, all the custom pages have the same title tags as index.php (the homepage). This is a red flag for google webmaster tools obviously.
add_action('theme_query', 'theme_page_query');
function theme_page_query() {
global $wp_query;
$act = get_query_var( 'act' );
if ($act == 'new-wallpapers') {
query_posts('orderby=post_date&order=DESC&paged='.get_query_var('page'));
} elseif ($act == 'popular-wallpapers') {
query_posts('meta_key=theme_hit_download&orderby=meta_value_num post_date&order=DESC&paged='.get_query_var('page'));
} elseif ($act == 'random-wallpapers') {
query_posts('orderby=rand&paged='.get_query_var('page'));
} elseif ($act == 'recent-downloads') {
query_posts('meta_key=theme_hit_download_time&orderby=meta_value&order=DESC&paged='.get_query_var('page'));
}
}
function theme_page_title($title) {
if (in_array(get_query_var( 'act' ), array(
'new-wallpapers',
'popular-wallpapers',
'random-wallpapers',
'recent-downloads',
))) {
$title = ucwords(str_replace('-', ' ', get_query_var( 'act' )));
}
return $title;
}
add_filter( 'wp_title', 'theme_wp_title', 10, 2 );
function theme_wp_title( $title, $sep ) {
global $paged, $page, $wp_query;
if ( is_feed() ) {
return $title;
}
if (in_array(get_query_var( 'act' ), array(
'new-wallpapers',
'popular-wallpapers',
'random-wallpapers',
'recent-downloads',
))) {
$title = ucwords(str_replace('-', ' ', get_query_var( 'act' ))) . " {$sep} ";
}
// Add the site name.
$title .= get_bloginfo( 'name' );
// Add the site description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) ) {
$title = "$title $sep $site_description";
}
// Add a page number if necessary.
if ( $paged >= 2 || $page >= 2 ) {
$title = "$title $sep " . sprintf( __( 'Page %s', 'theme' ), max( $paged, $page ) );
}
return $title;
}
I have tried searching, but I cannot find a step-by-step guide and I am not good in PHP. Any help would be much appreciated.
You can do this in three steps by
1.Add a new input box to the admin pages for creating and editing new Posts/Pages
2.Save the the value of that input box when that Post/Page is saved
3.Echo out a new title as part of the wp_head() function
here is the detailed explanation..Hope it helps ..Thanks
I want that wordpress should display title from selected post and selected page.I am using buisness news theme. Is their any setting available or I need to change in code I am new to wordpress. I found title code in header.php
<title><?php
//Print the <title> tag based on what is being viewed.
global $page, $paged;
// Add the blog name.
bloginfo( 'name' );
// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) ) echo " | $site_description";
// Add a page number if necessary:
if ( $paged >= 2 || $page >= 2 )
echo ' | ' . sprintf( __( 'Page %s', 'business-news' ), max( $paged, $page ) );
?></title>
But when I select particulate post it shows only site name in title. Where I am missing?
Try this:
<title>
<?php single_post_title(); ?>
</title>
manage using add_filter wp_title() function
<title><?php wp_title(''); ?></title>
If u want change using like this in function.php
function theme_name_wp_title( $title, $sep ) {
if ( is_feed() ) {
return $title;
}
global $page, $paged;
// Add the blog name
$title .= get_bloginfo( 'name', 'display' );
// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) ) {
$title .= " $sep $site_description";
}
// Add a page number if necessary:
if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
$title .= " $sep " . sprintf( __( 'Page %s', '_s' ), max( $paged, $page ) );
}
return $title;
}
add_filter( 'wp_title', 'theme_name_wp_title', 10, 2 );
You can simply use simply :
<title><?php wp_title(); ?></title>
For more help go to here