Skip to content

Instantly share code, notes, and snippets.

View abelsaad's full-sized avatar
😊

abdelrhman aboelsaad abelsaad

😊
View GitHub Profile
@abelsaad
abelsaad / home.php
Created July 6, 2021 07:21
View the latest posted topics
<?php
$the_query = new WP_Query( 'showposts=2' );
while ($the_query -> have_posts()) : $the_query -> the_post();
$thumb_id = get_post_thumbnail_id();
$thumb_url = wp_get_attachment_image_src($thumb_id, true);
?>
<li>
<a href="<?php the_permalink() ?>">
<img src="<?php echo $thumb_url[0]; ?>" />
@abelsaad
abelsaad / single.php
Created July 6, 2021 07:19
Newer & Previous Posts
<?php next_post_link() ?> - Displays Newer Posts link
<?php previous_post_link() ?> - Displays previous link
@abelsaad
abelsaad / category.php
Last active August 1, 2021 09:47
View posts from the same category
<?php
global $post;
$categories = get_the_category();
foreach ($categories as $category) :
?>
<h3>More News From This Category</h3>
<ul>
<?php
@abelsaad
abelsaad / loop.php
Created July 6, 2021 07:00
Simple loop
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<?php
// الكود الخاص بالتدوينة
?>
<?php endwhile; ?>
<?php else : ?>
<p>المعذرة, ما تبحث عنه غير متوفر هنا</p>
@abelsaad
abelsaad / functions.php
Last active August 1, 2021 09:47
Polylang: Translate custom strings
You must first register the strings for translation.
For example you echo "Hello world" in some template file like this:
<?php pll_e('Hello world'); ?>
To show string in the "Strings translation" add in your functions.php:
<?php
add_action('init', function() {
pll_register_string('mytheme-hello', 'Hello world');
@abelsaad
abelsaad / if_language_else.php
Created July 5, 2021 13:35
Polylang if language else
<?php if(pll_current_language() == 'ar') { ?>
<?php } else if(pll_current_language() == 'en') { ?>
<?php } ?>
@abelsaad
abelsaad / functions.php
Created July 5, 2021 12:46
How to remove “Archive:”, “Category:” etc. pre-title inserts in Archive Titles
<?php
add_filter( 'get_the_archive_title', 'my_theme_archive_title' );
/**
* Remove archive labels.
*
* @param string $title Current archive title to be displayed.
* @return string Modified archive title to be displayed.
*/
function my_theme_archive_title( $title ) {
@abelsaad
abelsaad / loop.php
Created June 23, 2021 08:34
Get Category
// A nice, way to display linked categories is by using a comma as separator
<?php the_category( ', ' ); ?>
// The separator will not be added after the last linked category. By using the following reasoning, each of the linked categories can also be enclosed, for example, in a <div> element:
<?php the_category( '</div><div>' ); ?>
// or to use the linked categories in a sentence:
This post has <?php the_category( ', ' ); ?> as categories.
// The simplest way to display a category, or a list of categories, without links is by using the following code:
@abelsaad
abelsaad / single.php
Created June 9, 2021 07:14
Custom Single page
<?php
$post = $wp_query->post;
if ( in_category('2') ) {
include(TEMPLATEPATH . '/single-play.php'); }
elseif ( in_category('3') ) {
include(TEMPLATEPATH . '/single-read.php'); }
@abelsaad
abelsaad / 404.php
Created May 29, 2021 17:05
Redirect to home page
<?php wp_redirect( home_url() ); exit; ?>