admin管理员组文章数量:1024638
I have a single.php template, I also have index.php but it's not reverting to that, its just saying
'about:blank#blocked'
in the address bar and displaying nothing on the page.
I've tried changing echo the_permalink() to just the_permalink(), I've saved my permalink settings to post name. I've also deactivated all plugins. Any ideas?
My archive.php loop is as follows:
if (have_posts()) :
while (have_posts()) :
?>
<div class="card container mb-3">
<a href="<?php
// this conditional outputs the permalink for programmes and events, and an external url to resources
if (is_post_type_archive( $resources )) {
echo 'https://' . get_field('website');
} else {
echo the_permalink();
}
?>">
<div class="card-body row"><?php
the_post();
?>
<div class="col-sm img-fluid"><?php
the_post_thumbnail('medium');
?></div>
<div class="col-sm p-2 m-0">
<h2 class="card-title text-center"><?php the_title(); ?></h2>
</a>
<?php
// This section gets any custom fields and displays them if they exist
$fields = get_fields();
if( $fields ): ?>
<ul>
<?php foreach( $fields as $name => $value ): ?>
<li><?php
echo $value;
?></li>
<?php endforeach; ?>
</ul>
<?php
endif;
?><p class="card-text"><?php the_excerpt(); ?></p>
</div>
</div> <!-- card body -->
</div><!-- card -->
<?php
endwhile;
endif;
?>
Thanks
I have a single.php template, I also have index.php but it's not reverting to that, its just saying
'about:blank#blocked'
in the address bar and displaying nothing on the page.
I've tried changing echo the_permalink() to just the_permalink(), I've saved my permalink settings to post name. I've also deactivated all plugins. Any ideas?
My archive.php loop is as follows:
if (have_posts()) :
while (have_posts()) :
?>
<div class="card container mb-3">
<a href="<?php
// this conditional outputs the permalink for programmes and events, and an external url to resources
if (is_post_type_archive( $resources )) {
echo 'https://' . get_field('website');
} else {
echo the_permalink();
}
?>">
<div class="card-body row"><?php
the_post();
?>
<div class="col-sm img-fluid"><?php
the_post_thumbnail('medium');
?></div>
<div class="col-sm p-2 m-0">
<h2 class="card-title text-center"><?php the_title(); ?></h2>
</a>
<?php
// This section gets any custom fields and displays them if they exist
$fields = get_fields();
if( $fields ): ?>
<ul>
<?php foreach( $fields as $name => $value ): ?>
<li><?php
echo $value;
?></li>
<?php endforeach; ?>
</ul>
<?php
endif;
?><p class="card-text"><?php the_excerpt(); ?></p>
</div>
</div> <!-- card body -->
</div><!-- card -->
<?php
endwhile;
endif;
?>
Thanks
Share Improve this question edited Apr 8, 2019 at 19:11 JakePowell asked Apr 8, 2019 at 18:38 JakePowellJakePowell 431 silver badge10 bronze badges 3- try echo "<pre>";print_r(the_permalink()); echo "</pre>" – Vishwa Commented Apr 9, 2019 at 5:42
- No change with this. If I enter the URL manually (e.g tyc.local/programme/TYC_fridays) it takes me to index.php – JakePowell Commented Apr 10, 2019 at 10:04
- Try turning on error reporting or look in your logs and see what the actual error is – rudtek Commented Apr 17, 2019 at 18:00
1 Answer
Reset to default 1the_post()
should be called at the start of the while
loop (or The Loop). I.e. Before you call functions like the_permalink()
and the_title()
which point to the current item in The Loop.
So your while
loop should start like so: (and remove the other the_post();
in your code)
while ( have_posts() ) : the_post();
And the browser sent you to about:blank#blocked
most likely because the a
element had an invalid href
(URL) value: https://
as in:
<a href="https://">Example</a>
And it's very likely because the get_field('website')
returned an empty value; for example, because of a wrong post data (ID/object).
So this part:
if (is_post_type_archive( $resources )) {
echo 'https://' . get_field('website');
}
could be rewritten to this:
if (is_post_type_archive( $resources )) {
if ( $url = get_field('website') ) {
echo 'https://' . $url;
} else {
the_permalink();
}
}
But I'm assuming the website
field doesn't start with the protocol (e.g. https://
or http://
).
And there's no need to echo the_permalink()
because the function already echoes the permalink/URL.
I have a single.php template, I also have index.php but it's not reverting to that, its just saying
'about:blank#blocked'
in the address bar and displaying nothing on the page.
I've tried changing echo the_permalink() to just the_permalink(), I've saved my permalink settings to post name. I've also deactivated all plugins. Any ideas?
My archive.php loop is as follows:
if (have_posts()) :
while (have_posts()) :
?>
<div class="card container mb-3">
<a href="<?php
// this conditional outputs the permalink for programmes and events, and an external url to resources
if (is_post_type_archive( $resources )) {
echo 'https://' . get_field('website');
} else {
echo the_permalink();
}
?>">
<div class="card-body row"><?php
the_post();
?>
<div class="col-sm img-fluid"><?php
the_post_thumbnail('medium');
?></div>
<div class="col-sm p-2 m-0">
<h2 class="card-title text-center"><?php the_title(); ?></h2>
</a>
<?php
// This section gets any custom fields and displays them if they exist
$fields = get_fields();
if( $fields ): ?>
<ul>
<?php foreach( $fields as $name => $value ): ?>
<li><?php
echo $value;
?></li>
<?php endforeach; ?>
</ul>
<?php
endif;
?><p class="card-text"><?php the_excerpt(); ?></p>
</div>
</div> <!-- card body -->
</div><!-- card -->
<?php
endwhile;
endif;
?>
Thanks
I have a single.php template, I also have index.php but it's not reverting to that, its just saying
'about:blank#blocked'
in the address bar and displaying nothing on the page.
I've tried changing echo the_permalink() to just the_permalink(), I've saved my permalink settings to post name. I've also deactivated all plugins. Any ideas?
My archive.php loop is as follows:
if (have_posts()) :
while (have_posts()) :
?>
<div class="card container mb-3">
<a href="<?php
// this conditional outputs the permalink for programmes and events, and an external url to resources
if (is_post_type_archive( $resources )) {
echo 'https://' . get_field('website');
} else {
echo the_permalink();
}
?>">
<div class="card-body row"><?php
the_post();
?>
<div class="col-sm img-fluid"><?php
the_post_thumbnail('medium');
?></div>
<div class="col-sm p-2 m-0">
<h2 class="card-title text-center"><?php the_title(); ?></h2>
</a>
<?php
// This section gets any custom fields and displays them if they exist
$fields = get_fields();
if( $fields ): ?>
<ul>
<?php foreach( $fields as $name => $value ): ?>
<li><?php
echo $value;
?></li>
<?php endforeach; ?>
</ul>
<?php
endif;
?><p class="card-text"><?php the_excerpt(); ?></p>
</div>
</div> <!-- card body -->
</div><!-- card -->
<?php
endwhile;
endif;
?>
Thanks
Share Improve this question edited Apr 8, 2019 at 19:11 JakePowell asked Apr 8, 2019 at 18:38 JakePowellJakePowell 431 silver badge10 bronze badges 3- try echo "<pre>";print_r(the_permalink()); echo "</pre>" – Vishwa Commented Apr 9, 2019 at 5:42
- No change with this. If I enter the URL manually (e.g tyc.local/programme/TYC_fridays) it takes me to index.php – JakePowell Commented Apr 10, 2019 at 10:04
- Try turning on error reporting or look in your logs and see what the actual error is – rudtek Commented Apr 17, 2019 at 18:00
1 Answer
Reset to default 1the_post()
should be called at the start of the while
loop (or The Loop). I.e. Before you call functions like the_permalink()
and the_title()
which point to the current item in The Loop.
So your while
loop should start like so: (and remove the other the_post();
in your code)
while ( have_posts() ) : the_post();
And the browser sent you to about:blank#blocked
most likely because the a
element had an invalid href
(URL) value: https://
as in:
<a href="https://">Example</a>
And it's very likely because the get_field('website')
returned an empty value; for example, because of a wrong post data (ID/object).
So this part:
if (is_post_type_archive( $resources )) {
echo 'https://' . get_field('website');
}
could be rewritten to this:
if (is_post_type_archive( $resources )) {
if ( $url = get_field('website') ) {
echo 'https://' . $url;
} else {
the_permalink();
}
}
But I'm assuming the website
field doesn't start with the protocol (e.g. https://
or http://
).
And there's no need to echo the_permalink()
because the function already echoes the permalink/URL.
本文标签: permalinksWhen I click on a single post my browser goes to aboutblankblocked and the page is white
版权声明:本文标题:permalinks - When I click on a single post my browser goes to about:blank#blocked and the page is white 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745602631a2158546.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论